Skip to content

Commit 17cb994

Browse files
MINOR: [Python][Parquet] Clarify code around restoring pandas metadata in ParquetDataset.read()
1 parent a769c29 commit 17cb994

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

python/pyarrow/parquet/core.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,6 +1568,7 @@ def read(self, columns=None, use_threads=True, use_pandas_metadata=False):
15681568
# column selection, to be able to restore those in the pandas DataFrame
15691569
metadata = self.schema.metadata or {}
15701570

1571+
common_metadata = None
15711572
if use_pandas_metadata:
15721573
# if the dataset schema metadata itself doesn't have pandas
15731574
# then try to get this from common file (for backwards compat)
@@ -1592,13 +1593,12 @@ def read(self, columns=None, use_threads=True, use_pandas_metadata=False):
15921593
use_threads=use_threads
15931594
)
15941595

1595-
# if use_pandas_metadata, restore the pandas metadata (which gets
1596-
# lost if doing a specific `columns` selection in to_table)
1597-
if use_pandas_metadata:
1598-
if metadata and b"pandas" in metadata:
1599-
new_metadata = table.schema.metadata or {}
1600-
new_metadata.update({b"pandas": metadata[b"pandas"]})
1601-
table = table.replace_schema_metadata(new_metadata)
1596+
# if the "pandas" metadata entry was retrieved from common_metadata,
1597+
# it will not live on the read table -> add it to the table metadata
1598+
if common_metadata and b"pandas" in metadata:
1599+
new_metadata = table.schema.metadata or {}
1600+
new_metadata.update({b"pandas": metadata[b"pandas"]})
1601+
table = table.replace_schema_metadata(new_metadata)
16021602

16031603
return table
16041604

0 commit comments

Comments
 (0)