Skip to content

Commit fae65a4

Browse files
BUG: constructor Timestamp.strptime() does not support %z.
1 parent 4d44a2a commit fae65a4

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

doc/source/whatsnew/v0.24.2.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Bug Fixes
6666

6767
**Timezones**
6868

69-
-
69+
- Bug in :meth:`Timestamp.strptime` - support %z. (:issue:`21257`)
7070
-
7171
-
7272

pandas/_libs/tslibs/timestamps.pyx

+6
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,12 @@ class Timestamp(_Timestamp):
677677
"""
678678
return cls(datetime.fromtimestamp(ts))
679679

680+
# Issue 25016. As strptime with %z is not supported in Python 2.
681+
@classmethod
682+
def strptime(cls, date_string, format):
683+
raise NotImplementedError("Timestamp.strptime() is not implmented."
684+
"Use to_datetime() to parse date strings.")
685+
680686
@classmethod
681687
def combine(cls, date, time):
682688
"""

pandas/tests/scalar/timestamp/test_timestamp.py

+8
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,14 @@ def test_constructor_invalid_tz(self):
355355
# interpreted as a `freq`
356356
Timestamp('2012-01-01', 'US/Pacific')
357357

358+
def test_constructor_strptime(self):
359+
# GH25016
360+
# Test support for Timestamp.strptime
361+
fmt = '%Y%m%d-%H%M%S-%f%z'
362+
ts = '20190129-235348-000001+0000'
363+
with pytest.raises(NotImplementedError):
364+
Timestamp.strptime(ts, fmt)
365+
358366
def test_constructor_tz_or_tzinfo(self):
359367
# GH#17943, GH#17690, GH#5168
360368
stamps = [Timestamp(year=2017, month=10, day=22, tz='UTC'),

0 commit comments

Comments
 (0)