Description
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
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.
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
INSTALLED VERSIONS
commit : bdc79c1
python : 3.12.2.final.0
python-bits : 64
OS : Darwin
OS-release : 23.4.0
Version : Darwin Kernel Version 23.4.0: Fri Mar 15 00:12:49 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6020
machine : arm64
processor : arm
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.UTF-8
pandas : 2.2.1
numpy : 1.26.4
pytz : 2023.3.post1
dateutil : 2.8.2
setuptools : 68.2.2
pip : 23.3.1
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : 8.20.0
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
bottleneck : 1.3.7
dataframe-api-compat : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : 2.8.7
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.3
qtpy : None
pyqt5 : None