Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions python/pyarrow/parquet/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1568,6 +1568,7 @@ def read(self, columns=None, use_threads=True, use_pandas_metadata=False):
# column selection, to be able to restore those in the pandas DataFrame
metadata = self.schema.metadata or {}

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

# if use_pandas_metadata, restore the pandas metadata (which gets
# lost if doing a specific `columns` selection in to_table)
if use_pandas_metadata:
if metadata and b"pandas" in metadata:

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If metadata would come from metadata = self.schema.metadata, it means it already had a "pandas" key, and there is no need to add it back here (to_table() does not (or no longer) loose the metadata)

new_metadata = table.schema.metadata or {}
new_metadata.update({b"pandas": metadata[b"pandas"]})
table = table.replace_schema_metadata(new_metadata)
# if the "pandas" metadata entry was retrieved from common_metadata,
# it will not live on the read table -> add it to the table metadata
if common_metadata and b"pandas" in metadata:
new_metadata = table.schema.metadata or {}
new_metadata.update({b"pandas": metadata[b"pandas"]})
table = table.replace_schema_metadata(new_metadata)

return table

Expand Down