You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "sjperkins (via GitHub)" <gi...@apache.org> on 2023/03/06 14:41:38 UTC
[GitHub] [arrow] sjperkins opened a new pull request, #34469: GH-33801: [Python] Further expose C++ Extension Types in Python
sjperkins opened a new pull request, #34469:
URL: https://github.com/apache/arrow/pull/34469
Closes https://github.com/apache/arrow/issues/33997
<!--
Thanks for opening a pull request!
If this is your first pull request you can find detailed information on how
to contribute here:
* [New Contributor's Guide](https://arrow.apache.org/docs/dev/developers/guide/step_by_step/pr_lifecycle.html#reviews-and-merge-of-the-pull-request)
* [Contributing Overview](https://arrow.apache.org/docs/dev/developers/overview.html)
If this is not a [minor PR](https://github.com/apache/arrow/blob/main/CONTRIBUTING.md#Minor-Fixes). 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](http://theapacheway.com/open/#:~:text=Openness%20allows%20new%20users%20the,must%20happen%20in%20the%20open.) 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}
In the case of PARQUET issues on JIRA the title also supports:
PARQUET-${JIRA_ISSUE_ID}: [${COMPONENT}] ${SUMMARY}
-->
### Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
-->
Explained in greater detail in https://github.com/apache/arrow/issues/33997, but my summary follows:
* C++ Extension Types currently are not well-exposed in the Python Layer
* In particular, generic `ExtensionArray` and `ExtensionScalar` types are associated with C++ Extensions exposed through `BaseExtensionType`, rather than hand-coded Python types (which would be laborious to generate).
### What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
-->
* When `BaseExtensionType.__arrow_ext_class__()` and `BaseExtensionType.__arrow_ext_scalar_class__()` are called, associated Python classes are created on the fly and cached for future calls.
* `BaseExtensionType.__arrow_ext_serialize__()` and `BaseExtensionType.__arrow_ext_deserialize__()` defer to `CExtensionType.Serialize()` and `CExtensionType.Deserialize()` respectively.
### Are these changes tested?
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
-->
* `__arrow_ext_class__()` and `__arrow_ext_scalar_class__()` are tested
* `__arrow_ext_serialize__()` and `__arrow_ext_deserialize__()` are not tested yet. I'd appreciate feedback on whether the general approach is useful going forward before adding tests.
### Are there any user-facing changes?
* I don't believe so.
<!--
If there are user-facing changes then we may require documentation to be updated before approving the PR.
-->
<!--
If there are any breaking changes to public APIs, please uncomment the line below and explain which changes are breaking.
-->
<!-- **This PR includes breaking changes to public APIs.** -->
<!--
Please uncomment the line below (and provide explanation) if the changes fix either (a) a security vulnerability, (b) a bug that caused incorrect or invalid data to be produced, or (c) a bug that causes a crash (even when the API contract is upheld). We use this to highlight fixes to issues that may affect users without their knowledge. For this reason, fixing bugs that cause errors don't count, since those are usually obvious.
-->
<!-- **This PR contains a "Critical Fix".** -->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] sjperkins commented on a diff in pull request #34469: GH-33801: [Python] Further expose C++ Extension Types in Python
Posted by "sjperkins (via GitHub)" <gi...@apache.org>.
sjperkins commented on code in PR #34469:
URL: https://github.com/apache/arrow/pull/34469#discussion_r1126521520
##########
python/pyarrow/tests/test_extension_type.py:
##########
@@ -1115,9 +1115,16 @@ def test_cpp_extension_in_python(tmpdir):
assert uuid_type.extension_name == "uuid"
assert uuid_type.storage_type == pa.binary(16)
+ array_cls = uuid_type.__arrow_ext_class__()
+ scalar_cls = uuid_type.__arrow_ext_scalar_class__()
+ assert array_cls.__name__ == "ExtensionArray(uuid)"
+ assert scalar_cls.__name__ == "ExtensionScalar(uuid)"
Review Comment:
The auto-generated class naming schema is similar to that of BaseExtensionType. i.e. `BaseExtensionType(extension<uuid>)`.
##########
python/pyarrow/tests/test_extension_type.py:
##########
@@ -1115,9 +1115,16 @@ def test_cpp_extension_in_python(tmpdir):
assert uuid_type.extension_name == "uuid"
assert uuid_type.storage_type == pa.binary(16)
+ array_cls = uuid_type.__arrow_ext_class__()
+ scalar_cls = uuid_type.__arrow_ext_scalar_class__()
+ assert array_cls.__name__ == "ExtensionArray(uuid)"
+ assert scalar_cls.__name__ == "ExtensionScalar(uuid)"
+
array = mod._make_uuid_array()
assert array.type == uuid_type
+ assert isinstance(array, array_cls)
Review Comment:
prior to this change, only `isinstance(array, pyarrow.ExtensionArray)` would have held.
##########
python/pyarrow/tests/test_extension_type.py:
##########
@@ -1127,3 +1134,12 @@ def test_cpp_extension_in_python(tmpdir):
reconstructed_array = batch.column(0)
assert reconstructed_array.type == uuid_type
assert reconstructed_array == array
+
+ storage = pa.array([b'0onmlkjihgfedcba']*4, pa.binary(16))
+ ext_array = pa.ExtensionArray.from_storage(uuid_type, storage)
+ assert isinstance(ext_array, array_cls)
Review Comment:
From memory, before to this change, `pa.ExtensionArray.from_storage` would have returned a `pyarrow.ExtensionArray`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] amol- commented on pull request #34469: GH-33801: [Python] Further expose C++ Extension Types in Python
Posted by "amol- (via GitHub)" <gi...@apache.org>.
amol- commented on PR #34469:
URL: https://github.com/apache/arrow/pull/34469#issuecomment-1490667423
Closing because it has been untouched for a while, in case it's still relevant feel free to reopen and move it forward 👍
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] amol- closed pull request #34469: GH-33801: [Python] Further expose C++ Extension Types in Python
Posted by "amol- (via GitHub)" <gi...@apache.org>.
amol- closed pull request #34469: GH-33801: [Python] Further expose C++ Extension Types in Python
URL: https://github.com/apache/arrow/pull/34469
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] github-actions[bot] commented on pull request #34469: GH-33801: [Python] Further expose C++ Extension Types in Python
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #34469:
URL: https://github.com/apache/arrow/pull/34469#issuecomment-1456265999
* Closes: #33801
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] sjperkins commented on pull request #34469: GH-33801: [Python] Further expose C++ Extension Types in Python
Posted by "sjperkins (via GitHub)" <gi...@apache.org>.
sjperkins commented on PR #34469:
URL: https://github.com/apache/arrow/pull/34469#issuecomment-1490693842
Would it be possible to re-open this issue? I'm awaiting review from Arrow maintainers here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] sjperkins closed pull request #34469: GH-33801: [Python] Further expose C++ Extension Types in Python
Posted by "sjperkins (via GitHub)" <gi...@apache.org>.
sjperkins closed pull request #34469: GH-33801: [Python] Further expose C++ Extension Types in Python
URL: https://github.com/apache/arrow/pull/34469
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] sjperkins commented on pull request #34469: GH-33801: [Python] Further expose C++ Extension Types in Python
Posted by "sjperkins (via GitHub)" <gi...@apache.org>.
sjperkins commented on PR #34469:
URL: https://github.com/apache/arrow/pull/34469#issuecomment-1494230727
Closing for reasons discussed in https://github.com/apache/arrow/pull/34483#issuecomment-1491702391
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] amol- commented on pull request #34469: GH-33801: [Python] Further expose C++ Extension Types in Python
Posted by "amol- (via GitHub)" <gi...@apache.org>.
amol- commented on PR #34469:
URL: https://github.com/apache/arrow/pull/34469#issuecomment-1490736738
Yes of course, the cleaning was done exactly to surface the prs that still needed attention
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org