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

Add sort parameter to concat. #1636

Merged
merged 7 commits into from
Jul 9, 2020
Merged

Add sort parameter to concat. #1636

merged 7 commits into from
Jul 9, 2020

Conversation

ueshin
Copy link
Collaborator

@ueshin ueshin commented Jul 8, 2020

Adding sort parameter to ks.concat().

@ueshin
Copy link
Collaborator Author

ueshin commented Jul 8, 2020

This is based on #1627. Please review it first.

@ueshin ueshin changed the title [WIP] Add sort parameter to concat. Add sort parameter to concat. Jul 8, 2020
@ueshin ueshin requested a review from HyukjinKwon July 8, 2020 19:47
@@ -1834,9 +1843,11 @@ def resolve_func(kdf, this_column_labels, that_column_labels):
# DataFrame, Series ... & Series, Series ...
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should throw an exception when axis=1 and sort is set:

>>> import pandas as pd
>>> pd.concat([pd.DataFrame({'b': [4, 5, 6]}, index=[4,3,2]), pd.DataFrame({'a': [3, 4, 5]}, index=[4,3,2])], sort=False, axis=1)
   b  a
4  4  3
3  5  4
2  6  5
>>> pd.concat([pd.DataFrame({'b': [4, 5, 6]}, index=[4,3,2]), pd.DataFrame({'a': [3, 4, 5]}, index=[4,3,2])], sort=True, axis=1)
   b  a
2  6  5
3  5  4
4  4  3

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

or do sort_index()?

Copy link
Collaborator Author

@ueshin ueshin Jul 9, 2020

Choose a reason for hiding this comment

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

Anyway pandas' behavior is not deterministic, at least seems so..

Copy link
Member

@HyukjinKwon HyukjinKwon Jul 9, 2020

Choose a reason for hiding this comment

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

😭 .. any way is fine. We could just sort_index() or just throw an exception

merged_columns = sorted(
list(set(itertools.chain.from_iterable(column_labelses_of_kdfs)))
)
merged_columns = column_labels_of_kdfs[0].copy()
Copy link
Member

Choose a reason for hiding this comment

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

no big deal since it's already guarded above but we could add an assert for the length of column_labels_of_kdfs to be non-empty.

Copy link
Member

Choose a reason for hiding this comment

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

We could also add an assert on merged_columns too.

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.

LGTM

@ueshin
Copy link
Collaborator Author

ueshin commented Jul 9, 2020

Thanks! merging.

@ueshin ueshin merged commit 90642b0 into databricks:master Jul 9, 2020
@ueshin ueshin deleted the concat_sort branch July 9, 2020 22:55
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.

2 participants