Skip to content

[SPARK-48220][PYTHON] Allow passing PyArrow Table to createDataFrame() - #46529

Closed
ianmcook wants to merge 30 commits into
apache:masterfrom
ianmcook:SPARK-48220
Closed

[SPARK-48220][PYTHON] Allow passing PyArrow Table to createDataFrame()#46529
ianmcook wants to merge 30 commits into
apache:masterfrom
ianmcook:SPARK-48220

Conversation

@ianmcook

@ianmcookianmcook commented May 10, 2024

Copy link
Copy Markdown
Member

What changes were proposed in this pull request?

  • Add support for passing a PyArrow Table to createDataFrame().
  • Document this on the Apache Arrow in PySpark user guide page.
  • Fix an issue with timestamp and struct columns in toArrow().

Why are the changes needed?

This seems like a logical next step after the addition of a toArrow() DataFrame method in #45481.

Does this PR introduce any user-facing change?

Users will have the ability to pass PyArrow Tables to createDataFrame(). There are no changes to the parameters of createDataFrame(). The only difference is that data can now be a PyArrow Table.

How was this patch tested?

Many tests were added, for Spark Classic and Spark Connect. I ran the tests locally with older versions of PyArrow installed (going back to 10.0).

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

No

Comment threadpython/pyspark/sql/tests/typing/test_session.yml Outdated
Comment threadpython/pyspark/sql/session.py Outdated
Comment threadpython/pyspark/sql/connect/session.py Outdated
@ianmcook
ianmcookforce-pushed the SPARK-48220 branch 8 times, most recently from c408d0b to 795d01aCompareMay 13, 2024 22:14
@alippai

Copy link
Copy Markdown

This makes the usage so much easier, thanks!

What will happen with the nanosecond timestamps? Truncated to milliseconds?

@ianmcook
ianmcookforce-pushed the SPARK-48220 branch 4 times, most recently from 005c4f7 to 7e34472CompareMay 15, 2024 16:15
@ianmcook

ianmcook commented May 15, 2024

Copy link
Copy Markdown
MemberAuthor

What will happen with the nanosecond timestamps? Truncated to milliseconds?

Truncated to microseconds for now.

@alippai

Copy link
Copy Markdown

I wish we had ns support in spark 4.0 as Java, parquet, arrow etc uses it natively now, but that’s certainly a different discussion and MRs :)

Thanks for the new API!

@ianmcook
ianmcook marked this pull request as ready for review May 16, 2024 07:52
@ianmcook
ianmcook requested a review from HyukjinKwonMay 16, 2024 07:52
@ianmcook
ianmcookforce-pushed the SPARK-48220 branch 3 times, most recently from 5275bb2 to 4cc3ca2CompareMay 16, 2024 16:10
@ianmcook

Copy link
Copy Markdown
MemberAuthor

Just rebased to master

@HyukjinKwon

Copy link
Copy Markdown
Member

will merge once ci passes

@ianmcook

Copy link
Copy Markdown
MemberAuthor

Thanks @HyukjinKwon. After you merge I will rebase the small follow-up PR #46688 and prep it for review.

@HyukjinKwon

Copy link
Copy Markdown
Member

Merged to master.

HyukjinKwon pushed a commit that referenced this pull request Jun 3, 2024
### What changes were proposed in this pull request?
This is a small follow-up to #46529. This adds support for some more Arrow data types:
- fixed-size binary
- fixed-size list
- large list
### Why are the changes needed?
Users who are creating Spark DataFrames from PyArrow Tables will expect it to work if their Tables contain these types of columns
### Does this PR introduce _any_ user-facing change?
It will prevent an error in the case where the user has one of these types of columns in their PyArrow Table. There are no other user-facing changes.
### How was this patch tested?
Tests are included.
### Was this patch authored or co-authored using generative AI tooling?
No
Closes#46688 from ianmcook/SPARK-48374.
Authored-by: Ian Cook <ianmcook@gmail.com>
Signed-off-by: Hyukjin Kwon <gurwls223@apache.org>
HyukjinKwon pushed a commit that referenced this pull request Jun 16, 2024
### What changes were proposed in this pull request?
This is a small follow-up to #46529. It fixes a known issue affecting PyArrow Tables passed to `spark.createDataFrame()`. After this PR, if the user is running PyArrow 17.0.0 or higher, null values in MapArray columns containing nested fields or timestamps will be preserved.
### Why are the changes needed?
Before this PR, null values in MapArray columns containing nested fields or timestamps are replaced by empty lists when a PyArrow Table is passed to `spark.createDataFrame()`.
### Does this PR introduce _any_ user-facing change?
It prevents loss of nulls in the case described above. There are no other user-facing changes.
### How was this patch tested?
A test is included.
### Was this patch authored or co-authored using generative AI tooling?
No
Closes#46837 from ianmcook/SPARK-48302.
Authored-by: Ian Cook <ianmcook@gmail.com>
Signed-off-by: Hyukjin Kwon <gurwls223@apache.org>
Sign up for freeto 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.

8 participants

@ianmcook@alippai@HyukjinKwon@amol-@jorisvandenbossche@BryanCutler@zhengruifeng@xinrong-meng