Pandas version checks
-
[X] I have checked that this issue has not already been reported.
-
[X] I have confirmed this bug exists on the latest version of pandas.
-
[X] I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
In [1]: pdf = pd.DataFrame({"idx": [0, 1, 2], "A": [1, 2, 3]}).set_index('idx')
[PYFLYBY] import pandas as pd
In [2]: pdf
Out[2]:
A
idx
0 1
1 2
2 3
In [3]: pdf.to_parquet("~/tmp/test.parquet")
In [4]: with pd.option_context("mode.dtype_backend", "pyarrow"):
...: df = pd.read_parquet("~/tmp/test.parquet")
...:
In [5]: df
Out[5]:
A idx
0 1 0
1 2 1
2 3 2
In [6]: pd.__version__
Out[6]: '2.1.0.dev0+93.g6bb8f73e75'
Issue Description
Roundtripping a DataFrame with an index to parquet and back under the options mode mode.type_backend='pyarrow'
causes indexes to be dropped.
Expected Behavior
I think pd.read_parquet should read from the schema (in particular pandas_metadata['index_columns']
to set the index. I don't think this is a bug in a lower level library like pyarrow since I think (?) indexes are a Pandas-specific abstraction. I assume there's some reason that setting the option mode skips pandas_compat._reconstruct_index
, but I can't figure it out.
This is what I expect to see instead:
In [16]: df = df.set_index('idx')
In [17]: df.info()
<class 'pandas.core.frame.DataFrame'>
Index: 3 entries, 0 to 2
Data columns (total 1 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 A 3 non-null int64[pyarrow]
dtypes: int64[pyarrow](1)
memory usage: 50.0 bytes
In [18]: df.index
Out[18]: Index([0, 1, 2], dtype='int64[pyarrow]', name='idx')
Thanks for the help!
Installed Versions
Comment From: phofl
Hi, this will be fixed with pyarrow 12.0, so I don't think we should do anything here.
Comment From: mroeschke
Agreed, closing as an upstream issue