Skip to content
Open
Show file tree
Hide file tree
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
11 changes: 9 additions & 2 deletions python/datafusion/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -78,6 +79,11 @@
from datafusion.plan import ExecutionPlan, LogicalPlan
from datafusion.record_batch import RecordBatch, RecordBatchStream

# parquet-java parses created_by as "<application> version <version>" (PARQUET-246).
_DEFAULT_CREATED_BY = (
f"datafusion-python version {importlib_metadata.version('datafusion')}"
)

if TYPE_CHECKING:
import pathlib
from collections.abc import Callable
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 <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.
Expand Down
10 changes: 10 additions & 0 deletions python/tests/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 "<application> version <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
Expand Down