diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 43078ef3a263c..aea7a2231582a 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -8156,7 +8156,6 @@ def asof(self, where, subset=None): # ---------------------------------------------------------------------- # Action Methods - @doc(klass=_shared_doc_kwargs["klass"]) def isna(self) -> Self: """ Detect missing values. @@ -8169,15 +8168,18 @@ def isna(self) -> Self: Returns ------- - {klass} - Mask of bool values for each element in {klass} that - indicates whether an element is an NA value. + Series/DataFrame + Mask of bool values for each element in Series/DataFrame + that indicates whether an element is an NA value. See Also -------- - {klass}.isnull : Alias of isna. - {klass}.notna : Boolean inverse of isna. - {klass}.dropna : Omit axes labels with missing values. + Series.isnull : Alias of isna. + DataFrame.isnull : Alias of isna. + Series.notna : Boolean inverse of isna. + DataFrame.notna : Boolean inverse of isna. + Series.dropna : Omit axes labels with missing values. + DataFrame.dropna : Omit axes labels with missing values. isna : Top-level isna. Examples @@ -8225,11 +8227,77 @@ def isna(self) -> Self: """ return isna(self).__finalize__(self, method="isna") - @doc(isna, klass=_shared_doc_kwargs["klass"]) def isnull(self) -> Self: + """ + Detect missing values. + + Return a boolean same-sized object indicating if the values are NA. + NA values, such as None or :attr:`numpy.NaN`, gets mapped to True + values. + Everything else gets mapped to False values. Characters such as empty + strings ``''`` or :attr:`numpy.inf` are not considered NA values. + + Returns + ------- + Series/DataFrame + Mask of bool values for each element in Series/DataFrame + that indicates whether an element is an NA value. + + See Also + -------- + Series.isna : Alias of isnull. + DataFrame.isna : Alias of isnull. + Series.notna : Boolean inverse of isnull. + DataFrame.notna : Boolean inverse of isnull. + Series.dropna : Omit axes labels with missing values. + DataFrame.dropna : Omit axes labels with missing values. + isna : Top-level isna. + + Examples + -------- + Show which entries in a DataFrame are NA. + + >>> df = pd.DataFrame( + ... dict( + ... age=[5, 6, np.nan], + ... born=[ + ... pd.NaT, + ... pd.Timestamp("1939-05-27"), + ... pd.Timestamp("1940-04-25"), + ... ], + ... name=["Alfred", "Batman", ""], + ... toy=[None, "Batmobile", "Joker"], + ... ) + ... ) + >>> df + age born name toy + 0 5.0 NaT Alfred NaN + 1 6.0 1939-05-27 Batman Batmobile + 2 NaN 1940-04-25 Joker + + >>> df.isna() + age born name toy + 0 False True False True + 1 False False False False + 2 True False False False + + Show which entries in a Series are NA. + + >>> ser = pd.Series([5, 6, np.nan]) + >>> ser + 0 5.0 + 1 6.0 + 2 NaN + dtype: float64 + + >>> ser.isna() + 0 False + 1 False + 2 True + dtype: bool + """ return isna(self).__finalize__(self, method="isnull") - @doc(klass=_shared_doc_kwargs["klass"]) def notna(self) -> Self: """ Detect existing (non-missing) values. @@ -8242,15 +8310,18 @@ def notna(self) -> Self: Returns ------- - {klass} - Mask of bool values for each element in {klass} that - indicates whether an element is not an NA value. + Series/DataFrame + Mask of bool values for each element in Series/DataFrame + that indicates whether an element is not an NA value. See Also -------- - {klass}.notnull : Alias of notna. - {klass}.isna : Boolean inverse of notna. - {klass}.dropna : Omit axes labels with missing values. + Series.notnull : Alias of notna. + DataFrame.notnull : Alias of notna. + Series.isna : Boolean inverse of notna. + DataFrame.isna : Boolean inverse of notna. + Series.dropna : Omit axes labels with missing values. + DataFrame.dropna : Omit axes labels with missing values. notna : Top-level notna. Examples diff --git a/pandas/core/series.py b/pandas/core/series.py index 1f027b722b3d9..fe71a3ab91933 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -6183,7 +6183,7 @@ def isna(self) -> Series: return NDFrame.isna(self) # error: Cannot determine type of 'isna' - @doc(NDFrame.isna, klass=_shared_doc_kwargs["klass"]) # type: ignore[has-type] + @doc(NDFrame.isna, klass=_shared_doc_kwargs["klass"]) def isnull(self) -> Series: """ Series.isnull is an alias for Series.isna. @@ -6260,7 +6260,7 @@ def notna(self) -> Series: return super().notna() # error: Cannot determine type of 'notna' - @doc(NDFrame.notna, klass=_shared_doc_kwargs["klass"]) # type: ignore[has-type] + @doc(NDFrame.notna, klass=_shared_doc_kwargs["klass"]) def notnull(self) -> Series: """ Series.notnull is an alias for Series.notna.