This is an automated email from the ASF dual-hosted git repository.
AlenkaF pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/main by this push:
new 0d8f1b99294 MINOR: [Python][Parquet] Clarify code around restoring
pandas metadata in ParquetDataset.read() (#51151)
0d8f1b99294 is described below
commit 0d8f1b9929462364b4fe48a68891d468e0b156a8
Author: Joris Van den Bossche <[email protected]>
AuthorDate: Wed Sep 9 11:03:45 2026 +0200
MINOR: [Python][Parquet] Clarify code around restoring pandas metadata in
ParquetDataset.read() (#51151)
### Rationale for this change
This might not strictly speaking be a valid "minor" issue since it changes
code, but it should keep the logic the same and (for me) clarify the intent of
it.
### Are these changes tested?
By existing tests
### Are there any user-facing changes?
No
Authored-by: Joris Van den Bossche <[email protected]>
Signed-off-by: AlenkaF <[email protected]>
---
python/pyarrow/parquet/core.py | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/python/pyarrow/parquet/core.py b/python/pyarrow/parquet/core.py
index 983e6cba4ea..4acfa4f6e22 100644
--- a/python/pyarrow/parquet/core.py
+++ b/python/pyarrow/parquet/core.py
@@ -1568,6 +1568,7 @@ Examples
# 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)
@@ -1592,13 +1593,12 @@ Examples
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:
- 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