Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Collision between equivalent frequencies 'QS-… #61142

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,7 @@ Datetimelike
- Bug in :meth:`DatetimeIndex.is_year_start` and :meth:`DatetimeIndex.is_quarter_start` returning ``False`` on double-digit frequencies (:issue:`58523`)
- Bug in :meth:`DatetimeIndex.union` and :meth:`DatetimeIndex.intersection` when ``unit`` was non-nanosecond (:issue:`59036`)
- Bug in :meth:`Series.dt.microsecond` producing incorrect results for pyarrow backed :class:`Series`. (:issue:`59154`)
- Bug in :meth:`_validate_inferred_freq` where DateTimeIndex incorrectly raised a ``ValueError`` when assigning a logically equivalent frequency (:issue:`61086`)
- Bug in :meth:`to_datetime` not respecting dayfirst if an uncommon date string was passed. (:issue:`58859`)
- Bug in :meth:`to_datetime` on float array with missing values throwing ``FloatingPointError`` (:issue:`58419`)
- Bug in :meth:`to_datetime` on float32 df with year, month, day etc. columns leads to precision issues and incorrect result. (:issue:`60506`)
Expand Down
7 changes: 6 additions & 1 deletion pandas/core/arrays/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -2519,8 +2519,13 @@ def _validate_inferred_freq(
-------
freq : DateOffset or None
"""
offset1 = to_offset(freq)
offset2 = to_offset(inferred_freq)

freq_equal = type(offset1) == type(offset2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think this is sufficient, for example QuarterBegin: startingMonth=2 and QuarterBegin: startingMonth=3 will both have the same type, but are not the same frequency.


if inferred_freq is not None:
if freq is not None and freq != inferred_freq:
if freq is not None and not freq_equal:
raise ValueError(
f"Inferred frequency {inferred_freq} from passed "
"values does not conform to passed frequency "
Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/indexes/datetimes/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1204,3 +1204,10 @@ def test_dti_constructor_object_dtype_dayfirst_yearfirst_with_tz(self):
result2 = DatetimeIndex([val], tz="US/Pacific", yearfirst=True)
expected2 = DatetimeIndex([yfirst]).as_unit("s")
tm.assert_index_equal(result2, expected2)

def test_validate_inferred_freq_equivalence(self):
idx = date_range("2020-02-01", freq="QS-FEB", periods=4)

new_idx = DatetimeIndex(idx, freq="QS-MAY")

assert isinstance(new_idx, DatetimeIndex)
Loading