From 4e2903f4a2e42540eb560a07fde9321b16f64582 Mon Sep 17 00:00:00 2001 From: Metin Hatipogullari Date: Sun, 15 Nov 2026 08:36:28 +0100 Subject: [PATCH] fix: include the version in the default Parquet created_by parquet-java parses created_by as " version " (PARQUET-246). Without a version it cannot parse the writer and refuses DELTA_BYTE_ARRAY columns, e.g. in Spark with the vectorized reader off. Co-Authored-By: Claude Opus 5.5 --- python/datafusion/dataframe.py | 11 +++++++++-- python/tests/test_dataframe.py | 10 ++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/python/datafusion/dataframe.py b/python/datafusion/dataframe.py index 12ab0a3c3..cb20fb3e6 100644 --- a/python/datafusion/dataframe.py +++ b/python/datafusion/dataframe.py @@ -44,6 +44,7 @@ from __future__ import annotations +import importlib.metadata as importlib_metadata import sys import warnings from collections.abc import AsyncIterator, Iterable, Iterator, Sequence @@ -78,6 +79,11 @@ from datafusion.plan import ExecutionPlan, LogicalPlan from datafusion.record_batch import RecordBatch, RecordBatchStream +# parquet-java parses created_by as " version " (PARQUET-246). +_DEFAULT_CREATED_BY = ( + f"datafusion-python version {importlib_metadata.version('datafusion')}" +) + if TYPE_CHECKING: import pathlib from collections.abc import Callable @@ -214,7 +220,7 @@ def __init__( dictionary_page_size_limit: int = 1024 * 1024, statistics_enabled: str | None = "page", max_row_group_size: int = 1024 * 1024, - created_by: str = "datafusion-python", + created_by: str = _DEFAULT_CREATED_BY, column_index_truncate_length: int | None = 64, statistics_truncate_length: int | None = None, data_page_row_count_limit: int = 20_000, @@ -257,7 +263,8 @@ def __init__( max_row_group_size: Target maximum number of rows in each row group (defaults to 1M rows). Writing larger row groups requires more memory to write, but can get better compression and be faster to read. - created_by: Sets "created by" property. + created_by: Sets "created by" property. Defaults to + ``datafusion-python version ``. column_index_truncate_length: Sets column index truncate length. statistics_truncate_length: Sets statistics truncate length. If ``None``, uses the default parquet writer setting. diff --git a/python/tests/test_dataframe.py b/python/tests/test_dataframe.py index 1b2bbfcd9..867ca6301 100644 --- a/python/tests/test_dataframe.py +++ b/python/tests/test_dataframe.py @@ -24,6 +24,7 @@ from pathlib import Path from typing import Any +import datafusion import numpy as np import pyarrow as pa import pyarrow.parquet as pq @@ -2840,6 +2841,15 @@ def test_write_parquet_with_options_created_by(df, tmp_path, created_by): assert metadata["created_by"] == created_by +def test_write_parquet_with_options_default_created_by(df, tmp_path): + """The default created_by follows the " version " form.""" + df.write_parquet_with_options(tmp_path, ParquetWriterOptions()) + + for file in tmp_path.rglob("*.parquet"): + created_by = pq.ParquetFile(file).metadata.created_by + assert created_by == f"datafusion-python version {datafusion.__version__}" + + @pytest.mark.parametrize("statistics_truncate_length", [5, 25, 50]) def test_write_parquet_with_options_statistics_truncate_length( df, tmp_path, statistics_truncate_length