From fdcdd4c2dc4f7ab049879cbaa64cfc430b0b86d9 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Sun, 22 Oct 2023 12:30:48 -0700 Subject: [PATCH] BUG: inferred_freq with non-nano (#55609) * BUG: inferred_freq with non-nano * GH ref --- doc/source/whatsnew/v2.2.0.rst | 1 + pandas/tests/tseries/frequencies/test_inference.py | 7 ++++--- pandas/tseries/frequencies.py | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/doc/source/whatsnew/v2.2.0.rst b/doc/source/whatsnew/v2.2.0.rst index c8c27f2f2e178..679845eb0098c 100644 --- a/doc/source/whatsnew/v2.2.0.rst +++ b/doc/source/whatsnew/v2.2.0.rst @@ -410,6 +410,7 @@ 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`) diff --git a/pandas/tests/tseries/frequencies/test_inference.py b/pandas/tests/tseries/frequencies/test_inference.py index aec9915d69e3c..867363e1a03bc 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): - # see gh-7310 +@pytest.mark.parametrize("unit", ["s", "ms", "us", "ns"]) +def test_infer_freq_tz(tz_naive_fixture, expected, dates, unit): + # see gh-7310, GH#55609 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)