diff --git a/ci/code_checks.sh b/ci/code_checks.sh index e095d97146d03..4915997277006 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -81,20 +81,10 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then MSG='Partially validate docstrings (EX01)' ; echo $MSG $BASE_DIR/scripts/validate_docstrings.py --format=actions --errors=EX01 --ignore_functions \ pandas.Series.backfill \ - pandas.Series.ffill \ pandas.Series.pad \ - pandas.Series.str.center \ - pandas.Series.str.decode \ - pandas.Series.str.encode \ - pandas.Series.str.find \ - pandas.Series.str.fullmatch \ - pandas.Series.str.index \ - pandas.Series.str.ljust \ - pandas.Series.str.match \ pandas.Series.str.normalize \ pandas.Series.str.rfind \ pandas.Series.str.rindex \ - pandas.Series.str.rjust \ pandas.Series.str.translate \ pandas.Series.sparse \ pandas.DataFrame.sparse \ diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 1adc331e3cd50..90a0444872ec7 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -7167,6 +7167,16 @@ def ffill( ------- {klass} or None Object with missing values filled or None if ``inplace=True``. + + Examples + -------- + >>> ser = pd.Series([1, np.NaN, 2, 3]) + >>> ser.ffill() + 0 1.0 + 1 1.0 + 2 2.0 + 3 3.0 + dtype: float64 """ return self.fillna( method="ffill", axis=axis, inplace=inplace, limit=limit, downcast=downcast diff --git a/pandas/core/strings/accessor.py b/pandas/core/strings/accessor.py index c8430b832f782..e8769370ca88d 100644 --- a/pandas/core/strings/accessor.py +++ b/pandas/core/strings/accessor.py @@ -1293,6 +1293,15 @@ def match(self, pat, case: bool = True, flags: int = 0, na=None): contains : Analogous, but less strict, relying on re.search instead of re.match. extract : Extract matched groups. + + Examples + -------- + >>> ser = pd.Series(["horse", "eagle", "donkey"]) + >>> ser.str.match("e") + 0 False + 1 True + 2 False + dtype: bool """ result = self._data.array._str_match(pat, case=case, flags=flags, na=na) return self._wrap_result(result, fill_value=na, returns_string=False) @@ -1324,6 +1333,15 @@ def fullmatch(self, pat, case: bool = True, flags: int = 0, na=None): match : Similar, but also returns `True` when only a *prefix* of the string matches the regular expression. extract : Extract matched groups. + + Examples + -------- + >>> ser = pd.Series(["cat", "duck", "dove"]) + >>> ser.str.fullmatch(r'd.+') + 0 False + 1 True + 2 True + dtype: bool """ result = self._data.array._str_fullmatch(pat, case=case, flags=flags, na=na) return self._wrap_result(result, fill_value=na, returns_string=False) @@ -1616,6 +1634,35 @@ def pad( Returns ------- Series/Index of objects. + + Examples + -------- + For Series.str.center: + + >>> ser = pd.Series(['dog', 'bird', 'mouse']) + >>> ser.str.center(8, fillchar='.') + 0 ..dog... + 1 ..bird.. + 2 .mouse.. + dtype: object + + For Series.str.ljust: + + >>> ser = pd.Series(['dog', 'bird', 'mouse']) + >>> ser.str.ljust(8, fillchar='.') + 0 dog..... + 1 bird.... + 2 mouse... + dtype: object + + For Series.str.rjust: + + >>> ser = pd.Series(['dog', 'bird', 'mouse']) + >>> ser.str.rjust(8, fillchar='.') + 0 .....dog + 1 ....bird + 2 ...mouse + dtype: object """ @Appender(_shared_docs["str_pad"] % {"side": "left and right", "method": "center"}) @@ -1867,6 +1914,17 @@ def decode(self, encoding, errors: str = "strict"): Returns ------- Series or Index + + Examples + -------- + For Series: + + >>> ser = pd.Series([b'cow', b'123', b'()']) + >>> ser.str.decode('ascii') + 0 cow + 1 123 + 2 () + dtype: object """ # TODO: Add a similar _bytes interface. if encoding in _cpython_optimized_decoders: @@ -1895,6 +1953,15 @@ def encode(self, encoding, errors: str = "strict"): Returns ------- Series/Index of objects + + Examples + -------- + >>> ser = pd.Series(['cow', '123', '()']) + >>> ser.str.encode(encoding='ascii') + 0 b'cow' + 1 b'123' + 2 b'()' + dtype: object """ result = self._data.array._str_encode(encoding, errors) return self._wrap_result(result, returns_string=False) @@ -2730,6 +2797,15 @@ def extractall(self, pat, flags: int = 0) -> DataFrame: See Also -------- %(also)s + + Examples + -------- + >>> ser = pd.Series(["cow_", "duck_", "do_ve"]) + >>> ser.str.find("_") + 0 3 + 1 4 + 2 2 + dtype: int64 """ @Appender( @@ -2813,6 +2889,15 @@ def normalize(self, form): See Also -------- %(also)s + + Examples + -------- + >>> ser = pd.Series(["horse", "eagle", "donkey"]) + >>> ser.str.index("e") + 0 4 + 1 0 + 2 4 + dtype: int64 """ @Appender(