From ebf292b1ecb4401b52bf361aae5d66ec2b615c8a Mon Sep 17 00:00:00 2001 From: Brock Date: Tue, 2 May 2023 09:08:42 -0700 Subject: [PATCH] REF: merge.py check for known arraylikes --- pandas/core/reshape/merge.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/pandas/core/reshape/merge.py b/pandas/core/reshape/merge.py index 0c438a7b8eb7c..a96a08f18e81f 100644 --- a/pandas/core/reshape/merge.py +++ b/pandas/core/reshape/merge.py @@ -52,7 +52,6 @@ ensure_float64, ensure_int64, ensure_object, - is_array_like, is_bool, is_bool_dtype, is_extension_array_dtype, @@ -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) @@ -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): @@ -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 @@ -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 = ( @@ -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 = (