Skip to content

Commit

Permalink
BUG/ENH: Timestamp.strptime
Browse files Browse the repository at this point in the history
  • Loading branch information
saurav-chakravorty committed Feb 5, 2019
1 parent e3b0950 commit fd91d3f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
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 @@ -61,7 +61,7 @@ Bug Fixes

**Timezones**

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

Expand Down
6 changes: 3 additions & 3 deletions pandas/_libs/tslibs/timestamps.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ class Timestamp(_Timestamp):
object freq=None, tz=None, unit=None,
year=None, month=None, day=None,
hour=None, minute=None, second=None, microsecond=None,
nanosecond=None, tzinfo=None):
tzinfo=None, nanosecond=None):
# The parameter list folds together legacy parameter names (the first
# four) and positional and keyword parameter names from pydatetime.
#
Expand Down Expand Up @@ -740,8 +740,8 @@ class Timestamp(_Timestamp):
# microsecond[, nanosecond[, tzinfo]]]]]])
ts_input = datetime(ts_input, freq, tz, unit or 0,
year or 0, month or 0, day or 0)
nanosecond = hour
tz = minute
nanosecond = minute
tz = hour
freq = None

if getattr(ts_input, 'tzinfo', None) is not None and tz is not None:
Expand Down
18 changes: 16 additions & 2 deletions pandas/tests/scalar/timestamp/test_timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,20 @@ def test_constructor_with_stringoffset(self):
assert repr(result) == expected
assert result == eval(repr(result))

# GH25016
# Test support for Timestamp.strptime
fmt = '%Y%m%d-%H%M%S-%f%z'
ts = '20190129-235348-000001+0000'
result = Timestamp.strptime(ts, fmt)
expected = Timestamp(2019, 1, 29, 23, 53, 48, 1, pytz.UTC)
assert result == expected

fmt = '%Y%m%d-%H%M%S-%f'
ts = '20190129-235348-000001'
result = Timestamp.strptime(ts, fmt)
expected = Timestamp(2019, 1, 29, 23, 53, 48, 1)
assert result == expected

def test_constructor_invalid(self):
with pytest.raises(TypeError, match='Cannot convert input'):
Timestamp(slice(2))
Expand Down Expand Up @@ -433,8 +447,8 @@ def test_constructor_fromordinal(self):
microsecond=6, nanosecond=1),
Timestamp(year=2000, month=1, day=2, hour=3, minute=4, second=5,
microsecond=6, nanosecond=1, tz='UTC'),
Timestamp(2000, 1, 2, 3, 4, 5, 6, 1, None),
Timestamp(2000, 1, 2, 3, 4, 5, 6, 1, pytz.UTC)])
Timestamp(2000, 1, 2, 3, 4, 5, 6, None, 1),
Timestamp(2000, 1, 2, 3, 4, 5, 6, pytz.UTC, 1)])
def test_constructor_nanosecond(self, result):
# GH 18898
expected = Timestamp(datetime(2000, 1, 2, 3, 4, 5, 6), tz=result.tz)
Expand Down

0 comments on commit fd91d3f

Please sign in to comment.