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 GroupBy.head to recognize agg_columns. #1474

Merged
merged 1 commit into from
May 11, 2020

Conversation

ueshin
Copy link
Collaborator

@ueshin ueshin commented May 9, 2020

Fixing GroupBy.head to recognize agg_columns.

>>> kdf = ks.DataFrame({"a": [1, 1, 1, 1, 2, 2, 2, 3, 3, 3] * 3, "b": [2, 3, 1, 4, 6, 9, 8, 10, 7, 5] * 3, "c": [3, 5, 2, 5, 1, 2, 6, 4, 3, 6] * 3})
>>> kdf.groupby("a")[["b"]].head(2).sort_index()
   a   b  c
0  1   2  3
1  1   3  5
4  2   6  1
5  2   9  2
7  3  10  4
8  3   7  3

This should be:

>>> pdf.groupby("a")[["b"]].head(2).sort_index()
    b
0   2
1   3
4   6
5   9
7  10
8   7

@ueshin ueshin requested a review from HyukjinKwon May 9, 2020 02:05
@codecov-io
Copy link

Codecov Report

Merging #1474 into master will increase coverage by 0.03%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1474      +/-   ##
==========================================
+ Coverage   93.74%   93.77%   +0.03%     
==========================================
  Files          36       36              
  Lines        8409     8420      +11     
==========================================
+ Hits         7883     7896      +13     
+ Misses        526      524       -2     
Impacted Files Coverage Δ
databricks/koalas/groupby.py 88.85% <100.00%> (+0.21%) ⬆️
databricks/koalas/frame.py 95.58% <0.00%> (+0.04%) ⬆️
databricks/koalas/generic.py 97.02% <0.00%> (+0.37%) ⬆️

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 2e68e03...205f99d. Read the comment docs.

kdf = kdf[
[s.rename(label) for s, label in zip(self._groupkeys, groupkey_labels)] + agg_columns
]
groupkey_scols = [kdf._internal.spark_column_for(label) for label in groupkey_labels]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ueshin, it looks good but can we have a private function for these cases? Looks like it's duplicated in #1472 https://github.com/databricks/koalas/pull/1473/files and #1471.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I'll address it in the following PRs.

Copy link
Member

@HyukjinKwon HyukjinKwon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ueshin
Copy link
Collaborator Author

ueshin commented May 11, 2020

Thanks! I'd merge this now. I'll address the comment in the following PRs.

@ueshin ueshin merged commit 4811f58 into databricks:master May 11, 2020
@ueshin ueshin deleted the groupby_head branch May 11, 2020 18:09
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