Skip to content

Commit fdcdd4c

Browse files
authored
BUG: inferred_freq with non-nano (#55609)
* BUG: inferred_freq with non-nano * GH ref
1 parent 54a65e0 commit fdcdd4c

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

doc/source/whatsnew/v2.2.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ Styler
410410
Other
411411
^^^^^
412412
- Bug in :func:`cut` incorrectly allowing cutting of timezone-aware datetimes with timezone-naive bins (:issue:`54964`)
413+
- Bug in :func:`infer_freq` and :meth:`DatetimeIndex.inferred_freq` with weekly frequencies and non-nanosecond resolutions (:issue:`55609`)
413414
- Bug in :meth:`DataFrame.apply` where passing ``raw=True`` ignored ``args`` passed to the applied function (:issue:`55009`)
414415
- Bug in rendering ``inf`` values inside a a :class:`DataFrame` with the ``use_inf_as_na`` option enabled (:issue:`55483`)
415416
- 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`)

pandas/tests/tseries/frequencies/test_inference.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,11 @@ def test_infer_freq_index(freq, expected):
229229
}.items()
230230
),
231231
)
232-
def test_infer_freq_tz(tz_naive_fixture, expected, dates):
233-
# see gh-7310
232+
@pytest.mark.parametrize("unit", ["s", "ms", "us", "ns"])
233+
def test_infer_freq_tz(tz_naive_fixture, expected, dates, unit):
234+
# see gh-7310, GH#55609
234235
tz = tz_naive_fixture
235-
idx = DatetimeIndex(dates, tz=tz)
236+
idx = DatetimeIndex(dates, tz=tz).as_unit(unit)
236237
assert idx.inferred_freq == expected
237238

238239

pandas/tseries/frequencies.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ def fields(self) -> np.ndarray: # structured array of fields
276276

277277
@cache_readonly
278278
def rep_stamp(self) -> Timestamp:
279-
return Timestamp(self.i8values[0])
279+
return Timestamp(self.i8values[0], unit=self.index.unit)
280280

281281
def month_position_check(self) -> str | None:
282282
return month_position_check(self.fields, self.index.dayofweek)

0 commit comments

Comments
 (0)