You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Python/C++] Empty column selection no longer restores index #21621
The index of a dataframe is no longer reconstructed when using empty column selection. This is a regression to 0.12.1 and probably only happens for pd.RangeIndex
Joris Van den Bossche / @jorisvandenbossche: @fjetter thanks for the report! A little bit simpler reproducible example, without parquet (but the same underlying reason, the rangeindex is indeed not constructed again for empty tables):
Joris Van den Bossche / @jorisvandenbossche:
A "quick and dirty" fix would be to special case tables with zero rows and zero columns in the check in _reconstruct_index (
), when recreating the pandas DataFrame from an empty arrow Table.
But I think the proper fix to this would be to allow the Table to have a non-zero num_rows. However, this would need separate fixes depending on where the Table is created (so eg a separate fix in the Table.from_pandas(columns=[]) and the parquet read code, for both examples above), and complicate the code in several places, so I am not sure we want to go down that route. (cc @wesm ?)
Joris Van den Bossche / @jorisvandenbossche:
Now we add the preserve_index=None / True distinction, the original example with preserve_index=True is working again as expected.
When doing the same example with the default of None (pa.Table.from_pandas(df, columns=[], preserve_index=None).to_pandas()), that still gives the same problem as reported.
For that one, I am not sure what is the best solution (do we want to go down the route of a Table having 0 columns but a non-zero num_rows ?)
Activity
asfimport commentedon May 6, 2019
Joris Van den Bossche / @jorisvandenbossche:
@fjetter thanks for the report! A little bit simpler reproducible example, without parquet (but the same underlying reason, the rangeindex is indeed not constructed again for empty tables):
But the above, now gives:
asfimport commentedon May 6, 2019
Joris Van den Bossche / @jorisvandenbossche:
A "quick and dirty" fix would be to special case tables with zero rows and zero columns in the check in
_reconstruct_index(arrow/python/pyarrow/pandas_compat.py
Lines 695 to 697 in 982f341
But I think the proper fix to this would be to allow the Table to have a non-zero
num_rows. However, this would need separate fixes depending on where the Table is created (so eg a separate fix in theTable.from_pandas(columns=[])and the parquet read code, for both examples above), and complicate the code in several places, so I am not sure we want to go down that route. (cc @wesm ?)asfimport commentedon Aug 22, 2019
Wes McKinney / @wesm:
Added to 0.15.0 in case something can be done
asfimport commentedon Sep 17, 2019
Joris Van den Bossche / @jorisvandenbossche:
Now we add the
preserve_index=None / Truedistinction, the original example withpreserve_index=Trueis working again as expected.When doing the same example with the default of None (
pa.Table.from_pandas(df, columns=[], preserve_index=None).to_pandas()), that still gives the same problem as reported.For that one, I am not sure what is the best solution (do we want to go down the route of a Table having 0 columns but a non-zero
num_rows?)asfimport commentedon Aug 5, 2021
Antoine Pitrou / @pitrou:
Do we want to act on this?
thisisnic commentedon Oct 23, 2026
No longer reproduces, closing!