We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
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.
import pandas as pd df = pd.DataFrame({'date': [pd.to_datetime(d) for d in ['20220101', '20220102', '20220103']], 'value': [1, 2, 3]}) df = df.set_index('date') print(df.loc[slice('20220101', '20220102'), :].index.name) print(df.loc[pd.date_range('20220101', '20220102'), :].index.name)
Hello,
I realized that using a date_range object with .loc on a datetime indexed dataframe drops the name of the corresponding index.
date_range
.loc
I'm not sure this behavior is normal.
The name of the index should be kept
commit : e8093ba python : 3.8.10.final.0 python-bits : 64 OS : Linux OS-release : 4.20.0-042000-generic Version : #201812232030 SMP Mon Dec 24 01:32:58 UTC 2018 machine : x86_64 processor : x86_64 byteorder : little LC_ALL : None LANG : en_US.UTF-8 LOCALE : en_US.UTF-8
pandas : 1.4.3 numpy : 1.23.0 pytz : 2022.1 dateutil : 2.8.2 setuptools : 44.0.0 pip : 20.0.2 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 : None pandas_datareader: None bs4 : None bottleneck : None brotli : None fastparquet : None fsspec : None gcsfs : None markupsafe : None matplotlib : None numba : None numexpr : None odfpy : None openpyxl : None pandas_gbq : None pyarrow : None pyreadstat : None pyxlsb : None s3fs : None scipy : None snappy : None sqlalchemy : None tables : None tabulate : None xarray : None xlrd : None xlwt : None zstandard : None
The text was updated successfully, but these errors were encountered:
code sample for pandas-dev#47545
7cfca3f
Thanks @SylvainLan for the report. Looks like a duplicate of #45818
Expected Behavior The name of the index should be kept
This was indeed the case in pandas-1.3.5
There was an intentional change in commit: [4a2096d] CI: Fix doctests (#42790) to preserve the name from an Index
Index
pd.date_range('20220101', '20220102') creates an DatetimeIndex(['2022-01-01', '2022-01-02'], dtype='datetime64[ns]', freq='D') without a name.
pd.date_range('20220101', '20220102')
DatetimeIndex(['2022-01-01', '2022-01-02'], dtype='datetime64[ns]', freq='D')
Sorry, something went wrong.
No branches or pull requests
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
Hello,
I realized that using a
date_range
object with.loc
on a datetime indexed dataframe drops the name of the corresponding index.I'm not sure this behavior is normal.
Expected Behavior
The name of the index should be kept
Installed Versions
INSTALLED VERSIONS
commit : e8093ba
python : 3.8.10.final.0
python-bits : 64
OS : Linux
OS-release : 4.20.0-042000-generic
Version : #201812232030 SMP Mon Dec 24 01:32:58 UTC 2018
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.4.3
numpy : 1.23.0
pytz : 2022.1
dateutil : 2.8.2
setuptools : 44.0.0
pip : 20.0.2
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 : None
pandas_datareader: None
bs4 : None
bottleneck : None
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
markupsafe : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : None
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None
The text was updated successfully, but these errors were encountered: