Skip to content
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

API: change Timestamp.strptime to raise NotImplementedError #25124

Merged
merged 7 commits into from
Feb 19, 2019
Merged
2 changes: 2 additions & 0 deletions doc/source/whatsnew/v0.25.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ Other Enhancements
Backwards incompatible API changes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

- :meth:`Timestamp.strptime` will now rise a NotImplementedError (:issue:`21257`)

.. _whatsnew_0250.api.other:

Other API Changes
Expand Down
9 changes: 8 additions & 1 deletion pandas/_libs/tslibs/nattype.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,6 @@ class NaTType(_NaT):
utctimetuple = _make_error_func('utctimetuple', datetime)
timetz = _make_error_func('timetz', datetime)
timetuple = _make_error_func('timetuple', datetime)
strptime = _make_error_func('strptime', datetime)
strftime = _make_error_func('strftime', datetime)
isocalendar = _make_error_func('isocalendar', datetime)
dst = _make_error_func('dst', datetime)
Expand All @@ -388,6 +387,14 @@ class NaTType(_NaT):
# The remaining methods have docstrings copy/pasted from the analogous
# Timestamp methods.

strptime = _make_error_func('strptime', # noqa:E128
"""
Timestamp.strptime(string, format)

Function is not implemented. Use pd.to_datetime().
"""
)

utcfromtimestamp = _make_error_func('utcfromtimestamp', # noqa:E128
"""
Timestamp.utcfromtimestamp(ts)
Expand Down
11 changes: 11 additions & 0 deletions pandas/_libs/tslibs/timestamps.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,17 @@ class Timestamp(_Timestamp):
"""
return cls(datetime.fromtimestamp(ts))

# Issue 25016.
@classmethod
def strptime(cls, date_string, format):
"""
Timestamp.strptime(string, format)

Function is not implemented. Use pd.to_datetime().
"""
raise NotImplementedError("Timestamp.strptime() is not implmented."
"Use to_datetime() to parse date strings.")

@classmethod
def combine(cls, date, time):
"""
Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/scalar/timestamp/test_timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,14 @@ def test_constructor_invalid_tz(self):
# interpreted as a `freq`
Timestamp('2012-01-01', 'US/Pacific')

def test_constructor_strptime(self):
# GH25016
# Test support for Timestamp.strptime
fmt = '%Y%m%d-%H%M%S-%f%z'
ts = '20190129-235348-000001+0000'
with pytest.raises(NotImplementedError):
Timestamp.strptime(ts, fmt)

def test_constructor_tz_or_tzinfo(self):
# GH#17943, GH#17690, GH#5168
stamps = [Timestamp(year=2017, month=10, day=22, tz='UTC'),
Expand Down