Skip to content

BUG: datetime index name droped after date_range selection #47545

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

Closed
2 of 3 tasks
SylvainLan opened this issue Jun 29, 2022 · 1 comment
Closed
2 of 3 tasks

BUG: datetime index name droped after date_range selection #47545

SylvainLan opened this issue Jun 29, 2022 · 1 comment
Labels
Bug Duplicate Report Duplicate issue or pull request

Comments

@SylvainLan
Copy link
Contributor

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({'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)

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

@SylvainLan SylvainLan added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jun 29, 2022
simonjayhawkins added a commit to simonjayhawkins/pandas that referenced this issue Jul 5, 2022
@simonjayhawkins
Copy link
Member

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

pd.date_range('20220101', '20220102') creates an DatetimeIndex(['2022-01-01', '2022-01-02'], dtype='datetime64[ns]', freq='D') without a name.

@simonjayhawkins simonjayhawkins added Duplicate Report Duplicate issue or pull request and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Duplicate Report Duplicate issue or pull request
Projects
None yet
Development

No branches or pull requests

2 participants