@@ -1911,7 +1911,9 @@ def _merge_blocks(
1911
1911
return blocks
1912
1912
1913
1913
1914
- def _compare_or_regex_search (a , b , regex = False ):
1914
+ def _compare_or_regex_search (
1915
+ a : Union [ArrayLike , Scalar ], b : Union [ArrayLike , Scalar ], regex : bool = False
1916
+ ) -> Union [ArrayLike , bool ]:
1915
1917
"""
1916
1918
Compare two array_like inputs of the same shape or two scalar values
1917
1919
@@ -1930,13 +1932,13 @@ def _compare_or_regex_search(a, b, regex=False):
1930
1932
"""
1931
1933
1932
1934
def _check_comparison_types (
1933
- result : Union [ArrayLike , Scalar ],
1935
+ result : Union [ArrayLike , bool ],
1934
1936
a : Union [ArrayLike , Scalar ],
1935
1937
b : Union [ArrayLike , Scalar ],
1936
- ) -> Union [ArrayLike , Scalar ]:
1938
+ ) -> Union [ArrayLike , bool ]:
1937
1939
"""
1938
- Raises an error if the two arrays cannot be compared,
1939
- otherwise returns the comparison result as expected.
1940
+ Raises an error if the two arrays (a,b) cannot be compared.
1941
+ Otherwise, returns the comparison result as expected.
1940
1942
"""
1941
1943
if is_scalar (result ) and (
1942
1944
isinstance (a , np .ndarray ) or isinstance (b , np .ndarray )
@@ -1958,22 +1960,21 @@ def _check_comparison_types(
1958
1960
op = lambda x : operator .eq (x , b )
1959
1961
else :
1960
1962
op = np .vectorize (
1961
- lambda x : bool (re .search (b , x )) if isinstance (x , str ) else False
1963
+ lambda x : bool (re .search (b , x ))
1964
+ if isinstance (x , str ) and isinstance (b , str )
1965
+ else False
1962
1966
)
1963
1967
1964
- is_a_array = isinstance (a , np .ndarray )
1965
- is_b_array = isinstance (b , np .ndarray )
1966
-
1967
1968
# GH#32621 use mask to avoid comparing to NAs
1968
- if is_a_array and not is_b_array :
1969
+ if isinstance ( a , np . ndarray ) and not isinstance ( b , np . ndarray ) :
1969
1970
mask = np .reshape (~ (isna (a )), a .shape )
1970
- elif is_b_array and not is_a_array :
1971
+ elif isinstance ( b , np . ndarray ) and not isinstance ( a , np . ndarray ) :
1971
1972
mask = np .reshape (~ (isna (b )), b .shape )
1972
- elif is_a_array and is_b_array :
1973
+ elif isinstance ( a , np . ndarray ) and isinstance ( b , np . ndarray ) :
1973
1974
mask = ~ (isna (a ) | isna (b ))
1974
- if is_a_array :
1975
+ if isinstance ( a , np . ndarray ) :
1975
1976
a = a [mask ]
1976
- if is_b_array :
1977
+ if isinstance ( b , np . ndarray ) :
1977
1978
b = b [mask ]
1978
1979
1979
1980
if is_datetimelike_v_numeric (a , b ) or is_numeric_v_string_like (a , b ):
0 commit comments