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 Series.koalas.transform_batch to support additional dtypes and reuse it. #2127

Merged
merged 3 commits into from
Mar 31, 2021

Conversation

ueshin
Copy link
Collaborator

@ueshin ueshin commented Mar 31, 2021

Fix Series.koalas.transform_batch to support additional dtypes and reuse it in Series.transform and DataFrame.transform.

After this, additional dtypes can be specified in the return type annotation of the UDFs for Series.koalas.transform_batch, Series.transform, and DataFrame.transform.

>>> 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(pser) -> ks.Series[dtype]:
...   return pser.astype(dtype)
...
>>> applied = kdf.a.koalas.transform_batch(to_category)
>>> applied
0    a
1    b
2    c
3    a
4    b
5    c
Name: a, dtype: category
Categories (4, object): ['a', 'b', 'c', 'd']
>>> applied.dtype
CategoricalDtype(categories=['a', 'b', 'c', 'd'], ordered=False)

@ueshin ueshin requested a review from xinrong-meng March 31, 2021 00:47
@codecov-io
Copy link

Codecov Report

Merging #2127 (e051950) into master (6fae0cb) will decrease coverage by 0.03%.
The diff coverage is 84.37%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2127      +/-   ##
==========================================
- Coverage   95.37%   95.34%   -0.04%     
==========================================
  Files          60       60              
  Lines       13606    13634      +28     
==========================================
+ Hits        12977    12999      +22     
- Misses        629      635       +6     
Impacted Files Coverage Δ
databricks/koalas/groupby.py 94.34% <0.00%> (ø)
databricks/koalas/accessors.py 91.98% <85.18%> (-1.52%) ⬇️
databricks/koalas/frame.py 96.49% <100.00%> (-0.06%) ⬇️
databricks/koalas/series.py 96.92% <100.00%> (-0.02%) ⬇️
databricks/koalas/missing/frame.py 100.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6fae0cb...e051950. Read the comment docs.

@xinrong-meng
Copy link
Contributor

I may need more time to fully understand the code paths. However, code changes in this PR look great! Thank you!

@ueshin
Copy link
Collaborator Author

ueshin commented Mar 31, 2021

Thanks! merging.

@ueshin ueshin merged commit bdceb8a into databricks:master Mar 31, 2021
@ueshin ueshin deleted the series_transform_batch branch March 31, 2021 20:36
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.

3 participants