Skip to content
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

BUG: Write and read parquet changes index type from PeriodIndex to int values of DataFrame with MultiIndex #49641

Open
3 tasks done
aiwalter opened this issue Nov 11, 2022 · 0 comments
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member

Comments

@aiwalter
Copy link

aiwalter commented Nov 11, 2022

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

# Running example with "DATE" as DatetimeIndex instead PeriodIndex (this works well)
import pandas as pd
data = pd.DataFrame({
  "ID": ["A", "B", "C"],
  "DATE": ["2020-01-01", "2020-01-02", "2020-01-03"],
  "VALUE": [11, 22, 22],
})

data["DATE"] = pd.DatetimeIndex(data["DATE"], freq="D")
types = data.dtypes
data = data.set_index(["ID", "DATE"])
data.to_parquet("data")
assert (pd.read_parquet("data").reset_index().dtypes == types).all()

# NOT running example with "DATE" as PeriodIndex (this fails!)
import pandas as pd
data = pd.DataFrame({
  "ID": ["A", "B", "C"],
  "DATE": ["2020-01-01", "2020-01-02", "2020-01-03"],
  "VALUE": [11, 22, 22],
})

data["DATE"] = pd.DatetimeIndex(data["DATE"], freq="D").to_period()
types = data.dtypes
data = data.set_index(["ID", "DATE"])
data.to_parquet("data")
assert (pd.read_parquet("data").reset_index().dtypes == types).all()

Issue Description

When I write a DataFrame with a MultiIndex that has one level as PeriodIndex, after write and read the PeriodIndex was casted into int values:

Before:
image

After write and read:
image

Expected Behavior

it works fine with DatetimeIndex so I would also expect it to work with PeriodIndex

Installed Versions

INSTALLED VERSIONS

commit : 91111fd
python : 3.8.10.final.0
python-bits : 64
OS : Linux
OS-release : 5.4.0-1090-azure
Version : #95~18.04.1-Ubuntu SMP Sun Aug 14 20:09:27 UTC 2022
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : C.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.5.1
numpy : 1.23.4
pytz : 2020.5
dateutil : 2.8.1
setuptools : 52.0.0
pip : 21.0.1
Cython : 0.29.23
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : 2.8.5
jinja2 : 2.11.3
IPython : 7.22.0
pandas_datareader: None
bs4 : None
bottleneck : None
brotli : None
fastparquet : None
fsspec : 0.9.0
gcsfs : None
matplotlib : 3.4.2
numba : None
numexpr : None
odfpy : None
openpyxl : 3.0.7
pandas_gbq : None
pyarrow : 4.0.0
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.6.2
snappy : None
sqlalchemy : None
tables : None
tabulate : 0.8.7
xarray : None
xlrd : None
xlwt : None
zstandard : None
tzdata : None

@aiwalter aiwalter added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Nov 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member
Projects
None yet
Development

No branches or pull requests

1 participant