Skip to content

BUG: The frequency of a DatetimeIndex is lost when using to_parquet with pyarrow #41543

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
3 tasks done
TanguyLe opened this issue May 18, 2021 · 1 comment
Open
3 tasks done
Labels
Bug freq retention User expects "freq" attribute to be preserved Frequency DateOffsets IO Parquet parquet, feather

Comments

@TanguyLe
Copy link

TanguyLe commented May 18, 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.


Code Sample

import pandas as pd

df = pd.DataFrame(
    [1, 2, 3], 
    columns=['a'],
    index=pd.date_range(
        freq="1T", 
        start="2021-01-01 00:00:00", 
        end="2021-01-01 00:02:00"
    )
)

df.to_parquet("test.parquet", engine="pyarrow")

pd.testing.assert_frame_equal(pd.read_parquet("test.parquet", engine="pyarrow"), df)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".../lib/python3.8/site-packages/pandas/_testing.py", line 1704, in assert_frame_equal
    assert_series_equal(
  File ".../python3.8/site-packages/pandas/_testing.py", line 1389, in assert_series_equal
    assert lidx.freq == ridx.freq, (lidx.freq, ridx.freq)
AssertionError: (None, <Minute>)

Problem description

With the following versions:

  • pandas: 1.2.4
  • pyarrow: 4.0.0

The bug is different with fastparquet, but there seem to be also a consistency issue (the index name).

Which I didn't see in earlier versions of pandas/fastparquet (0.25.3/0.4.1), I didn't try other combinations.
EDIT: It wasn't happening before most likely because assert_frame_equal wasn't checking the index frequency, not because it was there.

It seems that the index frequency is not passed in the pandas metadata within the table.

Maybe I'm missing a pyarrow option to make this happen, but I still feel like the index should be either discarded completely or kept in a compatible manner.

Expected Output

No exception raised and an index with the same attributes as the original one.

Output of pd.show_versions()

INSTALLED VERSIONS

commit : 2cb9652
python : 3.8.8.final.0
python-bits : 64
OS : Linux
OS-release : 5.4.0-72-generic
Version : #80~18.04.1-Ubuntu SMP Mon Apr 12 23:26:25 UTC 2021
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.2.4
numpy : 1.20.3
pytz : 2021.1
dateutil : 2.8.1
pip : 21.0.1
setuptools : 52.0.0.post20210125
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
fsspec : 2021.05.0
fastparquet : 0.6.3
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 4.0.0
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None

@TanguyLe TanguyLe added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels May 18, 2021
@jbrockmendel jbrockmendel added the IO Parquet parquet, feather label Jun 6, 2021
@mroeschke mroeschke added Frequency DateOffsets and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 20, 2021
@jbrockmendel
Copy link
Member

@jorisvandenbossche is there something we can pass to pyarrow in to_parquet to retain this?

@jbrockmendel jbrockmendel added the freq retention User expects "freq" attribute to be preserved label Aug 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug freq retention User expects "freq" attribute to be preserved Frequency DateOffsets IO Parquet parquet, feather
Projects
None yet
Development

No branches or pull requests

3 participants