Skip to content

Commit 3289f82

Browse files
fix #39556 (infer_freq not working with freq="H" and DST (#39644)
* fix #39556: - check that the delta are unique before checking if the are day multiples - add test with freq="H" that raises the bug * fix lint * when freq=="B", the deltas are not unique (1 or 3 days) => change by taking for delta the minimum of deltas and checking delta is not null * add whatsnew entry * as self.deltas is already ordered, deltas[0] is the minimum delta Co-authored-by: GFJ138 <[email protected]>
1 parent be35ea2 commit 3289f82

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

doc/source/whatsnew/v1.3.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ Datetimelike
300300
- Bug in :meth:`Timestamp.round`, :meth:`Timestamp.floor`, :meth:`Timestamp.ceil` for values near the implementation bounds of :class:`Timestamp` (:issue:`39244`)
301301
- Bug in :meth:`Timedelta.round`, :meth:`Timedelta.floor`, :meth:`Timedelta.ceil` for values near the implementation bounds of :class:`Timedelta` (:issue:`38964`)
302302
- Bug in :func:`date_range` incorrectly creating :class:`DatetimeIndex` containing ``NaT`` instead of raising ``OutOfBoundsDatetime`` in corner cases (:issue:`24124`)
303+
- Bug in :func:`infer_freq` incorrectly fails to infer 'H' frequency of :class:`DatetimeIndex` if the latter has a timezone and crosses DST boundaries (:issue:`39556`)
303304

304305
Timedelta
305306
^^^^^^^^^

pandas/tests/tseries/frequencies/test_inference.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ def test_infer_freq_tz(tz_naive_fixture, expected, dates):
280280
],
281281
)
282282
@pytest.mark.parametrize(
283-
"freq", ["3H", "10T", "3601S", "3600001L", "3600000001U", "3600000000001N"]
283+
"freq", ["H", "3H", "10T", "3601S", "3600001L", "3600000001U", "3600000000001N"]
284284
)
285285
def test_infer_freq_tz_transition(tz_naive_fixture, date_pair, freq):
286286
# see gh-8772

pandas/tseries/frequencies.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -246,16 +246,17 @@ def get_freq(self) -> Optional[str]:
246246
return None
247247

248248
delta = self.deltas[0]
249-
if _is_multiple(delta, _ONE_DAY):
249+
if delta and _is_multiple(delta, _ONE_DAY):
250250
return self._infer_daily_rule()
251251

252252
# Business hourly, maybe. 17: one day / 65: one weekend
253253
if self.hour_deltas in ([1, 17], [1, 65], [1, 17, 65]):
254254
return "BH"
255+
255256
# Possibly intraday frequency. Here we use the
256257
# original .asi8 values as the modified values
257258
# will not work around DST transitions. See #8772
258-
elif not self.is_unique_asi8:
259+
if not self.is_unique_asi8:
259260
return None
260261

261262
delta = self.deltas_asi8[0]

0 commit comments

Comments
 (0)