-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Bug: Join with Series inconsistent when DataFrame is empty vs when it is not #11719
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
where does this come from? In this case there are no matches, yet you need an index. What would you have it do? |
The docstring leaves it unspecified, or at least it's not very clear; so combined with a python interpreter, I assume it always returns the left side's index. Further, I interpreted Now, back to this case. I have an algorithm whose inputs sometimes contains an empty DataFrame. This will cause a lot of df = df.join(s, how='right', on='gene')
# later on
df.reset_index().groupby('gene_id')['family'] # <-- no 'family' column if input df was empty, yet worked just fine when input df wasn't empty |
ok, can you make a short tests which exercises all of these cases (e.g. 4 x how x (left empty, right non-empty + left non-empty, right empty + both empty + both non-empty), and show results? this can confirm what is existing behavior. essentialy this is a nested loop over the cases (and which can directly be turned into a test) |
Looks like this needs more information of the expected behavior of multiple cases, so closing until there is more clarity what the intended behavior should be |
Expected
Regardless of the arguments specified, the return of
DataFrame.join
always has the left side's index values and name. In the case ofhow='right'
, there should benp.nan
in the index when the right side does not 'match' a row on the left.In this case:
Actual / reproduce
Right index is returned for empty dataframe:
Note that it doesn't happen with non-empty frames:
Version
The text was updated successfully, but these errors were encountered: