File tree 3 files changed +12
-1
lines changed
3 files changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -905,6 +905,7 @@ Performance improvements
905
905
The improvement is not present if checking if the :class: `Categorical ` is less than or less than or equal than the scalar (:issue: `29820 `)
906
906
- Performance improvement in :meth: `Index.equals ` and :meth: `MultiIndex.equals ` (:issue: `29134 `)
907
907
- Performance improvement in :func: `~pandas.api.types.infer_dtype ` when ``skipna `` is ``True `` (:issue: `28814 `)
908
+ - Performance improvement in :class: `Timestamp ` constructor (:issue: `30543 `)
908
909
909
910
.. ---------------------------------------------------------------------------
910
911
Original file line number Diff line number Diff line change @@ -391,7 +391,10 @@ class Timestamp(_Timestamp):
391
391
# User passed tzinfo instead of tz; avoid silently ignoring
392
392
tz, tzinfo = tzinfo, None
393
393
394
- if isinstance (ts_input, str ):
394
+ if isinstance (ts_input, Timestamp) and tz is None :
395
+ # GH 30543 if pd.Timestamp already passed, return it
396
+ return ts_input
397
+ elif isinstance (ts_input, str ):
395
398
# User passed a date string to parse.
396
399
# Check that the user didn't also pass a date attribute kwarg.
397
400
if any (arg is not None for arg in _date_attributes):
Original file line number Diff line number Diff line change @@ -2313,3 +2313,10 @@ def test_nullable_integer_to_datetime():
2313
2313
tm .assert_series_equal (res , expected )
2314
2314
# Check that ser isn't mutated
2315
2315
tm .assert_series_equal (ser , ser_copy )
2316
+
2317
+
2318
+ def test_timestamp_constructor_identity ():
2319
+ # Test for #30543
2320
+ expected = pd .Timestamp ("2017-01-01T12" )
2321
+ result = pd .Timestamp (expected )
2322
+ assert result is expected
You can’t perform that action at this time.
0 commit comments