-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Left join without passing right_on
raises TypeError instead of intended ValueError
#26824
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
Comments
This is by design. Not entirely sure what you want to have happen (your example doesn't have an "A" label) but you might just be looking for Worth checking out the user guide for merging, joining and concatenation to get a feel for this: https://pandas.pydata.org/pandas-docs/stable/user_guide/merging.html# |
@WillAyd Sorry, I should have added the stack trace. I'm not raising the issue on usage. In the stacktrace I noticed the following:
You can see that the intention was to raise the |
Oh ok I see your point. That probably would make more sense. If you’d like to try a PR would certainly welcome that! |
Can I take this one only if @ajpen is not taking this up? I'm completely new to submitting to OSS and would appreciate some help. Here's what I think should help, a couple checks inside the checks for right_on and left_on elif self.left_on is not None:
n = len(self.left_on)
if self.right_index:
if len(self.left_on) != self.right.index.nlevels:
raise ValueError('len(left_on) must equal the number '
'of levels in the index of "right"')
self.right_on = [None] * n
if not self.right_on:
raise ValueError('both left_on and right_on should '
'be passed')
elif self.right_on is not None:
n = len(self.right_on)
if self.left_index:
if len(self.right_on) != self.left.index.nlevels:
raise ValueError('len(right_on) must equal the number '
'of levels in the index of "left"')
self.left_on = [None] * n
if not self.left_on:
raise ValueError('both left_on and right_on should '
'be passed')
if len(self.right_on) != len(self.left_on):
raise ValueError("len(right_on) must equal len(left_on)") |
@harshit-py Be my guest :) |
if this is raising an exception as expected and only the message is unclear or the exception type is inappropriate, then handling the exception with try/except and re-raising may be more appropriate than additional parameter validation. |
@simonjayhawkins thanks for the comment, do you mean something like this? try:
if len(self.right_on) != len(self.left_on):
raise ValueError("len(right_on) must equal len(left_on)")
except TypeError:
raise ValueError('both left_on and right_on should '
'be passed') Also, how to make sense of the Codecov report in the last unsuccessful PR? Pardon me for asking these basic questions, this would be my first submission. |
@harshit-py my initial concern was adding more validation to
the try/except may not be appropriate in this case after all. |
Some of the validation must have changed in the meantime since with OP's example I am getting
Which is a fairly clear error message. If anyone can reproduce the original error message with a new example we can reopen and consider how to provide a clearer error message. Closing for now. |
Code
Problem description
Unexpected exception is raised when doing a left join without passing arguments for
right_on
.Expected Output
Actual Output
The text was updated successfully, but these errors were encountered: