Skip to content

[FEAT] Add Dtypes method to DataFrame#177

Open
piyushka-ally wants to merge 1 commit intoapache:masterfrom
piyushka-ally:feat/add-dtypes-method
Open

[FEAT] Add Dtypes method to DataFrame#177
piyushka-ally wants to merge 1 commit intoapache:masterfrom
piyushka-ally:feat/add-dtypes-method

Conversation

@piyushka-ally
Copy link
Copy Markdown

What changes were proposed in this pull request?

This PR adds the Dtypes method to the DataFrame interface and its implementation on dataFrameImpl in the Go Spark Connect client. The method returns column names paired with their data type strings as [][2]string, mirroring PySpark's DataFrame.dtypes property.

The implementation reuses the existing Schema() method and follows the same pattern as the already-implemented Columns() method (spark/sql/dataframe.go:303), additionally extracting field.DataType.TypeName() for each field.

This is tracked in the umbrella issue: #58

Why are the changes needed?

dtypes is a standard DataFrame API in PySpark that returns the list of column names and their data types. It is listed as unimplemented in the DataFrame functionality tracking issue. Adding it improves API parity between the Go Spark Connect client and PySpark, making it easier for users to inspect the schema of a DataFrame in a concise format.

Does this PR introduce any user-facing change?

Yes. A new method Dtypes(ctx context.Context) ([][2]string, error) is added to the public DataFrame interface. Users can now call Dtypes on a DataFrame to get column name and type pairs, for example:

dtypes, err := df.Dtypes(ctx)
// dtypes: [["age", "Integer"], ["name", "String"]]

There is no change to existing behavior.

How was this patch tested?

The implementation is a straightforward extension of the existing Columns() method pattern; it calls Schema() and iterates over the fields. No new unit tests were added because Dtypes depends on Schema() which requires a live Spark session (same as Columns()). The method can be verified via integration tests against a running Spark Connect server.

Add Dtypes() to return column names paired with their data type strings,
mirroring PySpark's dtypes property. Addresses apache#58.

Co-authored-by: Isaac
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.

1 participant