Repository navigation
GH-35721: [Python] Recognize pandas arrays in the array() constructor for the from_pandas argument - #55477
Open
jay23606 wants to merge 1 commit into
Conversation
Author
|
I have read the CLA Document and I hereby sign the CLA |
|
|
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are recorded for the change aligning ExtensionArray null handling with Series and Index inputs.
No open issues 🎉
What changed in this PR
This PR addresses GH-35721 by extending pa.array()’s automatic pandas null handling to pandas ExtensionArray inputs, aligning them with Series and Index inputs.
Changes:
- Detects extension dtypes in
get_valuesto enable pandas semantics automatically. - Adds a regression test checking that a floating-point ExtensionArray converts NaN to null when
from_pandasis omitted.
The new test was syntax-checked locally; runtime validation remains pending in CI.
| File | Description |
|---|---|
python/pyarrow/tests/test_array.py |
Adds regression coverage for ExtensionArray null handling. |
python/pyarrow/array.pxi |
Uses extension-dtype detection to select pandas semantics. |
Review effort: Balanced
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When
pa.array()is called withoutfrom_pandas, it setsfrom_pandas=Trueautomatically only for pandas Series and Index inputs. A pandas ExtensionArray such aspd.array([1.2, np.nan], dtype=float)was not detected, so NaN was kept as NaN instead of being converted to null, unlike the Series case.Change
In
get_values(python/pyarrow/array.pxi), the generic branch now setsis_pandas_objectwhen the input has an extension dtype (pandas_api.is_extension_array_dtype(obj)). Plain lists and numpy arrays keep the existing behaviour.Testing
Added
test_pandas_null_sentinels_extension_arrayinpython/pyarrow/tests/test_array.py. It checks thatpa.array(pd.array([1.2, np.nan], dtype=float))equals thefrom_pandas=Trueresult and has one null. The test could not be run in this environment because pyarrow is not built here, so it is verified by CI only. Only a syntax check was run locally:python -c "import ast,sys; ast.parse(open('python/pyarrow/tests/test_array.py',encoding='utf-8').read()); print('syntax ok')".Regression test: untested: CONTRIBUTING does not mention tests
Fixes #35721