|
29 | 29 |
|
30 | 30 |
|
31 | 31 | def isna(obj):
|
32 |
| - """Detect missing values (NaN in numeric arrays, None/NaN in object arrays) |
| 32 | + """ |
| 33 | + Detect missing values for an array-like object. |
| 34 | +
|
| 35 | + This function takes a scalar or array-like object and indictates |
| 36 | + whether values are missing (``NaN`` in numeric arrays, ``None`` or ``NaN`` |
| 37 | + in object arrays, ``NaT`` in datetimelike). |
33 | 38 |
|
34 | 39 | Parameters
|
35 | 40 | ----------
|
36 |
| - arr : ndarray or object value |
37 |
| - Object to check for null-ness |
| 41 | + obj : scalar or array-like |
| 42 | + Object to check for null or missing values. |
38 | 43 |
|
39 | 44 | Returns
|
40 | 45 | -------
|
41 |
| - isna : array-like of bool or bool |
42 |
| - Array or bool indicating whether an object is null or if an array is |
43 |
| - given which of the element is null. |
| 46 | + bool or array-like of bool |
| 47 | + For scalar input, returns a scalar boolean. |
| 48 | + For array input, returns an array of boolean indicating whether each |
| 49 | + corresponding element is missing. |
44 | 50 |
|
45 |
| - See also |
| 51 | + See Also |
| 52 | + -------- |
| 53 | + notna : boolean inverse of pandas.isna. |
| 54 | + Series.isna : Detetct missing values in a Series. |
| 55 | + DataFrame.isna : Detect missing values in a DataFrame. |
| 56 | + Index.isna : Detect missing values in an Index. |
| 57 | +
|
| 58 | + Examples |
46 | 59 | --------
|
47 |
| - pandas.notna: boolean inverse of pandas.isna |
48 |
| - pandas.isnull: alias of isna |
| 60 | + Scalar arguments (including strings) result in a scalar boolean. |
| 61 | +
|
| 62 | + >>> pd.isna('dog') |
| 63 | + False |
| 64 | +
|
| 65 | + >>> pd.isna(np.nan) |
| 66 | + True |
| 67 | +
|
| 68 | + ndarrays result in an ndarray of booleans. |
| 69 | +
|
| 70 | + >>> array = np.array([[1, np.nan, 3], [4, 5, np.nan]]) |
| 71 | + >>> array |
| 72 | + array([[ 1., nan, 3.], |
| 73 | + [ 4., 5., nan]]) |
| 74 | + >>> pd.isna(array) |
| 75 | + array([[False, True, False], |
| 76 | + [False, False, True]]) |
| 77 | +
|
| 78 | + For indexes, an ndarray of booleans is returned. |
| 79 | +
|
| 80 | + >>> index = pd.DatetimeIndex(["2017-07-05", "2017-07-06", None, |
| 81 | + ... "2017-07-08"]) |
| 82 | + >>> index |
| 83 | + DatetimeIndex(['2017-07-05', '2017-07-06', 'NaT', '2017-07-08'], |
| 84 | + dtype='datetime64[ns]', freq=None) |
| 85 | + >>> pd.isna(index) |
| 86 | + array([False, False, True, False]) |
| 87 | +
|
| 88 | + For Series and DataFrame, the same type is returned, containing booleans. |
| 89 | +
|
| 90 | + >>> df = pd.DataFrame([['ant', 'bee', 'cat'], ['dog', None, 'fly']]) |
| 91 | + >>> df |
| 92 | + 0 1 2 |
| 93 | + 0 ant bee cat |
| 94 | + 1 dog None fly |
| 95 | + >>> pd.isna(df) |
| 96 | + 0 1 2 |
| 97 | + 0 False False False |
| 98 | + 1 False True False |
| 99 | +
|
| 100 | + >>> pd.isna(df[1]) |
| 101 | + 0 False |
| 102 | + 1 True |
| 103 | + Name: 1, dtype: bool |
49 | 104 | """
|
50 | 105 | return _isna(obj)
|
51 | 106 |
|
@@ -197,24 +252,78 @@ def _isna_ndarraylike_old(obj):
|
197 | 252 |
|
198 | 253 |
|
199 | 254 | def notna(obj):
|
200 |
| - """Replacement for numpy.isfinite / -numpy.isnan which is suitable for use |
201 |
| - on object arrays. |
| 255 | + """ |
| 256 | + Detect non-missing values for an array-like object. |
| 257 | +
|
| 258 | + This function takes a scalar or array-like object and indictates |
| 259 | + whether values are valid (not missing, which is ``NaN`` in numeric |
| 260 | + arrays, ``None`` or ``NaN`` in object arrays, ``NaT`` in datetimelike). |
202 | 261 |
|
203 | 262 | Parameters
|
204 | 263 | ----------
|
205 |
| - arr : ndarray or object value |
206 |
| - Object to check for *not*-null-ness |
| 264 | + obj : array-like or object value |
| 265 | + Object to check for *not* null or *non*-missing values. |
207 | 266 |
|
208 | 267 | Returns
|
209 | 268 | -------
|
210 |
| - notisna : array-like of bool or bool |
211 |
| - Array or bool indicating whether an object is *not* null or if an array |
212 |
| - is given which of the element is *not* null. |
| 269 | + bool or array-like of bool |
| 270 | + For scalar input, returns a scalar boolean. |
| 271 | + For array input, returns an array of boolean indicating whether each |
| 272 | + corresponding element is valid. |
213 | 273 |
|
214 |
| - See also |
| 274 | + See Also |
| 275 | + -------- |
| 276 | + isna : boolean inverse of pandas.notna. |
| 277 | + Series.notna : Detetct valid values in a Series. |
| 278 | + DataFrame.notna : Detect valid values in a DataFrame. |
| 279 | + Index.notna : Detect valid values in an Index. |
| 280 | +
|
| 281 | + Examples |
215 | 282 | --------
|
216 |
| - pandas.isna : boolean inverse of pandas.notna |
217 |
| - pandas.notnull : alias of notna |
| 283 | + Scalar arguments (including strings) result in a scalar boolean. |
| 284 | +
|
| 285 | + >>> pd.notna('dog') |
| 286 | + True |
| 287 | +
|
| 288 | + >>> pd.notna(np.nan) |
| 289 | + False |
| 290 | +
|
| 291 | + ndarrays result in an ndarray of booleans. |
| 292 | +
|
| 293 | + >>> array = np.array([[1, np.nan, 3], [4, 5, np.nan]]) |
| 294 | + >>> array |
| 295 | + array([[ 1., nan, 3.], |
| 296 | + [ 4., 5., nan]]) |
| 297 | + >>> pd.notna(array) |
| 298 | + array([[ True, False, True], |
| 299 | + [ True, True, False]]) |
| 300 | +
|
| 301 | + For indexes, an ndarray of booleans is returned. |
| 302 | +
|
| 303 | + >>> index = pd.DatetimeIndex(["2017-07-05", "2017-07-06", None, |
| 304 | + ... "2017-07-08"]) |
| 305 | + >>> index |
| 306 | + DatetimeIndex(['2017-07-05', '2017-07-06', 'NaT', '2017-07-08'], |
| 307 | + dtype='datetime64[ns]', freq=None) |
| 308 | + >>> pd.notna(index) |
| 309 | + array([ True, True, False, True]) |
| 310 | +
|
| 311 | + For Series and DataFrame, the same type is returned, containing booleans. |
| 312 | +
|
| 313 | + >>> df = pd.DataFrame([['ant', 'bee', 'cat'], ['dog', None, 'fly']]) |
| 314 | + >>> df |
| 315 | + 0 1 2 |
| 316 | + 0 ant bee cat |
| 317 | + 1 dog None fly |
| 318 | + >>> pd.notna(df) |
| 319 | + 0 1 2 |
| 320 | + 0 True True True |
| 321 | + 1 True False True |
| 322 | +
|
| 323 | + >>> pd.notna(df[1]) |
| 324 | + 0 True |
| 325 | + 1 False |
| 326 | + Name: 1, dtype: bool |
218 | 327 | """
|
219 | 328 | res = isna(obj)
|
220 | 329 | if is_scalar(res):
|
|
0 commit comments