@@ -170,12 +170,13 @@ def coerce_to_array(
170170 values [~ mask_values ] = values_object [~ mask_values ].astype (bool )
171171
172172 # if the values were integer-like, validate it were actually 0/1's
173- if inferred_dtype in integer_like :
174- if not np .all (
173+ if ( inferred_dtype in integer_like ) and not (
174+ np .all (
175175 values [~ mask_values ].astype (float )
176176 == values_object [~ mask_values ].astype (float )
177- ):
178- raise TypeError ("Need to pass bool-like values" )
177+ )
178+ ):
179+ raise TypeError ("Need to pass bool-like values" )
179180
180181 if mask is None and mask_values is None :
181182 mask = np .zeros (len (values ), dtype = bool )
@@ -193,9 +194,9 @@ def coerce_to_array(
193194 if mask_values is not None :
194195 mask = mask | mask_values
195196
196- if not values .ndim = = 1 :
197+ if values .ndim ! = 1 :
197198 raise ValueError ("values must be a 1D list-like" )
198- if not mask .ndim = = 1 :
199+ if mask .ndim ! = 1 :
199200 raise ValueError ("mask must be a 1D list-like" )
200201
201202 return values , mask
@@ -395,9 +396,8 @@ def astype(self, dtype, copy: bool = True) -> ArrayLike:
395396 self ._data .astype (dtype .numpy_dtype ), self ._mask .copy (), copy = False
396397 )
397398 # for integer, error if there are missing values
398- if is_integer_dtype (dtype ):
399- if self ._hasna :
400- raise ValueError ("cannot convert NA to integer" )
399+ if is_integer_dtype (dtype ) and self ._hasna :
400+ raise ValueError ("cannot convert NA to integer" )
401401 # for float dtype, ensure we use np.nan before casting (numpy cannot
402402 # deal with pd.NA)
403403 na_value = self ._na_value
@@ -576,7 +576,7 @@ def _logical_method(self, other, op):
576576 elif isinstance (other , np .bool_ ):
577577 other = other .item ()
578578
579- if other_is_scalar and not ( other is libmissing .NA or lib .is_bool (other ) ):
579+ if other_is_scalar and other is not libmissing .NA and not lib .is_bool (other ):
580580 raise TypeError (
581581 "'other' should be pandas.NA or a bool. "
582582 f"Got { type (other ).__name__ } instead."
0 commit comments