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

Raise a more helpful error for duplicated columns in Join #820

Merged
merged 2 commits into from
Sep 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions databricks/koalas/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -5433,6 +5433,14 @@ def join(self, right: 'DataFrame', on: Optional[Union[str, List[str]]] = None,
2 K1 A1 B1
3 K2 A2 B2
"""
if isinstance(right, ks.Series):
common = list(self.columns.intersection([right.name]))
else:
common = list(self.columns.intersection(right.columns))
if len(common) > 0 and not lsuffix and not rsuffix:
raise ValueError(
"columns overlap but no suffix specified: "
"{rename}".format(rename=common))
if on:
self = self.set_index(on)
join_kdf = self.merge(right, left_index=True, right_index=True, how=how,
Expand Down
6 changes: 6 additions & 0 deletions databricks/koalas/tests/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,7 @@ def test_join(self):
'A': ['A0', 'A1', 'A2', 'A3']}, columns=['key', 'A'])
kdf2 = ks.DataFrame({'key': ['K0', 'K1', 'K2'],
'B': ['B0', 'B1', 'B2']}, columns=['key', 'B'])
ks1 = ks.Series(['A1', 'A5'], index=[1, 2], name='A')
join_pdf = pdf1.join(pdf2, lsuffix='_left', rsuffix='_right')
join_pdf.sort_values(by=list(join_pdf.columns), inplace=True)

Expand All @@ -1009,6 +1010,11 @@ def test_join(self):

self.assert_eq(join_pdf, join_kdf)

# join with duplicated columns in Series and DataFrame
with self.assertRaisesRegex(ValueError,
"columns overlap but no suffix specified"):
kdf1.join(ks1, how='outer')
kdf1.join(kdf2, how='outer')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually this only tests the first line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry. I will fix it.

Copy link
Member

Choose a reason for hiding this comment

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

Ah yes. Sorry for missing this one will take a closer look next time @ueshin

# check `on` parameter
join_pdf = pdf1.join(pdf2.set_index('key'), on='key', lsuffix='_left', rsuffix='_right')
join_pdf.sort_values(by=list(join_pdf.columns), inplace=True)
Expand Down