Conversation
`Dataset.to_pandas()` returns ArrayXD columns as `PandasArrayExtensionArray`,
but that pandas extension array did not implement pyarrow's `__arrow_array__`
protocol, so converting the DataFrame back to Arrow failed with
`ArrowTypeError: Did not pass numpy.dtype object`. This broke
`Dataset.from_pandas(ds.to_pandas())` and `ds.with_format("pandas").map(fn,
batched=True)` for any dataset with an Array2D..Array5D column.
The new `__arrow_array__` builds the list storage with the existing
`to_pyarrow_listarray` helper and wraps it in the matching ArrayXD extension
type (inferred from the numpy data, or taken from the requested type), so the
column keeps its Array2D/3D/4D/5D feature after the round trip.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
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.
Fixes #8699
Dataset.to_pandas()returns ArrayXD columns asPandasArrayExtensionArray, but that extension array never implemented pyarrow's__arrow_array__protocol, sopa.Table.from_pandasraisedArrowTypeError: Did not pass numpy.dtype object. This brokeDataset.from_pandas(ds.to_pandas())andds.with_format("pandas").map(fn, batched=True)for any dataset with anArray2D..Array5Dcolumn.This PR adds
PandasArrayExtensionArray.__arrow_array__:to_pyarrow_listarrayhelper (same code path asArrowWriter), so fixed-shape and dynamic-first-dimension arrays and null rows are handled the same way as when writing;ArrayNDExtensionType, taken from the requestedtypewhen pyarrow passes one (e.g.schema=), otherwise inferred from the numpy data (shape/dtype), so the column keeps its ArrayXD feature after the round trip;Tests:
test_array_xd_from_pandas(fixed + dynamic shape; coverspa.array(series.array),Dataset.from_pandaswith/withoutfeatures, and a pandas-formatted batchedmap) andtest_array_xd_from_pandas_with_none(null row preserved as an Arrow null).tests/features/test_array_xd.py,test_features.py,test_formatting.pyand the pandas/map subset oftest_arrow_dataset.pypass;ruff check/ruff format --checkclean on the changed files.Disclosure: found, reproduced and the draft fix tested locally with the help of an AI coding agent (Claude Code); reviewed before filing.
馃 Generated with Claude Code