Skip to content

BUG: freq attribute is None after set_index #42747

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

Open
2 of 3 tasks
antvig opened this issue Jul 27, 2021 · 8 comments
Open
2 of 3 tasks

BUG: freq attribute is None after set_index #42747

antvig opened this issue Jul 27, 2021 · 8 comments
Labels
Bug Datetime Datetime data dtype Internals Related to non-user accessible pandas implementation Regression Functionality that used to work in a prior pandas version

Comments

@antvig
Copy link

antvig commented Jul 27, 2021

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

df = pd.DataFrame({"datetime": pd.date_range("1/1/1", periods=20, freq="H", tz="UTC")})

df.set_index("datetime", inplace=True)

df.index.freq --> `None`

Problem description

This behavior is new in 1.3.0 and 1.3.1.

In 1.2.5, the output was, as expected, H

Expected Output

'H'

Output of pd.show_versions()

INSTALLED VERSIONS

commit : c7f7443
python : 3.8.10.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19041
machine : AMD64
processor : Intel64 Family 6 Model 158 Stepping 13, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : fr_FR.cp1252
pandas : 1.3.1
numpy : 1.21.1
pytz : 2021.1
dateutil : 2.8.2
pip : 21.1.3
setuptools : 57.4.0
Cython : None
pytest : 6.2.4
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
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : 1.7.0
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None

@antvig antvig added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 27, 2021
simonjayhawkins added a commit to simonjayhawkins/pandas that referenced this issue Jul 27, 2021
@simonjayhawkins
Copy link
Member

Thanks @antvig for the report.

This behavior is new in 1.3.0 and 1.3.1.

first bad commit: [6b6d8fd] REF: Back DatetimeTZBlock with sometimes-2D DTA (#41082) cc @jbrockmendel

@simonjayhawkins simonjayhawkins added Internals Related to non-user accessible pandas implementation Regression Functionality that used to work in a prior pandas version Datetime Datetime data dtype and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 27, 2021
@simonjayhawkins simonjayhawkins added this to the 1.3.2 milestone Jul 27, 2021
@jbrockmendel
Copy link
Member

This behavior matches what happens with tznaive DTI (which i think theres an issue about), is unavoidable

@simonjayhawkins simonjayhawkins modified the milestones: 1.3.2, 1.3.3 Aug 15, 2021
@simonjayhawkins simonjayhawkins modified the milestones: 1.3.3, 1.3.4 Sep 11, 2021
@simonjayhawkins
Copy link
Member

changing milestone to 1.3.5

@simonjayhawkins simonjayhawkins modified the milestones: 1.3.4, 1.3.5 Oct 16, 2021
@jbrockmendel
Copy link
Member

@simonjayhawkins there's essentially no prospect for this to change for 1.3.5

@simonjayhawkins
Copy link
Member

@simonjayhawkins there's essentially no prospect for this to change for 1.3.5

Can you elaborate. Is the new behavior considered correct? If not, why can't this be fixed.

@jreback
Copy link
Contributor

jreback commented Nov 28, 2021

good to fix but not needed for 1.3.x

@jbrockmendel
Copy link
Member

Can you elaborate. Is the new behavior considered correct? If not, why can't this be fixed.

The changed behavior is driven by the fact that when you do reset_index with a DTI/TDI, it is unwrapped to DTA/TDA to become a column and reshaped to 2D. 2D DTA/TDA never have non-None freq. We could "cheat" here since it is single-column and retain the freq, but that would only be until 2.0 when DTA/TDA will lost the freq attr entirely (xref #31218)

@simonjayhawkins
Copy link
Member

moving off 1.3.x milestone

@simonjayhawkins simonjayhawkins modified the milestones: 1.3.5, Contributions Welcome Dec 11, 2021
@mroeschke mroeschke removed this from the Contributions Welcome milestone Oct 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Datetime Datetime data dtype Internals Related to non-user accessible pandas implementation Regression Functionality that used to work in a prior pandas version
Projects
None yet
Development

No branches or pull requests

5 participants