-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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-FEB' and 'QS-NOV' #61086
Comments
Thanks for the report. When setting the attribute, pandas generates the NumPy array with the new frequency and confirms that it matches the data underlying the DatetimeIndex. I'd be supportive of doing the same in
Edit: Any frequency can be equivalent to some other, I think. |
Thanks for the quick triage! Another welcome addition would be a method like Analogous methods exist for changing other properties of (a copy of) the index - to such as If that exists, I'd prefer it over using |
Take |
…ncies 'QS-FEB' and 'QS-NOV'
I think this should be separated off into its own issue. Can you open a new one with this enhancement request. |
Yes, I agree. See here. |
…ncies 'QS-FEB' and 'QS-NOV'
…ncies 'QS-FEB' and 'QS-NOV'
|
To react to your point 2.: One advantage of the distinction is e.g. business years starting in e.g. November. Aggregating to years, we need to use "YS-NOV". Aggregating to quarters can currently be done with "QS-NOV", which is more intuitive than having to use "QS-FEB". However, I agree with you and think the disadvantages outweigh this advantage. And the current implementation is unreliable anyway: i = pd.date_range('2025-02', freq='QS-MAY', periods=3)
i.inferred_freq # 'QS-NOV' (!) From where I'm standing, the best compromise is to have 3 main QS-frequencies (QS-JAN, -FEB, -MAR), and consider the others as aliases.
|
Pandas version checks
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
Issue Description
pd.DatetimeIndex(...)
, when passed both an index with a frequency, AND a frequency, throws an error if the frequencies are unequal - even if they are equivalent.Expected Behavior
If the frequencies are unequal, but equivalent (like in the example), an index with the specified (new) frequency should be returned.
That the frequencies are equivalent can be seen in the following snippet: simply direct setting the frequency of
i
to the specified frequency DOES work:I think this only occurs for quarter-frequency, where "equivalent" means that the starting month mod 3 is equal.
Current workaround:
We don't want to change
i
, so the current workaround toi2 = pd.DatetimeIndex(i, freq='QS-FEB')
is...which is cumbersome, because it requires 2 steps and cannot be used in list comprehensions etc.
Alternatively, there is the elegant
Installed Versions
pandas : 2.2.3
numpy : 2.1.1
pytz : 2024.2
dateutil : 2.9.0.post0
pip : 24.2
Cython : None
sphinx : None
IPython : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
blosc : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : None
lxml.etree : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
psycopg2 : None
pymysql : None
pyarrow : None
pyreadstat : None
pytest : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlsxwriter : None
zstandard : None
tzdata : 2024.2
qtpy : None
pyqt5 : None
The text was updated successfully, but these errors were encountered: