Skip to content

BUG GH15240 Timestamp.replace raised ValueError instead of TypeError. #15253

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/source/whatsnew/v0.20.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -510,3 +510,5 @@ Bug Fixes


- Bug in ``DataFrame.boxplot`` where ``fontsize`` was not applied to the tick labels on both axes (:issue:`15108`)

- Bug in ``Timestamp.replace`` where invalid argument caused a ValueError instead of TypeError (:issue:`15240`)
13 changes: 11 additions & 2 deletions pandas/tseries/tests/test_timezones.py
Original file line number Diff line number Diff line change
Expand Up @@ -1195,10 +1195,10 @@ def test_replace(self):
expected = Timestamp('2015-02-02 00:05:05.000005005', tz=tz)
self.assertEqual(result, expected)

# error
# error GH 15240 return error should be type error not value error
def f():
dt.replace(foo=5)
self.assertRaises(ValueError, f)
self.assertRaises(TypeError, f)

def f():
dt.replace(hour=0.1)
Expand All @@ -1208,6 +1208,15 @@ def f():
dt = Timestamp('2013-11-03 01:59:59.999999-0400', tz='US/Eastern')
self.assertEqual(dt.tz_localize(None), dt.replace(tzinfo=None))

# GH 15240 return error should be type error not value error
expected = "TypeError(\"'apple' is an invalid keyword " \
"argument for this function\",)"
try:
Timestamp("2012").replace(apple=3)
except Exception as e:
result = repr(e)
self.assertEqual(expected, result)

def test_ambiguous_compat(self):
# validate that pytz and dateutil are compat for dst
# when the transition happens
Expand Down
3 changes: 2 additions & 1 deletion pandas/tslib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,8 @@ class Timestamp(_Timestamp):
elif k == 'tzinfo':
tzinfo = v
else:
raise ValueError("invalid name {} passed".format(k))
raise TypeError("'{}' is an invalid keyword argument for this function".format(k))
# ValueError("invalid name {} passed".format(k))

# reconstruct & check bounds
value = pandas_datetimestruct_to_datetime(PANDAS_FR_ns, &dts)
Expand Down