Skip to content

[SPARK-46776][PYTHON] Support pa.ChunkedArray columns in createDataFrame from pandas#56157

Closed
Yicong-Huang wants to merge 1 commit into
apache:masterfrom
Yicong-Huang:SPARK-46776
Closed

[SPARK-46776][PYTHON] Support pa.ChunkedArray columns in createDataFrame from pandas#56157
Yicong-Huang wants to merge 1 commit into
apache:masterfrom
Yicong-Huang:SPARK-46776

Conversation

@Yicong-Huang
Copy link
Copy Markdown
Contributor

@Yicong-Huang Yicong-Huang commented May 27, 2026

What changes were proposed in this pull request?

pa.Array.from_pandas may return a pa.ChunkedArray (e.g. for string[pyarrow] dtype, or string data over 2 GB), which pa.RecordBatch.from_arrays rejects. Route the conversion through pa.Table.from_arrays(...).to_batches() instead, which accepts both Array and ChunkedArray and emits zero-copy RecordBatches aligned on a common chunk boundary.

Why are the changes needed?

Fix createDataFrame from pandas raising TypeError: Cannot convert pyarrow.lib.ChunkedArray to pyarrow.lib.Array. See SPARK-46776.

Does this PR introduce any user-facing change?

Yes. createDataFrame(pandas_df) no longer raises when a column is backed by a multi-chunk pyarrow array.

How was this patch tested?

New test ArrowTestsMixin.test_createDataFrame_pandas_chunked_array_backed, exercised on both classic and Spark Connect paths via the parity suite.

Was this patch authored or co-authored using generative AI tooling?

No

@Yicong-Huang
Copy link
Copy Markdown
Contributor Author

cc @HyukjinKwon @zhengruifeng

Yicong-Huang added a commit that referenced this pull request May 28, 2026
…ame from pandas

### What changes were proposed in this pull request?

`pa.Array.from_pandas` may return a `pa.ChunkedArray` (e.g. for `string[pyarrow]` dtype, or string data over 2 GB), which `pa.RecordBatch.from_arrays` rejects. Route the conversion through `pa.Table.from_arrays(...).to_batches()` instead, which accepts both `Array` and `ChunkedArray` and emits zero-copy `RecordBatch`es aligned on a common chunk boundary.

### Why are the changes needed?

Fix `createDataFrame` from pandas raising `TypeError: Cannot convert pyarrow.lib.ChunkedArray to pyarrow.lib.Array`. See [SPARK-46776](https://issues.apache.org/jira/browse/SPARK-46776).

### Does this PR introduce _any_ user-facing change?

Yes. `createDataFrame(pandas_df)` no longer raises when a column is backed by a multi-chunk pyarrow array.

### How was this patch tested?

New test `ArrowTestsMixin.test_createDataFrame_pandas_chunked_array_backed`, exercised on both classic and Spark Connect paths via the parity suite.

### Was this patch authored or co-authored using generative AI tooling?

No

Closes #56157 from Yicong-Huang/SPARK-46776.

Authored-by: Yicong Huang <17627829+Yicong-Huang@users.noreply.github.com>
Signed-off-by: Yicong-Huang <17627829+Yicong-Huang@users.noreply.github.com>
(cherry picked from commit 2f4ed64)
Signed-off-by: Yicong-Huang <17627829+Yicong-Huang@users.noreply.github.com>
@Yicong-Huang
Copy link
Copy Markdown
Contributor Author

Yicong-Huang commented May 28, 2026

Merged to master and branch-4.x.
Thanks @HyukjinKwon!

@zhengruifeng
Copy link
Copy Markdown
Contributor

late lgtm

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants