Skip to content

BUG: read_parquet wrongly returns empty index if asked to read empty column list #59028

Open
@batterseapower

Description

@batterseapower

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

import pandas as pd
import pyarrow as pa
import pyarrow.parquet as pq

pd.DataFrame(index=['A', 'B'], columns=['C', 'D']).to_parquet('temp.parquet')

# All correctly print 2
print(len(pd.read_parquet('temp.parquet', columns=['C']).index))
print(len(pd.read_parquet('temp.parquet', columns=[]).index))
print(pq.read_table('temp.parquet', columns=[]).num_rows)
print(len(pq.read_table('temp.parquet', columns=[]).to_pandas().index))

pd.DataFrame(index=pd.RangeIndex(2), columns=['C', 'D']).to_parquet('temp.parquet')

# Correctly prints 2
print(len(pd.read_parquet('temp.parquet', columns=['C']).index))
# BUG: prints 0!
print(len(pd.read_parquet('temp.parquet', columns=[]).index))
# Correctly prints 2
print(pq.read_table('temp.parquet', columns=[]).num_rows)
print(len(pq.read_table('temp.parquet', columns=[]).to_pandas().index))

pd.DataFrame(index=pd.RangeIndex(2), columns=[]).to_parquet('temp.parquet')

# BUG: all incorrectly print 0
print(len(pd.read_parquet('temp.parquet', columns=[]).index))
print(len(pd.read_parquet('temp.parquet', columns=None).index))
print(pq.read_table('temp.parquet', columns=[]).num_rows)
print(len(pq.read_table('temp.parquet', columns=[]).to_pandas().index))

pq.write_table(pa.Table.from_pandas(pd.DataFrame(index=pd.RangeIndex(2), columns=[])), 'temp.parquet')

# BUG: all incorrectly print 0
print(len(pd.read_parquet('temp.parquet', columns=[]).index))
print(len(pd.read_parquet('temp.parquet', columns=None).index))
print(pq.read_table('temp.parquet', columns=[]).num_rows)
print(len(pq.read_table('temp.parquet', columns=[]).to_pandas().index))

Issue Description

If you do pd.read_parquet(columns=[]) the resulting DataFrame should have no columns, but should still have the expected index. However, in the special case where the expected index is a trivial RangeIndex we are instead getting an empty index with entirely the wrong length.

Expected Behavior

If column 'c' exists in a file, it should be the case that pd.read_parquet(path, columns=[c]).index.equals(pd.read_parquet(path, columns=[]).index)

Installed Versions

INSTALLED VERSIONS ------------------ commit : d9cdd2e python : 3.11.3.final.0 python-bits : 64 OS : Linux OS-release : 4.18.0-348.20.1.el8_5.x86_64 Version : #1 SMP Thu Mar 10 20:59:28 UTC 2022 machine : x86_64 processor : x86_64 byteorder : little LC_ALL : None LANG : en_GB.UTF-8 LOCALE : en_GB.UTF-8

pandas : 2.2.2
numpy : 1.24.3
pytz : 2023.3
dateutil : 2.8.2
setuptools : 67.7.2
pip : 23.1.2
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 : 8.13.2
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
bottleneck : 1.3.7
dataframe-api-compat : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : 2.9.0
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 14.0.2
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.3
qtpy : None
pyqt5 : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugIO Parquetparquet, featherNeeds TriageIssue that has not been reviewed by a pandas team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions