Skip to content

Commit 98f130d

Browse files
jbrockmendelYi Wei
authored and
Yi Wei
committed
REF: merge.py check for known arraylikes (pandas-dev#53041)
1 parent 6665244 commit 98f130d

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

pandas/core/reshape/merge.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
ensure_float64,
5353
ensure_int64,
5454
ensure_object,
55-
is_array_like,
5655
is_bool,
5756
is_bool_dtype,
5857
is_extension_array_dtype,
@@ -124,6 +123,8 @@
124123
np.object_: libhashtable.ObjectFactorizer,
125124
}
126125

126+
_known = (np.ndarray, ExtensionArray, Index, ABCSeries)
127+
127128

128129
@Substitution("\nleft : DataFrame or named Series")
129130
@Appender(_merge_doc, indents=0)
@@ -928,7 +929,7 @@ def _maybe_add_join_keys(
928929
left_has_missing = None
929930
right_has_missing = None
930931

931-
assert all(is_array_like(x) for x in self.left_join_keys)
932+
assert all(isinstance(x, _known) for x in self.left_join_keys)
932933

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

11421143
left, right = self.left, self.right
11431144

1144-
is_lkey = lambda x: is_array_like(x) and len(x) == len(left)
1145-
is_rkey = lambda x: is_array_like(x) and len(x) == len(right)
1145+
is_lkey = lambda x: isinstance(x, _known) and len(x) == len(left)
1146+
is_rkey = lambda x: isinstance(x, _known) and len(x) == len(right)
11461147

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

19281929
if not self.right_index:
19291930
right_on_0 = right_on[0]
1930-
if is_array_like(right_on_0):
1931+
if isinstance(right_on_0, _known):
19311932
ro_dtype = right_on_0.dtype
19321933
else:
19331934
ro_dtype = (

0 commit comments

Comments
 (0)