Skip to content

Commit 967f39e

Browse files
- check that the delta are unique before checking if the are day multiples - add test with freq="H" that raises the bug
1 parent d558bce commit 967f39e

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

pandas/tests/tseries/frequencies/test_inference.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ def test_infer_freq_tz(tz_naive_fixture, expected, dates):
267267
],
268268
)
269269
@pytest.mark.parametrize(
270-
"freq", ["3H", "10T", "3601S", "3600001L", "3600000001U", "3600000000001N"]
270+
"freq", ["H", "3H", "10T", "3601S", "3600001L", "3600000001U", "3600000000001N"]
271271
)
272272
def test_infer_freq_tz_transition(tz_naive_fixture, date_pair, freq):
273273
# see gh-8772

pandas/tseries/frequencies.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -239,17 +239,17 @@ def get_freq(self) -> Optional[str]:
239239
if not self.is_monotonic or not self.index._is_unique:
240240
return None
241241

242-
delta = self.deltas[0]
243-
if _is_multiple(delta, _ONE_DAY):
242+
if self.is_unique and _is_multiple(self.deltas[0], _ONE_DAY):
244243
return self._infer_daily_rule()
245244

246245
# Business hourly, maybe. 17: one day / 65: one weekend
247246
if self.hour_deltas in ([1, 17], [1, 65], [1, 17, 65]):
248247
return "BH"
248+
249249
# Possibly intraday frequency. Here we use the
250250
# original .asi8 values as the modified values
251251
# will not work around DST transitions. See #8772
252-
elif not self.is_unique_asi8:
252+
if not self.is_unique_asi8:
253253
return None
254254

255255
delta = self.deltas_asi8[0]
@@ -414,7 +414,7 @@ def _infer_daily_rule(self):
414414

415415

416416
def _is_multiple(us, mult: int) -> bool:
417-
return us % mult == 0
417+
return (us % mult == 0)
418418

419419

420420
def _maybe_add_count(base: str, count: float) -> str:

0 commit comments

Comments
 (0)