[FEAT] Add Dtypes method to DataFrame#177
Open
piyushka-ally wants to merge 1 commit intoapache:masterfrom
Open
[FEAT] Add Dtypes method to DataFrame#177piyushka-ally wants to merge 1 commit intoapache:masterfrom
piyushka-ally wants to merge 1 commit intoapache:masterfrom
Conversation
Add Dtypes() to return column names paired with their data type strings, mirroring PySpark's dtypes property. Addresses apache#58. Co-authored-by: Isaac
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.
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.