Skip to content

[SPARK-56256][PYTHON] Add emptyDataFrame API to SparkSession#55055

Open
zhengruifeng wants to merge 3 commits intoapache:masterfrom
zhengruifeng:emptyDataFrame
Open

[SPARK-56256][PYTHON] Add emptyDataFrame API to SparkSession#55055
zhengruifeng wants to merge 3 commits intoapache:masterfrom
zhengruifeng:emptyDataFrame

Conversation

@zhengruifeng
Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Add a new SparkSession.emptyDataFrame(schema) API that creates an empty DataFrame with the specified schema.

Why are the changes needed?

Creating an empty DataFrame with a given schema is a common operation, but currently requires calling spark.createDataFrame([], schema) which is not very intuitive. This new API provides a more readable and discoverable way to create empty DataFrames.

Does this PR introduce any user-facing change?

Yes. Adds a new public API SparkSession.emptyDataFrame(schema: Union[StructType, str]) -> DataFrame.

How was this patch tested?

Added unit tests in test_creation.py covering both StructType and DDL string schema inputs. Tests are shared via the mixin and run for both classic and Spark Connect.

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

Yes.

Copy link
Copy Markdown
Member

@dongjoon-hyun dongjoon-hyun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, LGTM because this is a Python version of the following

Copy link
Copy Markdown
Member

@dongjoon-hyun dongjoon-hyun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you follow the Apache Spark and ASF guideline, @zhengruifeng ? We need the
phrase: 'Generated-by: ' followed by the name of the tool and its version.

Image

Apache Spark Guideline

If generative AI tooling has been used in the process of authoring this patch, please include the
phrase: 'Generated-by: ' followed by the name of the tool and its version.

ASF Guideline

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