From 7e56a92ce7a70571dbdec9d7741bbbb3b2260728 Mon Sep 17 00:00:00 2001 From: Brock Date: Fri, 20 Oct 2023 09:21:55 -0700 Subject: [PATCH 1/2] BUG: inferred_freq with non-nano --- doc/source/whatsnew/v2.2.0.rst | 1 + pandas/tests/tseries/frequencies/test_inference.py | 5 +++-- pandas/tseries/frequencies.py | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/doc/source/whatsnew/v2.2.0.rst b/doc/source/whatsnew/v2.2.0.rst index c8c27f2f2e178..8a888116fe198 100644 --- a/doc/source/whatsnew/v2.2.0.rst +++ b/doc/source/whatsnew/v2.2.0.rst @@ -413,6 +413,7 @@ Other - Bug in :meth:`DataFrame.apply` where passing ``raw=True`` ignored ``args`` passed to the applied function (:issue:`55009`) - Bug in rendering ``inf`` values inside a a :class:`DataFrame` with the ``use_inf_as_na`` option enabled (:issue:`55483`) - Bug in rendering a :class:`Series` with a :class:`MultiIndex` when one of the index level's names is 0 not having that name displayed (:issue:`55415`) +- Bug in :func:`infer_freq` and :meth:`DatetimeIndex.inferred_freq` with weekly frequencies and non-nanosecond resolutions (:issue:`??`) - .. ***DO NOT USE THIS SECTION*** diff --git a/pandas/tests/tseries/frequencies/test_inference.py b/pandas/tests/tseries/frequencies/test_inference.py index aec9915d69e3c..b7c881b7a2457 100644 --- a/pandas/tests/tseries/frequencies/test_inference.py +++ b/pandas/tests/tseries/frequencies/test_inference.py @@ -229,10 +229,11 @@ def test_infer_freq_index(freq, expected): }.items() ), ) -def test_infer_freq_tz(tz_naive_fixture, expected, dates): +@pytest.mark.parametrize("unit", ["s", "ms", "us", "ns"]) +def test_infer_freq_tz(tz_naive_fixture, expected, dates, unit): # see gh-7310 tz = tz_naive_fixture - idx = DatetimeIndex(dates, tz=tz) + idx = DatetimeIndex(dates, tz=tz).as_unit(unit) assert idx.inferred_freq == expected diff --git a/pandas/tseries/frequencies.py b/pandas/tseries/frequencies.py index 4bd558a30c92f..67958a03c3969 100644 --- a/pandas/tseries/frequencies.py +++ b/pandas/tseries/frequencies.py @@ -276,7 +276,7 @@ def fields(self) -> np.ndarray: # structured array of fields @cache_readonly def rep_stamp(self) -> Timestamp: - return Timestamp(self.i8values[0]) + return Timestamp(self.i8values[0], unit=self.index.unit) def month_position_check(self) -> str | None: return month_position_check(self.fields, self.index.dayofweek) From 28c47cb1433a86a2f1d79be24fa49e8d68f0d357 Mon Sep 17 00:00:00 2001 From: Brock Date: Fri, 20 Oct 2023 09:22:52 -0700 Subject: [PATCH 2/2] GH ref --- doc/source/whatsnew/v2.2.0.rst | 2 +- pandas/tests/tseries/frequencies/test_inference.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v2.2.0.rst b/doc/source/whatsnew/v2.2.0.rst index 8a888116fe198..679845eb0098c 100644 --- a/doc/source/whatsnew/v2.2.0.rst +++ b/doc/source/whatsnew/v2.2.0.rst @@ -410,10 +410,10 @@ Styler Other ^^^^^ - Bug in :func:`cut` incorrectly allowing cutting of timezone-aware datetimes with timezone-naive bins (:issue:`54964`) +- Bug in :func:`infer_freq` and :meth:`DatetimeIndex.inferred_freq` with weekly frequencies and non-nanosecond resolutions (:issue:`55609`) - Bug in :meth:`DataFrame.apply` where passing ``raw=True`` ignored ``args`` passed to the applied function (:issue:`55009`) - Bug in rendering ``inf`` values inside a a :class:`DataFrame` with the ``use_inf_as_na`` option enabled (:issue:`55483`) - Bug in rendering a :class:`Series` with a :class:`MultiIndex` when one of the index level's names is 0 not having that name displayed (:issue:`55415`) -- Bug in :func:`infer_freq` and :meth:`DatetimeIndex.inferred_freq` with weekly frequencies and non-nanosecond resolutions (:issue:`??`) - .. ***DO NOT USE THIS SECTION*** diff --git a/pandas/tests/tseries/frequencies/test_inference.py b/pandas/tests/tseries/frequencies/test_inference.py index b7c881b7a2457..867363e1a03bc 100644 --- a/pandas/tests/tseries/frequencies/test_inference.py +++ b/pandas/tests/tseries/frequencies/test_inference.py @@ -231,7 +231,7 @@ def test_infer_freq_index(freq, expected): ) @pytest.mark.parametrize("unit", ["s", "ms", "us", "ns"]) def test_infer_freq_tz(tz_naive_fixture, expected, dates, unit): - # see gh-7310 + # see gh-7310, GH#55609 tz = tz_naive_fixture idx = DatetimeIndex(dates, tz=tz).as_unit(unit) assert idx.inferred_freq == expected