Skip to content
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

Fix DataFrame.koalas.apply_batch to support additional dtypes. #2126

Merged
merged 3 commits into from Mar 30, 2021

Conversation

ueshin
Copy link
Collaborator

@ueshin ueshin commented Mar 30, 2021

Fix DataFrame.koalas.apply_batch to support additional dtypes.

After this, additional dtypes can be specified in the return type annotation of the UDFs for DataFrame.koalas.apply_batch.

>>> kdf = ks.DataFrame(
...     {"a": ["a", "b", "c", "a", "b", "c"], "b": ["b", "a", "c", "c", "b", "a"]}
... )
>>> dtype = pd.CategoricalDtype(categories=["a", "b", "c", "d"])
>>> def to_category(pdf) -> ks.DataFrame["a": dtype, "b": dtype]:
...     return pdf.astype(dtype)
...
>>> applied = kdf.koalas.apply_batch(to_category)
>>> applied
   a  b
0  a  b
1  b  a
2  c  c
3  a  c
4  b  b
5  c  a
>>> applied.dtypes
a    category
b    category
dtype: object

FYI: without the fix:

>>> applied
   a  b
0  0  1
1  1  0
2  2  2
3  0  2
4  1  1
5  2  0
>>> applied.dtypes
a    int64
b    int64
dtype: object

@xinrong-meng
Copy link
Contributor

Looks great! Pending tests. Thanks!

@ueshin
Copy link
Collaborator Author

ueshin commented Mar 30, 2021

Thanks! merging.

@ueshin ueshin merged commit 6fae0cb into databricks:master Mar 30, 2021
@ueshin ueshin deleted the frame_apply_batch branch March 30, 2021 22:48
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.

None yet

2 participants