Pandas version checks
-
[X] I have checked that this issue has not already been reported.
-
[X] I have confirmed this bug exists on the latest version of pandas.
-
[X] I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
import pandas as pd
df = pd.DataFrame(index=pd.date_range(start="2014-01-01", end="2023-01-01", freq="MS"))
df.resample("QS").sum().loc["2014-Q1"]
Issue Description
The example above throws a key error.
Interestingly, df.resample("QS").sum().loc["2015-Q1"]
yields the indices corresponding to the first quarter of 2014.
See stackoverflow issue.
https://stackoverflow.com/questions/78315553/pandas-bug-when-trying-to-loc-data-on-a-quarter/78320367?
Expected Behavior
The view should be on the first quarter of 2014. Expected output is
Empty DataFrame
Columns: []
Index: [2014-01-01 00:00:00]
but it doesn't find it. Instead, I get the following with another indexing
In [12]: df_resampled.loc["2015-Q1"]
Out[12]:
Empty DataFrame
Columns: []
Index: [2014-01-01 00:00:00]
Note that the problem disappears if I do
df_resampled.freq = None
df_resampled.loc["2014-Q1"]
In which case the correct output is yielded.
Installed Versions
Comment From: rhshadrach
Thanks for the report. The result of resample has freq as <QuarterBegin: startingMonth=1>
. With this on the index, the lookup for "2014-Q1"
is looking for Timestamp('2013-02-01 00:00:00')
which seems off to me.
It doesn't appear to me that resample is the issue.
cc @MarcoGorelli
Comment From: MarcoGorelli
thanks for the ping, adding this to my mental list of quarter oddities https://github.com/pandas-dev/pandas/issues/8435#issuecomment-2012433875
Comment From: tuhinsharma121
anyone working on it? Can I give it a try?
Comment From: tuhinsharma121
take