Skip to content

Commit 7c052bf

Browse files
committed
TST: Add regression test for infer_freq stateful behavior (#55794)
1 parent 1b5b02c commit 7c052bf

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

pandas/tests/tseries/frequencies/test_inference.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,3 +556,19 @@ def test_infer_freq_pyarrow():
556556
assert frequencies.infer_freq(pd_series.values) == "30s"
557557
assert frequencies.infer_freq(pd_index) == "30s"
558558
assert frequencies.infer_freq(pd_series) == "30s"
559+
560+
561+
def test_infer_freq_no_stateful_behavior():
562+
# GH#55794 infer_freq should not have stateful behavior
563+
# calling infer_freq on a full index with duplicates should not
564+
# affect the result of calling it on a slice without duplicates
565+
times = to_datetime(["2019-01-01", "2019-01-02", "2019-01-03", "2019-01-03"])
566+
567+
# Before calling infer_freq on full index
568+
assert frequencies.infer_freq(times[:3]) == "D"
569+
570+
# Call on full index (which has duplicates, so returns None)
571+
frequencies.infer_freq(times)
572+
573+
# After calling on full index, slice should still return "D"
574+
assert frequencies.infer_freq(times[:3]) == "D"

0 commit comments

Comments
 (0)