-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: freq information lost after stack() is called #49054
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
Comments
Hi @MMCMA I think it is only happening when I do In [64]: idx = pd.date_range('20200101', periods=12, freq='BM')
In [65]: df = pd.DataFrame(dict(a=range(12)), index=idx)
In [66]: df.index
Out[66]:
DatetimeIndex(['2020-01-31', '2020-02-28', '2020-03-31', '2020-04-30',
'2020-05-29', '2020-06-30', '2020-07-31', '2020-08-31',
'2020-09-30', '2020-10-30', '2020-11-30', '2020-12-31'],
dtype='datetime64[ns]', freq='BM')
In [67]: df2 = df.stack()
In [68]: df.index
Out[68]:
DatetimeIndex(['2020-01-31', '2020-02-28', '2020-03-31', '2020-04-30',
'2020-05-29', '2020-06-30', '2020-07-31', '2020-08-31',
'2020-09-30', '2020-10-30', '2020-11-30', '2020-12-31'],
dtype='datetime64[ns]', freq='BM')
In [69]: df2.index
Out[69]:
MultiIndex([('2020-01-31', 'a'),
('2020-02-28', 'a'),
('2020-03-31', 'a'),
('2020-04-30', 'a'),
('2020-05-29', 'a'),
('2020-06-30', 'a'),
('2020-07-31', 'a'),
('2020-08-31', 'a'),
('2020-09-30', 'a'),
('2020-10-30', 'a'),
('2020-11-30', 'a'),
('2020-12-31', 'a')],
)
In [70]: df.index
Out[70]:
DatetimeIndex(['2020-01-31', '2020-02-28', '2020-03-31', '2020-04-30',
'2020-05-29', '2020-06-30', '2020-07-31', '2020-08-31',
'2020-09-30', '2020-10-30', '2020-11-30', '2020-12-31'],
dtype='datetime64[ns]', freq=None) |
Yes, I can replicate this with pandas 1.5.0, I also checked an older pandas version and the freq property in |
Simple reproducer:
|
Hey @MMCMA Thanks for having reported this - there's now a release candidate for pandas 2.0.0, which you can install with
or
If you try it out and report bugs, then we can fix them before the final 2.0.0 release |
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
Some of our CI pipeline unittests failed after upgrading to pandas 1.5.0 (linux). (I can't share this example.)
I tried to replicate the error above locally, and it seems to behave the same way. However, the same issue is only visible in ipython within my pycharm console. When I open a python instance via cmd, I cannot replicate the behaviour, which makes this bug a bit harder to trace I believe.
Expected Behavior
I would expect that the index.freq property would not be lost
Installed Versions
INSTALLED VERSIONS
commit : 87cfe4e
python : 3.9.7.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19043
machine : AMD64
processor : Intel64 Family 6 Model 142 Stepping 12, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_United States.1252
pandas : 1.5.0
numpy : 1.22.4
pytz : 2021.3
dateutil : 2.8.2
setuptools : 58.0.4
pip : 21.2.4
Cython : 0.29.25
pytest : 6.2.4
hypothesis : None
sphinx : 4.3.1
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.6.4
html5lib : None
pymysql : None
psycopg2 : 2.9.3
jinja2 : 3.0.3
IPython : 7.29.0
pandas_datareader: 0.10.0
bs4 : None
bottleneck : None
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.5.0
numba : 0.55.2
numexpr : None
odfpy : None
openpyxl : 3.0.9
pandas_gbq : None
pyarrow : 8.0.0
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.7.3
snappy : None
sqlalchemy : 1.4.31
tables : None
tabulate : 0.8.9
xarray : None
xlrd : None
xlwt : None
zstandard : None
tzdata : None
The text was updated successfully, but these errors were encountered: