Skip to content

BUG: inferred resolution with ISO8601 and tzoffset #56208

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v2.2.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ Datetimelike
- Bug in :meth:`Index.view` to a datetime64 dtype with non-supported resolution incorrectly raising (:issue:`55710`)
- Bug in :meth:`Series.dt.round` with non-nanosecond resolution and ``NaT`` entries incorrectly raising ``OverflowError`` (:issue:`56158`)
- Bug in :meth:`Tick.delta` with very large ticks raising ``OverflowError`` instead of ``OutOfBoundsTimedelta`` (:issue:`55503`)
- Bug in :meth:`Timestamp.unit` being inferred incorrectly from an ISO8601 format string with minute or hour resolution and a timezone offset (:issue:`56208`)
- 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`)
- 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`)
- 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`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
goto parse_error;
}
out->hour = (*substr - '0');
bestunit = NPY_FR_h;
++substr;
--sublen;
/* Second digit optional */
Expand Down Expand Up @@ -425,6 +426,7 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
}
/* First digit required */
out->min = (*substr - '0');
bestunit = NPY_FR_m;
++substr;
--sublen;
/* Second digit optional if there was a separator */
Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/scalar/timestamp/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,13 @@ def test_constructor_str_infer_reso(self):
assert ts == Timestamp("01-01-2013T00:00:00.000000002+0000")
assert ts.unit == "ns"

# GH#56208 minute reso through the ISO8601 path with tz offset
ts = Timestamp("2020-01-01 00:00+00:00")
assert ts.unit == "s"

ts = Timestamp("2020-01-01 00+00:00")
assert ts.unit == "s"


class TestTimestampConstructors:
def test_weekday_but_no_day_raises(self):
Expand Down