-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
BUG: can't concatenate DataFrame with Series with duplicate keys #33805
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
Conversation
pandas/core/reshape/concat.py
Outdated
except KeyError as err: | ||
raise ValueError(f"Key {key} not in level {level}") from err | ||
mask = level == key | ||
if not any(mask): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use mask.any()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it’s a bit more idiomatic to use .get_indexer here which handles duplicates - if u can make that work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jreback thanks for the review. I've looked into that, but it seems it errors with duplicates:
>>> pd.Index(['a', 'b']).get_indexer(['a'])
array([0])
>>> pd.Index(['a', 'b', 'b']).get_indexer(['a'])
---------------------------------------------------------------------------
InvalidIndexError Traceback (most recent call last)
<ipython-input-10-0a1bc1d27a1b> in <module>
----> 1 pd.Index(['a', 'b', 'b']).get_indexer(['a'])
~/pandas-dev/pandas/core/indexes/base.py in get_indexer(self, target, method, limit, tolerance)
2926
2927 if not self.is_unique:
-> 2928 raise InvalidIndexError(
2929 "Reindexing only valid with uniquely valued Index objects"
2930 )
InvalidIndexError: Reindexing only valid with uniquely valued Index objects
Should I open an issue for get_indexer
first and make sure that deals with duplicates before coming back to this one?
lgtm. let's merge on green. |
Thanks - sure, it's green now |
Thanks @MarcoGorelli |
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff