Skip to content

GH-45902: [Python][Parquet] Expose ParquetWriter properties and arrow_properties - #47087

Open
SoundBot wants to merge 1 commit into
apache:mainfrom
SoundBot:expose-parquetwrite-props
Open

SoundBot wants to merge 1 commit into
apache:mainfrom
SoundBot:expose-parquetwrite-props

Conversation

@SoundBot

@SoundBot SoundBot commented Jul 12, 2025 •

Copy link
Copy Markdown

Rationale for this change

Exposes ParquetWriter properties via writer.properties and writer.arrow_properties
(see #45902)

What changes are included in this PR?

See above

Are these changes tested?

Yes

Are there any user-facing changes?

Yes, properties are available via writer.properties and writer.arrow_properties

@github-actions

Copy link
Copy Markdown

Thanks for opening a pull request!

If this is not a minor PR. Could you open an issue for this pull request on GitHub? https://github.com/apache/arrow/issues/new/choose

Opening GitHub issues ahead of time contributes to the Openness of the Apache Arrow project.

Then could you also rename the pull request title in the following format?

GH-${GITHUB_ISSUE_ID}: [${COMPONENT}] ${SUMMARY}

or

MINOR: [${COMPONENT}] ${SUMMARY}

See also:

@SoundBot
SoundBot force-pushed the expose-parquetwrite-props branch 3 times, most recently from f921baf to db3942b Compare July 14, 2025 03:47
@SoundBot SoundBot changed the title [Python][Parquet] Expose ParquetWriter properties and arrow_properties GH-45902: [Python][Parquet] Expose ParquetWriter properties and arrow_properties Jul 14, 2025
@github-actions

Copy link
Copy Markdown

⚠️ GitHub issue #45902 has been automatically assigned in GitHub to PR creator.

@SoundBot
SoundBot marked this pull request as ready for review July 14, 2025 04:18

@AlenkaF AlenkaF left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for submitting a PR!
From a quick look the test needs a @pytest.mark.pandas mark and some style changes are needed to fix linter errors:

diff --git a/cpp/src/parquet/arrow/writer.cc b/cpp/src/parquet/arrow/writer.cc
index 3724e2edf0..cdaeebc294 100644
--- a/cpp/src/parquet/arrow/writer.cc
+++ b/cpp/src/parquet/arrow/writer.cc
@@ -473,7 +473,9 @@ class FileWriterImpl : public FileWriter {
 
   const WriterProperties& properties() const override { return *writer_->properties(); }
 
-  const ArrowWriterProperties& arrow_properties() const override { return *arrow_properties_; }
+  const ArrowWriterProperties& arrow_properties() const override {
+    return *arrow_properties_;
+  }
 
   ::arrow::MemoryPool* memory_pool() const override {
     return column_write_context_.memory_pool;
diff --git a/python/pyarrow/_parquet.pyx b/python/pyarrow/_parquet.pyx
index f1287d7b8a..6f3b9a5f[43](https://github.com/apache/arrow/actions/runs/16257450496/job/45897414651?pr=47087#step:5:44) 100644
--- a/python/pyarrow/_parquet.pyx
+++ b/python/pyarrow/_parquet.pyx
@@ -2458,7 +2458,6 @@ cdef class WriterPropertiesWrapper(_Weakrefable):
         return self.props.default_column_properties().statistics_enabled()
 
 
-
 cdef class ArrowWriterPropertiesWrapper(_Weakrefable):
     cdef:
         shared_ptr[ArrowWriterProperties] props

I will have a look at the proposed code shortly.

@SoundBot
SoundBot force-pushed the expose-parquetwrite-props branch from 23d3161 to 3adfc51 Compare July 14, 2025 23:54
@SoundBot

ghost commented Jul 15, 2025

Copy link
Copy Markdown
Author

@AlenkaF thank you, I added @pytest.mark.pandas and ran pre-commit run --all-files

Comment on lines +455 to +456
df = _test_dataframe(100)
table = pa.Table.from_pandas(df, preserve_index=False)

ghost Jul 21, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

not specifically related to this PR but would be nice to have an utility function to create an Arrow table directly instead of having to go through pandas. This test doesn't really have to require pandas but the utility function is handy. We can create an issue to move some of those tests to use a new utility function and remove the @pytest.mark.pandas for some of those tests. @AlenkaF what do you think? It could be a good-first-issue

ghost Jul 21, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Agree, adding a new utility function to create Arrow tables and/or batches would be great! And perfect for good-first-issue 👍

ghost Jul 23, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Created: #47172

ghost Aug 11, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The PR that adds a utility function to create an Arrow table directly (without going through pandas) has been merged. It would be great to use that here now.

ghost Sep 1, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That is not even required. Any hand-created Arrow table, however trivial, would probably be sufficient for this test.

@raulcd

ghost commented Jul 21, 2025

Copy link
Copy Markdown
Member

@github-actions crossbow submit -g python -g wheel

@github-actions

ghost commented Jul 21, 2025

Copy link
Copy Markdown

Revision: 3adfc51

Submitted crossbow builds: ursacomputing/crossbow @ actions-623832f922

Task Status
example-python-minimal-build-fedora-conda GitHub Actions
example-python-minimal-build-ubuntu-venv GitHub Actions
python-sdist GitHub Actions
test-conda-python-3.10 GitHub Actions
test-conda-python-3.10-hdfs-2.9.2 GitHub Actions
test-conda-python-3.10-hdfs-3.2.1 GitHub Actions
test-conda-python-3.10-pandas-latest-numpy-latest GitHub Actions
test-conda-python-3.11 GitHub Actions
test-conda-python-3.11-dask-latest GitHub Actions
test-conda-python-3.11-dask-upstream_devel GitHub Actions
test-conda-python-3.11-hypothesis GitHub Actions
test-conda-python-3.11-pandas-latest-numpy-1.26 GitHub Actions
test-conda-python-3.11-pandas-latest-numpy-latest GitHub Actions
test-conda-python-3.11-pandas-nightly-numpy-nightly GitHub Actions
test-conda-python-3.11-pandas-upstream_devel-numpy-nightly GitHub Actions
test-conda-python-3.11-spark-master GitHub Actions
test-conda-python-3.12 GitHub Actions
test-conda-python-3.12-cpython-debug GitHub Actions
test-conda-python-3.13 GitHub Actions
test-conda-python-3.9 GitHub Actions
test-conda-python-3.9-pandas-1.1.3-numpy-1.19.5 GitHub Actions
test-conda-python-emscripten GitHub Actions
test-cuda-python-ubuntu-22.04-cuda-11.7.1 GitHub Actions
test-debian-12-python-3-amd64 GitHub Actions
test-debian-12-python-3-i386 GitHub Actions
test-fedora-39-python-3 GitHub Actions
test-ubuntu-22.04-python-3 GitHub Actions
test-ubuntu-22.04-python-313-freethreading GitHub Actions
test-ubuntu-24.04-python-3 GitHub Actions
wheel-macos-monterey-cp310-cp310-amd64 GitHub Actions
wheel-macos-monterey-cp310-cp310-arm64 GitHub Actions
wheel-macos-monterey-cp311-cp311-amd64 GitHub Actions
wheel-macos-monterey-cp311-cp311-arm64 GitHub Actions
wheel-macos-monterey-cp312-cp312-amd64 GitHub Actions
wheel-macos-monterey-cp312-cp312-arm64 GitHub Actions
wheel-macos-monterey-cp313-cp313-amd64 GitHub Actions
wheel-macos-monterey-cp313-cp313-arm64 GitHub Actions
wheel-macos-monterey-cp313-cp313t-amd64 GitHub Actions
wheel-macos-monterey-cp313-cp313t-arm64 GitHub Actions
wheel-macos-monterey-cp39-cp39-amd64 GitHub Actions
wheel-macos-monterey-cp39-cp39-arm64 GitHub Actions
wheel-manylinux-2-28-cp310-cp310-amd64 GitHub Actions
wheel-manylinux-2-28-cp310-cp310-arm64 GitHub Actions
wheel-manylinux-2-28-cp311-cp311-amd64 GitHub Actions
wheel-manylinux-2-28-cp311-cp311-arm64 GitHub Actions
wheel-manylinux-2-28-cp312-cp312-amd64 GitHub Actions
wheel-manylinux-2-28-cp312-cp312-arm64 GitHub Actions
wheel-manylinux-2-28-cp313-cp313-amd64 GitHub Actions
wheel-manylinux-2-28-cp313-cp313-arm64 GitHub Actions
wheel-manylinux-2-28-cp313-cp313t-amd64 GitHub Actions
wheel-manylinux-2-28-cp313-cp313t-arm64 GitHub Actions
wheel-manylinux-2-28-cp39-cp39-amd64 GitHub Actions
wheel-manylinux-2-28-cp39-cp39-arm64 GitHub Actions
wheel-musllinux-1-2-cp310-cp310-amd64 GitHub Actions
wheel-musllinux-1-2-cp310-cp310-arm64 GitHub Actions
wheel-musllinux-1-2-cp311-cp311-amd64 GitHub Actions
wheel-musllinux-1-2-cp311-cp311-arm64 GitHub Actions
wheel-musllinux-1-2-cp312-cp312-amd64 GitHub Actions
wheel-musllinux-1-2-cp312-cp312-arm64 GitHub Actions
wheel-musllinux-1-2-cp313-cp313-amd64 GitHub Actions
wheel-musllinux-1-2-cp313-cp313-arm64 GitHub Actions
wheel-musllinux-1-2-cp313-cp313t-amd64 GitHub Actions
wheel-musllinux-1-2-cp313-cp313t-arm64 GitHub Actions
wheel-musllinux-1-2-cp39-cp39-amd64 GitHub Actions
wheel-musllinux-1-2-cp39-cp39-arm64 GitHub Actions
wheel-windows-cp310-cp310-amd64 GitHub Actions
wheel-windows-cp311-cp311-amd64 GitHub Actions
wheel-windows-cp312-cp312-amd64 GitHub Actions
wheel-windows-cp313-cp313-amd64 GitHub Actions
wheel-windows-cp313-cp313t-amd64 GitHub Actions
wheel-windows-cp39-cp39-amd64 GitHub Actions

@raulcd

ghost commented Jul 21, 2025

Copy link
Copy Markdown
Member

The example-python-minimal-build-* failures are unrelated to the PR, known issue:

@SoundBot

ghost commented Jul 21, 2025

Copy link
Copy Markdown
Author

Is there anything else needed to merge this PR? @AlenkaF @raulcd

ghost left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry for the delay in replying. I think the PR is in great shape — the Cython wrapper classes and properties look good to me. (I considered whether nogil was needed for props_ptr, but since it's just transferring a pointer, I agree it's unnecessary.) The tests are clear, and CI is green, so it's a +1 from me.

I only have one comment regarding the test utility used. Once we get one more approval, I’ll go ahead and merge it.

Comment on lines +455 to +456
df = _test_dataframe(100)
table = pa.Table.from_pandas(df, preserve_index=False)

ghost Aug 11, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The PR that adds a utility function to create an Arrow table directly (without going through pandas) has been merged. It would be great to use that here now.

@SoundBot

ghost commented Aug 22, 2025

Copy link
Copy Markdown
Author

@rok @wgtmac can any of you folks review this PR please?

return result


cdef class WriterPropertiesWrapper(_Weakrefable):

ghost Aug 22, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not familiar with CPython. Does it mean that we only support a subset of attributes from these properties?

ghost Aug 22, 2025

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

That's correct. The full WriterProperties object is accessible in the Cython code, but the Python wrapper intentionally exposes only a subset.

ghost Aug 23, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is that? Is it a convention on the pyarrow side? Isn't it annoying to add a missing property in the future? cc @rok

ghost Aug 25, 2025

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@wgtmac I'm not aware is there is a better way. I think generally you expose what the end-users might want to use.

ghost Aug 29, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sounds good to me. WDYT? @pitrou

@SoundBot

ghost commented Aug 28, 2025

Copy link
Copy Markdown
Author

Hey folks, I suggest that if this code passes the sniff test, we merge it and address enhancements in later PRs.
If not, let's list the concrete changes I need to make to get this over the finish line.

return result


cdef class WriterPropertiesWrapper(_Weakrefable):

ghost Sep 1, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why call it "Wrapper"? We should just call it WriterProperties. If that produces a name clash with the C++ class, then we should rename the latter in the Cython declarations to CWriterProperties as we do for many other such cases.

return self.props.default_column_properties().statistics_enabled()


cdef class ArrowWriterPropertiesWrapper(_Weakrefable):

ghost Sep 1, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same here.

elif version_int == 1: # V2
return "V2"
else:
return f"unknown({version_int})"

ghost Sep 1, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should probably raise ValueError here?

Comment thread python/pyarrow/_parquet.pyx Resolved
Comment on lines +2468 to +2469
cdef init(self, shared_ptr[ArrowWriterProperties] props):
self.props = props

ghost Sep 1, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If we're getting a const-ref from the C++ APIs, we should certainly not turn it into a shared_ptr. You should probably let the C++ APIs return a shared_ptr?

Comment on lines +474 to +478
assert props is not None
assert hasattr(props, 'version')
assert hasattr(props, 'created_by')
assert hasattr(props, 'dictionary_enabled')
assert hasattr(props, 'statistics_enabled')

ghost Sep 1, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No need for all this, the attribute accesses below are sufficient.

assert props.version == 2
assert props.dictionary_enabled is True
assert props.statistics_enabled is True
assert isinstance(props.created_by, str)

ghost Sep 1, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why not test the actual value instead of this (or at least some substring of the value)?

self.props = props

@property
def version(self):

ghost Sep 1, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please add docstrings for all these properties.

assert hasattr(props, 'created_by')
assert hasattr(props, 'dictionary_enabled')
assert hasattr(props, 'statistics_enabled')
assert props.version == 2

ghost Sep 1, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not sure what this 2 means... we passed "2.6" above and probably expect to get it back?

@github-actions

ghost commented Sep 2, 2026

Copy link
Copy Markdown

Thank you for your contribution. Unfortunately, this pull request has been marked as stale because it has had no activity in the past 365 days. Please remove the stale label or comment below, or this PR will be closed in 14 days. Feel free to re-open this if it has been closed in error. If you do not have repository permissions to reopen the PR, please tag a maintainer.

@github-actions github-actions Bot added the Status: stale-warning Issues and PRs flagged as stale which are due to be closed if no indication otherwise label Sep 2, 2026
@rok

ghost commented Sep 2, 2026

Copy link
Copy Markdown
Member

@SoundBot would you be interested in continuing this work?

@github-actions github-actions Bot removed the Status: stale-warning Issues and PRs flagged as stale which are due to be closed if no indication otherwise label Sep 3, 2026
@Reranko05

ghost commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator

@rok Should we consider closing this PR and unassign the author from the issue so that anyone interested can pick it up? He hasn't had any GitHub activity since August 2025, so it seems unlikely that the work will be continued.

@rok

ghost commented Oct 30, 2026

Copy link
Copy Markdown
Member

@Reranko05 agreed. Let's unassign this issue to allow someone else complete it, but also leave room for @SoundBot to come back and do it in case they have time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants