@@ -170,12 +170,13 @@ def coerce_to_array(
170
170
values [~ mask_values ] = values_object [~ mask_values ].astype (bool )
171
171
172
172
# 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 (
175
175
values [~ mask_values ].astype (float )
176
176
== 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" )
179
180
180
181
if mask is None and mask_values is None :
181
182
mask = np .zeros (len (values ), dtype = bool )
@@ -193,9 +194,9 @@ def coerce_to_array(
193
194
if mask_values is not None :
194
195
mask = mask | mask_values
195
196
196
- if not values .ndim = = 1 :
197
+ if values .ndim ! = 1 :
197
198
raise ValueError ("values must be a 1D list-like" )
198
- if not mask .ndim = = 1 :
199
+ if mask .ndim ! = 1 :
199
200
raise ValueError ("mask must be a 1D list-like" )
200
201
201
202
return values , mask
@@ -395,9 +396,8 @@ def astype(self, dtype, copy: bool = True) -> ArrayLike:
395
396
self ._data .astype (dtype .numpy_dtype ), self ._mask .copy (), copy = False
396
397
)
397
398
# 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" )
401
401
# for float dtype, ensure we use np.nan before casting (numpy cannot
402
402
# deal with pd.NA)
403
403
na_value = self ._na_value
@@ -576,7 +576,7 @@ def _logical_method(self, other, op):
576
576
elif isinstance (other , np .bool_ ):
577
577
other = other .item ()
578
578
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 ):
580
580
raise TypeError (
581
581
"'other' should be pandas.NA or a bool. "
582
582
f"Got { type (other ).__name__ } instead."
0 commit comments