Skip to content

CLN: move code out of a try clause in merge.py #30382

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

Merged
merged 1 commit into from
Dec 21, 2019
Merged
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
26 changes: 13 additions & 13 deletions pandas/core/reshape/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,20 +116,20 @@ def _groupby_and_merge(

# if we can groupby the rhs
# then we can get vastly better perf
try:

# we will check & remove duplicates if indicated
if check_duplicates:
if on is None:
on = []
elif not isinstance(on, (list, tuple)):
on = [on]

if right.duplicated(by + on).any():
_right = right.drop_duplicates(by + on, keep="last")
# TODO: use overload to refine return type of drop_duplicates
assert _right is not None # needed for mypy
right = _right
# we will check & remove duplicates if indicated
if check_duplicates:
if on is None:
on = []
elif not isinstance(on, (list, tuple)):
on = [on]

if right.duplicated(by + on).any():
_right = right.drop_duplicates(by + on, keep="last")
Copy link
Member

Choose a reason for hiding this comment

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

no risk of raising in 127/128?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was a risk already, right? This just ensures that a KeyError isn't catched unintended.

Copy link
Member

Choose a reason for hiding this comment

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

makes sense, thanks

# TODO: use overload to refine return type of drop_duplicates
assert _right is not None # needed for mypy
right = _right
try:
rby = right.groupby(by, sort=False)
except KeyError:
rby = None
Expand Down