diff --git a/pandas/core/base.py b/pandas/core/base.py index 4b147dc619692..be9e65d40cd8b 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -317,6 +317,21 @@ def transpose(self: _T, *args, **kwargs) -> _T: def shape(self) -> Shape: """ Return a tuple of the shape of the underlying data. + + Returns + -------- + tuple + Shape of the Series. + + See Also + -------- + Series.size : Returns the size of the Series as an int. + + Examples + -------- + >>> s = pd.Series(['Cat', 'Dog', 'Cow', 'Zebra', 'Monkey']) + >>> s.shape + (5,) """ return self._values.shape @@ -360,6 +375,21 @@ def nbytes(self) -> int: def size(self) -> int: """ Return the number of elements in the underlying data. + + Returns + -------- + int + Size of the array. + + See Also + -------- + Series.shape : Returns the shape of the Series as a tuple. + + Examples + -------- + >>> s = pd.Series(['Cat', 'Dog', 'Cow', 'Zebra', 'Monkey']) + >>> s.size + 5 """ return len(self._values) @@ -771,6 +801,17 @@ def hasnans(self) -> bool: Return True if there are any NaNs. Enables various performance speedups. + + Returns + -------- + bool + Whether the Series contains a NaN. + + Examples + -------- + >> s = pd.Series([0, 1, np.nan, 3, 4]) + >> s.hasnans + True """ # error: Item "bool" of "Union[bool, ndarray[Any, dtype[bool_]], NDFrame]" # has no attribute "any" diff --git a/pandas/core/series.py b/pandas/core/series.py index 2987858492a25..0d05384bc10b6 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -573,6 +573,21 @@ def _can_hold_na(self) -> bool: def dtype(self) -> DtypeObj: """ Return the dtype object of the underlying data. + + Returns + -------- + dtype + dtype of the underlying data. + + See Also + -------- + Series.dtypes : Returns the dtype object of the underlying data. + + Examples + -------- + >> s = pd.Series([0, 1, 2, 3, 4]) + >> s.dtype + dtype('int64') """ return self._mgr.dtype @@ -580,6 +595,22 @@ def dtype(self) -> DtypeObj: def dtypes(self) -> DtypeObj: """ Return the dtype object of the underlying data. + + Returns + -------- + dtype + dtype of the underlying data. + + See Also + -------- + Series.dtype : Returns the dtype object of the underlying data, normally used + for DataFrames. + + Examples + -------- + >> s = pd.Series([0, 1, 2, 3, 4]) + >> s.dtypes + dtype('int64') """ # DataFrame compatibility return self.dtype