-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-24444][DOCS][PYTHON] Improve Pandas UDF docs to explain column assignment #21471
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
Changes from 3 commits
5550079
a41314f
c7f1a3f
620b22d
79b3eb3
beac351
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2500,7 +2500,8 @@ def pandas_udf(f=None, returnType=None, functionType=None): | |
| A grouped map UDF defines transformation: A `pandas.DataFrame` -> A `pandas.DataFrame` | ||
| The returnType should be a :class:`StructType` describing the schema of the returned | ||
| `pandas.DataFrame`. | ||
| The length of the returned `pandas.DataFrame` can be arbitrary. | ||
| The length of the returned `pandas.DataFrame` can be arbitrary and the columns must be | ||
| indexed so that their position matches the corresponding field in the schema. | ||
|
|
||
| Grouped map UDFs are used with :meth:`pyspark.sql.GroupedData.apply`. | ||
|
|
||
|
|
@@ -2548,6 +2549,10 @@ def pandas_udf(f=None, returnType=None, functionType=None): | |
| | 2|6.0| | ||
| +---+---+ | ||
|
|
||
| .. note:: If returning a new `pandas.DataFrame` constructed with a dictionary, it is | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we do a "warning"?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know if there is warning, but the notes show up highlighted so it's pretty clear
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. K. I think sphinx supports these http://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html#directives "caution" or "warning" seems more appropriate but note works too. |
||
| recommended to explicitly index the columns by name to ensure the positions are correct. | ||
| For example, `pd.DataFrame({'id': ids, 'a': data}, columns=['id', 'a'])`. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we recommend OrderedDict? I feel specifying column names twice is not ideal |
||
|
|
||
| .. seealso:: :meth:`pyspark.sql.GroupedData.apply` | ||
|
|
||
| 3. GROUPED_AGG | ||
|
|
||
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.
Seems my previous comments is squashed:
Should we recommend OrderedDict? I feel specifying column names twice is not ideal
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.
It's not ideal to list the column names, but I think it makes it clear that you can't rely on the dictionary order. I'll add OrderedDict there too, to show there is more than one way.