Skip to content

Commit 81de5aa

Browse files
DeaMariaLeonim-vinicius
authored and
im-vinicius
committed
DOC: Fixing EX01 - Added examples (pandas-dev#53499)
* Added examples Series.decode * Added more examples * Added Series.str examples
1 parent 8ecf00b commit 81de5aa

File tree

3 files changed

+95
-10
lines changed

3 files changed

+95
-10
lines changed

ci/code_checks.sh

-10
Original file line numberDiff line numberDiff line change
@@ -81,20 +81,10 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
8181
MSG='Partially validate docstrings (EX01)' ; echo $MSG
8282
$BASE_DIR/scripts/validate_docstrings.py --format=actions --errors=EX01 --ignore_functions \
8383
pandas.Series.backfill \
84-
pandas.Series.ffill \
8584
pandas.Series.pad \
86-
pandas.Series.str.center \
87-
pandas.Series.str.decode \
88-
pandas.Series.str.encode \
89-
pandas.Series.str.find \
90-
pandas.Series.str.fullmatch \
91-
pandas.Series.str.index \
92-
pandas.Series.str.ljust \
93-
pandas.Series.str.match \
9485
pandas.Series.str.normalize \
9586
pandas.Series.str.rfind \
9687
pandas.Series.str.rindex \
97-
pandas.Series.str.rjust \
9888
pandas.Series.str.translate \
9989
pandas.Series.sparse \
10090
pandas.DataFrame.sparse \

pandas/core/generic.py

+10
Original file line numberDiff line numberDiff line change
@@ -7167,6 +7167,16 @@ def ffill(
71677167
-------
71687168
{klass} or None
71697169
Object with missing values filled or None if ``inplace=True``.
7170+
7171+
Examples
7172+
--------
7173+
>>> ser = pd.Series([1, np.NaN, 2, 3])
7174+
>>> ser.ffill()
7175+
0 1.0
7176+
1 1.0
7177+
2 2.0
7178+
3 3.0
7179+
dtype: float64
71707180
"""
71717181
return self.fillna(
71727182
method="ffill", axis=axis, inplace=inplace, limit=limit, downcast=downcast

pandas/core/strings/accessor.py

+85
Original file line numberDiff line numberDiff line change
@@ -1293,6 +1293,15 @@ def match(self, pat, case: bool = True, flags: int = 0, na=None):
12931293
contains : Analogous, but less strict, relying on re.search instead of
12941294
re.match.
12951295
extract : Extract matched groups.
1296+
1297+
Examples
1298+
--------
1299+
>>> ser = pd.Series(["horse", "eagle", "donkey"])
1300+
>>> ser.str.match("e")
1301+
0 False
1302+
1 True
1303+
2 False
1304+
dtype: bool
12961305
"""
12971306
result = self._data.array._str_match(pat, case=case, flags=flags, na=na)
12981307
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):
13241333
match : Similar, but also returns `True` when only a *prefix* of the string
13251334
matches the regular expression.
13261335
extract : Extract matched groups.
1336+
1337+
Examples
1338+
--------
1339+
>>> ser = pd.Series(["cat", "duck", "dove"])
1340+
>>> ser.str.fullmatch(r'd.+')
1341+
0 False
1342+
1 True
1343+
2 True
1344+
dtype: bool
13271345
"""
13281346
result = self._data.array._str_fullmatch(pat, case=case, flags=flags, na=na)
13291347
return self._wrap_result(result, fill_value=na, returns_string=False)
@@ -1616,6 +1634,35 @@ def pad(
16161634
Returns
16171635
-------
16181636
Series/Index of objects.
1637+
1638+
Examples
1639+
--------
1640+
For Series.str.center:
1641+
1642+
>>> ser = pd.Series(['dog', 'bird', 'mouse'])
1643+
>>> ser.str.center(8, fillchar='.')
1644+
0 ..dog...
1645+
1 ..bird..
1646+
2 .mouse..
1647+
dtype: object
1648+
1649+
For Series.str.ljust:
1650+
1651+
>>> ser = pd.Series(['dog', 'bird', 'mouse'])
1652+
>>> ser.str.ljust(8, fillchar='.')
1653+
0 dog.....
1654+
1 bird....
1655+
2 mouse...
1656+
dtype: object
1657+
1658+
For Series.str.rjust:
1659+
1660+
>>> ser = pd.Series(['dog', 'bird', 'mouse'])
1661+
>>> ser.str.rjust(8, fillchar='.')
1662+
0 .....dog
1663+
1 ....bird
1664+
2 ...mouse
1665+
dtype: object
16191666
"""
16201667

16211668
@Appender(_shared_docs["str_pad"] % {"side": "left and right", "method": "center"})
@@ -1867,6 +1914,17 @@ def decode(self, encoding, errors: str = "strict"):
18671914
Returns
18681915
-------
18691916
Series or Index
1917+
1918+
Examples
1919+
--------
1920+
For Series:
1921+
1922+
>>> ser = pd.Series([b'cow', b'123', b'()'])
1923+
>>> ser.str.decode('ascii')
1924+
0 cow
1925+
1 123
1926+
2 ()
1927+
dtype: object
18701928
"""
18711929
# TODO: Add a similar _bytes interface.
18721930
if encoding in _cpython_optimized_decoders:
@@ -1895,6 +1953,15 @@ def encode(self, encoding, errors: str = "strict"):
18951953
Returns
18961954
-------
18971955
Series/Index of objects
1956+
1957+
Examples
1958+
--------
1959+
>>> ser = pd.Series(['cow', '123', '()'])
1960+
>>> ser.str.encode(encoding='ascii')
1961+
0 b'cow'
1962+
1 b'123'
1963+
2 b'()'
1964+
dtype: object
18981965
"""
18991966
result = self._data.array._str_encode(encoding, errors)
19001967
return self._wrap_result(result, returns_string=False)
@@ -2730,6 +2797,15 @@ def extractall(self, pat, flags: int = 0) -> DataFrame:
27302797
See Also
27312798
--------
27322799
%(also)s
2800+
2801+
Examples
2802+
--------
2803+
>>> ser = pd.Series(["cow_", "duck_", "do_ve"])
2804+
>>> ser.str.find("_")
2805+
0 3
2806+
1 4
2807+
2 2
2808+
dtype: int64
27332809
"""
27342810

27352811
@Appender(
@@ -2813,6 +2889,15 @@ def normalize(self, form):
28132889
See Also
28142890
--------
28152891
%(also)s
2892+
2893+
Examples
2894+
--------
2895+
>>> ser = pd.Series(["horse", "eagle", "donkey"])
2896+
>>> ser.str.index("e")
2897+
0 4
2898+
1 0
2899+
2 4
2900+
dtype: int64
28162901
"""
28172902

28182903
@Appender(

0 commit comments

Comments
 (0)