Skip to content

Commit 5e2fcb9

Browse files
DOC: update .str.contains/match/startswith docstring examples for default behaviour (#61960)
1 parent 8759c5d commit 5e2fcb9

File tree

1 file changed

+15
-45
lines changed

1 file changed

+15
-45
lines changed

pandas/core/strings/accessor.py

Lines changed: 15 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,9 +1242,9 @@ def contains(
12421242
Flags to pass through to the re module, e.g. re.IGNORECASE.
12431243
na : scalar, optional
12441244
Fill value for missing values. The default depends on dtype of the
1245-
array. For object-dtype, ``numpy.nan`` is used. For the nullable
1246-
``StringDtype``, ``pandas.NA`` is used. For the ``"str"`` dtype,
1247-
``False`` is used.
1245+
array. For the ``"str"`` dtype, ``False`` is used. For object
1246+
dtype, ``numpy.nan`` is used. For the nullable ``StringDtype``,
1247+
``pandas.NA`` is used.
12481248
regex : bool, default True
12491249
If True, assumes the pat is a regular expression.
12501250
@@ -1293,18 +1293,6 @@ def contains(
12931293
4 False
12941294
dtype: bool
12951295
1296-
Specifying `na` to be `False` instead of `NaN` replaces NaN values
1297-
with `False`. If Series or Index does not contain NaN values
1298-
the resultant dtype will be `bool`, otherwise, an `object` dtype.
1299-
1300-
>>> s1.str.contains("og", na=False, regex=True)
1301-
0 False
1302-
1 True
1303-
2 False
1304-
3 False
1305-
4 False
1306-
dtype: bool
1307-
13081296
Returning 'house' or 'dog' when either expression occurs in a string.
13091297
13101298
>>> s1.str.contains("house|dog", regex=True)
@@ -1381,9 +1369,9 @@ def match(self, pat: str, case: bool = True, flags: int = 0, na=lib.no_default):
13811369
Regex module flags, e.g. re.IGNORECASE.
13821370
na : scalar, optional
13831371
Fill value for missing values. The default depends on dtype of the
1384-
array. For object-dtype, ``numpy.nan`` is used. For the nullable
1385-
``StringDtype``, ``pandas.NA`` is used. For the ``"str"`` dtype,
1386-
``False`` is used.
1372+
array. For the ``"str"`` dtype, ``False`` is used. For object
1373+
dtype, ``numpy.nan`` is used. For the nullable ``StringDtype``,
1374+
``pandas.NA`` is used.
13871375
13881376
Returns
13891377
-------
@@ -1431,9 +1419,9 @@ def fullmatch(self, pat, case: bool = True, flags: int = 0, na=lib.no_default):
14311419
Regex module flags, e.g. re.IGNORECASE.
14321420
na : scalar, optional
14331421
Fill value for missing values. The default depends on dtype of the
1434-
array. For object-dtype, ``numpy.nan`` is used. For the nullable
1435-
``StringDtype``, ``pandas.NA`` is used. For the ``"str"`` dtype,
1436-
``False`` is used.
1422+
array. For the ``"str"`` dtype, ``False`` is used. For object
1423+
dtype, ``numpy.nan`` is used. For the nullable ``StringDtype``,
1424+
``pandas.NA`` is used.
14371425
14381426
Returns
14391427
-------
@@ -2671,9 +2659,9 @@ def startswith(
26712659
accepted.
26722660
na : scalar, optional
26732661
Object shown if element tested is not a string. The default depends
2674-
on dtype of the array. For object-dtype, ``numpy.nan`` is used.
2675-
For the nullable ``StringDtype``, ``pandas.NA`` is used.
2676-
For the ``"str"`` dtype, ``False`` is used.
2662+
on dtype of the array. For the ``"str"`` dtype, ``False`` is used.
2663+
For object dtype, ``numpy.nan`` is used. For the nullable
2664+
``StringDtype``, ``pandas.NA`` is used.
26772665
26782666
Returns
26792667
-------
@@ -2710,15 +2698,6 @@ def startswith(
27102698
2 False
27112699
3 False
27122700
dtype: bool
2713-
2714-
Specifying `na` to be `False` instead of `NaN`.
2715-
2716-
>>> s.str.startswith("b", na=False)
2717-
0 True
2718-
1 False
2719-
2 False
2720-
3 False
2721-
dtype: bool
27222701
"""
27232702
if not isinstance(pat, (str, tuple)):
27242703
msg = f"expected a string or tuple, not {type(pat).__name__}"
@@ -2742,9 +2721,9 @@ def endswith(
27422721
accepted.
27432722
na : scalar, optional
27442723
Object shown if element tested is not a string. The default depends
2745-
on dtype of the array. For object-dtype, ``numpy.nan`` is used.
2746-
For the nullable ``StringDtype``, ``pandas.NA`` is used.
2747-
For the ``"str"`` dtype, ``False`` is used.
2724+
on dtype of the array. For the ``"str"`` dtype, ``False`` is used.
2725+
For object dtype, ``numpy.nan`` is used. For the nullable
2726+
``StringDtype``, ``pandas.NA`` is used.
27482727
27492728
Returns
27502729
-------
@@ -2781,15 +2760,6 @@ def endswith(
27812760
2 True
27822761
3 False
27832762
dtype: bool
2784-
2785-
Specifying `na` to be `False` instead of `NaN`.
2786-
2787-
>>> s.str.endswith("t", na=False)
2788-
0 True
2789-
1 False
2790-
2 False
2791-
3 False
2792-
dtype: bool
27932763
"""
27942764
if not isinstance(pat, (str, tuple)):
27952765
msg = f"expected a string or tuple, not {type(pat).__name__}"

0 commit comments

Comments
 (0)