-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: Allow merging on Index vectors #19073
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
BUG: Allow merging on Index vectors #19073
Conversation
Codecov Report
@@ Coverage Diff @@
## master #19073 +/- ##
==========================================
+ Coverage 91.53% 91.53% +<.01%
==========================================
Files 148 148
Lines 48688 48690 +2
==========================================
+ Hits 44566 44568 +2
Misses 4122 4122
Continue to review full report at Codecov.
|
pandas/core/reshape/merge.py
Outdated
x, (np.ndarray, Series)) and len(x) == len(left) | ||
is_rkey = lambda x: isinstance( | ||
x, (np.ndarray, Series)) and len(x) == len(right) | ||
is_lkey = lambda x: isinstance(x, list_types) and len(x) == len(left) |
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.
can you use is_list_like
here?
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.
I thought about that, but passing in list
or tuple
is not accepted (later on, we check for the dtype
attribute by comparing dtypes). Those data types will pass the is_list_like
check, however.
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.
maybe lambda x: is_list_like(x) and hasattr(x, 'dtype')
?
just trying to avoid hardcoding (actually you could add that as is_array_like
in dtypes/common
, seems useful
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.
Yeah, is_array_like
makes sense as an abstraction. I'll add that.
@@ -1370,6 +1370,22 @@ def f(): | |||
household.join(log_return, how='outer') | |||
pytest.raises(NotImplementedError, f) | |||
|
|||
def test_merge_datetime_index(self): |
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.
can you parameterize on ndarray, Series, Index
(for the df.index.year arg)
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.
Done.
224ee15
to
6ce573a
Compare
pandas/core/dtypes/inference.py
Outdated
------- | ||
is_array_like : bool | ||
Whether `obj` has array-like properties. | ||
""" |
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.
can you show Index, Series, ndarray (and a scalar) as examples
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.
as a followup we could replace code in various places to use this
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.
Done.
This behavior used to work in v0.19.0 and is consistent with the documentation. Closes pandas-devgh-19038
Used for abstracting checks in DataFrame.merge, but the function itself can be quite useful.
6ce573a
to
1a553bc
Compare
@jreback : Comments have been addressed, and all is green. PTAL. |
very nice @gfyoung thanks! |
This behavior used to work in v0.19.0 and
is consistent with the documentation.
Closes #19038