Skip to content

REF: merge.py check for known arraylikes #53041

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
May 4, 2023
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
13 changes: 7 additions & 6 deletions pandas/core/reshape/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
ensure_float64,
ensure_int64,
ensure_object,
is_array_like,
is_bool,
is_bool_dtype,
is_extension_array_dtype,
Expand Down Expand Up @@ -124,6 +123,8 @@
np.object_: libhashtable.ObjectFactorizer,
}

_known = (np.ndarray, ExtensionArray, Index, ABCSeries)


@Substitution("\nleft : DataFrame or named Series")
@Appender(_merge_doc, indents=0)
Expand Down Expand Up @@ -928,7 +929,7 @@ def _maybe_add_join_keys(
left_has_missing = None
right_has_missing = None

assert all(is_array_like(x) for x in self.left_join_keys)
assert all(isinstance(x, _known) for x in self.left_join_keys)

keys = zip(self.join_names, self.left_on, self.right_on)
for i, (name, lname, rname) in enumerate(keys):
Expand Down Expand Up @@ -1141,8 +1142,8 @@ def _get_merge_keys(

left, right = self.left, self.right

is_lkey = lambda x: is_array_like(x) and len(x) == len(left)
is_rkey = lambda x: is_array_like(x) and len(x) == len(right)
is_lkey = lambda x: isinstance(x, _known) and len(x) == len(left)
is_rkey = lambda x: isinstance(x, _known) and len(x) == len(right)

# Note that pd.merge_asof() has separate 'on' and 'by' parameters. A
# user could, for example, request 'left_index' and 'left_by'. In a
Expand Down Expand Up @@ -1914,7 +1915,7 @@ def _validate_left_right_on(self, left_on, right_on):
# GH#29130 Check that merge keys do not have dtype object
if not self.left_index:
left_on_0 = left_on[0]
if is_array_like(left_on_0):
if isinstance(left_on_0, _known):
lo_dtype = left_on_0.dtype
else:
lo_dtype = (
Expand All @@ -1927,7 +1928,7 @@ def _validate_left_right_on(self, left_on, right_on):

if not self.right_index:
right_on_0 = right_on[0]
if is_array_like(right_on_0):
if isinstance(right_on_0, _known):
ro_dtype = right_on_0.dtype
else:
ro_dtype = (
Expand Down