@@ -163,14 +163,22 @@ def _isna(obj, inf_as_na: bool = False):
163
163
raise NotImplementedError ("isna is not defined for MultiIndex" )
164
164
elif isinstance (obj , type ):
165
165
return False
166
- elif isinstance (obj , (ABCSeries , np .ndarray , ABCIndex , ABCExtensionArray )):
167
- return _isna_ndarraylike (obj , inf_as_na = inf_as_na )
166
+ elif isinstance (obj , (np .ndarray , ABCExtensionArray )):
167
+ return _isna_array (obj , inf_as_na = inf_as_na )
168
+ elif isinstance (obj , (ABCSeries , ABCIndex )):
169
+ result = _isna_array (obj ._values , inf_as_na = inf_as_na )
170
+ # box
171
+ if isinstance (obj , ABCSeries ):
172
+ result = obj ._constructor (
173
+ result , index = obj .index , name = obj .name , copy = False
174
+ )
175
+ return result
168
176
elif isinstance (obj , ABCDataFrame ):
169
177
return obj .isna ()
170
178
elif isinstance (obj , list ):
171
- return _isna_ndarraylike (np .asarray (obj , dtype = object ), inf_as_na = inf_as_na )
179
+ return _isna_array (np .asarray (obj , dtype = object ), inf_as_na = inf_as_na )
172
180
elif hasattr (obj , "__array__" ):
173
- return _isna_ndarraylike (np .asarray (obj ), inf_as_na = inf_as_na )
181
+ return _isna_array (np .asarray (obj ), inf_as_na = inf_as_na )
174
182
else :
175
183
return False
176
184
@@ -206,13 +214,13 @@ def _use_inf_as_na(key):
206
214
globals ()["INF_AS_NA" ] = False
207
215
208
216
209
- def _isna_ndarraylike ( obj , inf_as_na : bool = False ):
217
+ def _isna_array ( values : ArrayLike , inf_as_na : bool = False ):
210
218
"""
211
219
Return an array indicating which values of the input array are NaN / NA.
212
220
213
221
Parameters
214
222
----------
215
- obj: array-like
223
+ obj: ndarray or ExtensionArray
216
224
The input array whose elements are to be checked.
217
225
inf_as_na: bool
218
226
Whether or not to treat infinite values as NA.
@@ -222,7 +230,6 @@ def _isna_ndarraylike(obj, inf_as_na: bool = False):
222
230
array-like
223
231
Array of boolean values denoting the NA status of each element.
224
232
"""
225
- values = getattr (obj , "_values" , obj )
226
233
dtype = values .dtype
227
234
228
235
if is_extension_array_dtype (dtype ):
@@ -241,10 +248,6 @@ def _isna_ndarraylike(obj, inf_as_na: bool = False):
241
248
else :
242
249
result = np .isnan (values )
243
250
244
- # box
245
- if isinstance (obj , ABCSeries ):
246
- result = obj ._constructor (result , index = obj .index , name = obj .name , copy = False )
247
-
248
251
return result
249
252
250
253
@@ -650,7 +653,7 @@ def isna_all(arr: ArrayLike) -> bool:
650
653
checker = lambda x : np .asarray (x .view ("i8" )) == iNaT
651
654
652
655
else :
653
- checker = lambda x : _isna_ndarraylike (x , inf_as_na = INF_AS_NA )
656
+ checker = lambda x : _isna_array (x , inf_as_na = INF_AS_NA )
654
657
655
658
return all (
656
659
checker (arr [i : i + chunk_len ]).all () for i in range (0 , total_len , chunk_len )
0 commit comments