Skip to content

GH-35289: [Python] Support large variable width types in numpy conversion - #36701

Merged
AlenkaF merged 11 commits into
apache:mainfrom
Kimahriman:nptoarrow-large-binary
Mar 4, 2025
Merged

AlenkaF merged 11 commits into
apache:mainfrom
Kimahriman:nptoarrow-large-binary

Conversation

@Kimahriman

@Kimahriman Kimahriman commented Jul 15, 2023 •

Copy link
Copy Markdown
Contributor

Rationale for this change

Add support for LargeBinaryType, BinaryViewType, LargeStringType, and StringViewType in NumPy to Arrow conversion.

What changes are included in this PR?

Adds new Visit methods in NumPyConverter for LargeStringType, StringViewType, LargeBinaryType, and BinaryViewType. These are built on top of new templated VisitString and VisitBinary methods.

Also adds the Arrow -> NumPy type map for the large binary types.

Are these changes tested?

New test added showing a string and binary array over 2 GiB is valid and still a single chunk. Also added the new Arrow to NumPy maps to a schema test.

Are there any user-facing changes?

Adds support for converting NumPy string/binary lists to large binary types.

@github-actions

Copy link
Copy Markdown

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

@AlenkaF

AlenkaF commented Aug 22, 2023 •

Copy link
Copy Markdown
Member

Thank you for the contribution @Kimahriman !

The PR looks good!
As you have mentioned, there might be some improvement possible with consolidating the common code.

In the C++ part, where I am a novice also - but, I would try with creating a helper Status function and see if I can make it work with both builder instances or not (am not really sure it will work).

As for the python test, it could also be consolidated with test_numpy_binary_overflow_to_chunked with parametrizing the test function as for example in

@pytest.mark.parametrize('list_type_factory', [pa.list_, pa.large_list])
.

@jorisvandenbossche

Copy link
Copy Markdown
Member

If there's a way to consolidate the common code let me know, this is my first C++ in a long time.

In the Visit functions, I think the main (only?) difference is the type of builder that was created? In that case I think it should be possible to template this: have a single VisitString() that is templated on the builder type, and then the Visit(const StringType& type) could be a small wrapper around calling VisitString<ChunkedStringBuilder>(). Although the builder having different parameters to instantiate it might complicate things ..

@Kimahriman

Copy link
Copy Markdown
Contributor Author

Thanks for the ideas, I'll see if I can figure anything out 😅

@Kimahriman

Copy link
Copy Markdown
Contributor Author

Ok I learned about C++ templates and deduped the different functions, and I just parametrized the existing python test

@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.

Great work! The PR looks good IMO +1.
@jorisvandenbossche could you give one more look before merging?

@Kimahriman

Copy link
Copy Markdown
Contributor Author

@jorisvandenbossche gentle ping

@Kimahriman

Copy link
Copy Markdown
Contributor Author

@jorisvandenbossche gentle ping again. Merged in master and resolved the conflict

@jorisvandenbossche jorisvandenbossche 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.

Looks good!

And apologies for the very slow follow-up ..

I have one more request: could you add a simple test for this as well (the large_memory test you edited it good to have, but in most our CI builds those are skipped, so it would be good to have a simple small test as well that is run everywhere).
For example there is a test_array_from_numpy_ascii and test_array_from_numpy_unicode. You could add one case to those tests with specifying the type as the large variant.

@Kimahriman

Copy link
Copy Markdown
Contributor Author

Looks good!

And apologies for the very slow follow-up ..

I have one more request: could you add a simple test for this as well (the large_memory test you edited it good to have, but in most our CI builds those are skipped, so it would be good to have a simple small test as well that is run everywhere). For example there is a test_array_from_numpy_ascii and test_array_from_numpy_unicode. You could add one case to those tests with specifying the type as the large variant.

Parameterized those tests to specify the type and use regular and large types

@rok

rok commented Feb 27, 2025

Copy link
Copy Markdown
Member

I can review or pickup next week. @Kimahriman are you interested in continuing this work?

@Kimahriman

Copy link
Copy Markdown
Contributor Author

I can review or pickup next week. @Kimahriman are you interested in continuing this work?

I was able to get this up to date with main, I don't know much about the view types

@rok

rok commented Feb 27, 2025

Copy link
Copy Markdown
Member

Thank you @Kimahriman! Depending on how adventurous you feel we can make a separate PR or add view types here.

@Kimahriman

Copy link
Copy Markdown
Contributor Author

Probably would be good to do in a follow on, not sure how quickly I can figure out and get the views working

@rok

rok commented Feb 28, 2025

Copy link
Copy Markdown
Member

@Kimahriman agreed!

@Kimahriman

Copy link
Copy Markdown
Contributor Author

Nevermind adding the views was pretty simple

@github-actions

Copy link
Copy Markdown

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

Comment thread python/pyarrow/tests/test_array.py Resolved

@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.

Thank you for continuing to work on this PR @Kimahriman, it is much appreciated! And thanks @pitrou for the ping.

The PR LGTM with all the comments addressed. I think you can update the description tiny bit (AppendUTF32 is updated, no copy was needed AFAIU).

@github-actions

github-actions Bot commented Mar 3, 2025

Copy link
Copy Markdown

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

1 similar comment
@github-actions

github-actions Bot commented Mar 3, 2025

Copy link
Copy Markdown

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

@Kimahriman

Copy link
Copy Markdown
Contributor Author

All the open discussions should be resolved, and I updated the description a bit with the current implementation

@AlenkaF

AlenkaF commented Mar 4, 2025

Copy link
Copy Markdown
Member

@github-actions crossbow submit -g python

@github-actions

github-actions Bot commented Mar 4, 2025

Copy link
Copy Markdown

Revision: cb479c8

Submitted crossbow builds: ursacomputing/crossbow @ actions-4fe3452fe3

Task Status
example-python-minimal-build-fedora-conda GitHub Actions
example-python-minimal-build-ubuntu-venv 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

@AlenkaF

AlenkaF commented Mar 4, 2025

Copy link
Copy Markdown
Member

All failing builds are known, test-conda-python-3.11-hypothesis has an issue opened: #45292 and two minimal builds also: #44803. None of it is connected to this PR. @rok want to have a look before I merge?

@rok rok 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.

Looks great, thanks for doing this @Kimahriman !

@AlenkaF
AlenkaF merged commit 9752c34 into apache:main Mar 4, 2025
@AlenkaF

AlenkaF commented Mar 4, 2025

Copy link
Copy Markdown
Member

Thank you for your contribution and patience @Kimahriman !

@conbench-apache-arrow

Copy link
Copy Markdown

After merging your PR, Conbench analyzed the 4 benchmarking runs that have been run so far on merge-commit 9752c34.

There were no benchmark performance regressions. 🎉

The full Conbench report has more details. It also includes information about 13 possible false positives for unstable benchmarks that are known to sometimes produce them.

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.

[Python] Converting from NumPy to large_string or large_binary returns not implemented

5 participants