Skip to content

Commit 13bdca4

Browse files
authored
BUG: inferred resolution with ISO8601 and tzoffset (#56208)
* BUG: inferred resolution with ISO8601 and tzoffset * GH ref
1 parent 3934e56 commit 13bdca4

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

doc/source/whatsnew/v2.2.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,7 @@ Datetimelike
459459
- Bug in :meth:`Index.view` to a datetime64 dtype with non-supported resolution incorrectly raising (:issue:`55710`)
460460
- Bug in :meth:`Series.dt.round` with non-nanosecond resolution and ``NaT`` entries incorrectly raising ``OverflowError`` (:issue:`56158`)
461461
- Bug in :meth:`Tick.delta` with very large ticks raising ``OverflowError`` instead of ``OutOfBoundsTimedelta`` (:issue:`55503`)
462+
- Bug in :meth:`Timestamp.unit` being inferred incorrectly from an ISO8601 format string with minute or hour resolution and a timezone offset (:issue:`56208`)
462463
- Bug in ``.astype`` converting from a higher-resolution ``datetime64`` dtype to a lower-resolution ``datetime64`` dtype (e.g. ``datetime64[us]->datetim64[ms]``) silently overflowing with values near the lower implementation bound (:issue:`55979`)
463464
- Bug in adding or subtracting a :class:`Week` offset to a ``datetime64`` :class:`Series`, :class:`Index`, or :class:`DataFrame` column with non-nanosecond resolution returning incorrect results (:issue:`55583`)
464465
- Bug in addition or subtraction of :class:`BusinessDay` offset with ``offset`` attribute to non-nanosecond :class:`Index`, :class:`Series`, or :class:`DataFrame` column giving incorrect results (:issue:`55608`)

pandas/_libs/src/vendored/numpy/datetime/np_datetime_strings.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
364364
goto parse_error;
365365
}
366366
out->hour = (*substr - '0');
367+
bestunit = NPY_FR_h;
367368
++substr;
368369
--sublen;
369370
/* Second digit optional */
@@ -425,6 +426,7 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
425426
}
426427
/* First digit required */
427428
out->min = (*substr - '0');
429+
bestunit = NPY_FR_m;
428430
++substr;
429431
--sublen;
430432
/* Second digit optional if there was a separator */

pandas/tests/scalar/timestamp/test_constructors.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,13 @@ def test_constructor_str_infer_reso(self):
457457
assert ts == Timestamp("01-01-2013T00:00:00.000000002+0000")
458458
assert ts.unit == "ns"
459459

460+
# GH#56208 minute reso through the ISO8601 path with tz offset
461+
ts = Timestamp("2020-01-01 00:00+00:00")
462+
assert ts.unit == "s"
463+
464+
ts = Timestamp("2020-01-01 00+00:00")
465+
assert ts.unit == "s"
466+
460467

461468
class TestTimestampConstructors:
462469
def test_weekday_but_no_day_raises(self):

0 commit comments

Comments
 (0)