-
Notifications
You must be signed in to change notification settings - Fork 234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert df to pyspark DataFrame if it is pandas before writing #469
Merged
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6f28e2e
Convert df to pyspark DataFrame if it is pandas before writing
dbeatty10 1afde7a
Changelog entry
dbeatty10 68c6aac
Use `overwriteSchema` option like dbt-databricks
dbeatty10 82062d4
Upstream `py_write_table` macro from dbt-databricks
dbeatty10 1afc312
Convert df to a PySpark DataFrame if it's a Pandas-on-Spark DataFrame…
dbeatty10 09388ff
Separate conversion logic from import logic
dbeatty10 dca2b40
Raise exception if not able to convert to a Spark DataFrame
dbeatty10 cbf11e9
Prefer pandas → pandas-on-Spark → Spark over direct pandas → Spark
dbeatty10 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
kind: Under the Hood | ||
body: Convert df to pyspark DataFrame if it is pandas before writing | ||
time: 2022-09-16T12:57:06.846297-06:00 | ||
custom: | ||
Author: chamini2 dbeatty10 | ||
Issue: "468" | ||
PR: "469" |
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this line required? (the
import pandas
one)From what I see, in databricks we might usually want to load
pyspark.pandas
rather thanpandas
(and I don't think it is required here)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@b-per I believe it is required in order to do test the type:
isinstance(df, pandas.core.frame.DataFrame)
. I tried commenting out the single line with the import, and it did not work.However, digging into your question did uncover something else...
Goal
For the
py_write_table()
macro, we want the return type to bepyspark.sql.dataframe.DataFrame
.Potential input types
There are three different data types we expect 1 it to be:
pyspark.sql.dataframe.DataFrame
(PySpark DataFrame)pandas.core.frame.DataFrame
(Pandas DataFrame)pyspark.pandas.frame.DataFrame
(Pandas-on-Spark DataFrame)Are we handling each of the three cases?
pyspark.sql.dataframe.DataFrame
, so no conversion necessary.pandas.core.frame.DataFrame
and converts it usingspark.createDataFrame()
if so.to_spark()
on it 2.I'll update this PR to include the third case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, my bad, I thought
isinstance
was comparing with a string and not an object type.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@b-per Very glad you asked, because now we have a more robust implementation as a result!