Skip to content

Commit

Permalink
BUG: constructor Timestamp.strptime() does not support %z.
Browse files Browse the repository at this point in the history
  • Loading branch information
saurav-chakravorty committed Feb 12, 2019
1 parent 4d44a2a commit fae65a4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.24.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Bug Fixes

**Timezones**

-
- Bug in :meth:`Timestamp.strptime` - support %z. (:issue:`21257`)
-
-

Expand Down
6 changes: 6 additions & 0 deletions pandas/_libs/tslibs/timestamps.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,12 @@ class Timestamp(_Timestamp):
"""
return cls(datetime.fromtimestamp(ts))

# Issue 25016. As strptime with %z is not supported in Python 2.
@classmethod
def strptime(cls, date_string, format):
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

0 comments on commit fae65a4

Please sign in to comment.