From c2aa182e4557a2418ff3ffa5d9dc5adb4ee21972 Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Sat, 26 Jul 2025 11:01:00 +0200 Subject: [PATCH] DOC: update .str.contains/match/startswith docstring examples for default behaviour --- pandas/core/strings/accessor.py | 60 +++++++++------------------------ 1 file changed, 15 insertions(+), 45 deletions(-) diff --git a/pandas/core/strings/accessor.py b/pandas/core/strings/accessor.py index 14dadd9b41772..c108808905dc7 100644 --- a/pandas/core/strings/accessor.py +++ b/pandas/core/strings/accessor.py @@ -1242,9 +1242,9 @@ def contains( Flags to pass through to the re module, e.g. re.IGNORECASE. na : scalar, optional Fill value for missing values. The default depends on dtype of the - array. For object-dtype, ``numpy.nan`` is used. For the nullable - ``StringDtype``, ``pandas.NA`` is used. For the ``"str"`` dtype, - ``False`` is used. + array. For the ``"str"`` dtype, ``False`` is used. For object + dtype, ``numpy.nan`` is used. For the nullable ``StringDtype``, + ``pandas.NA`` is used. regex : bool, default True If True, assumes the pat is a regular expression. @@ -1293,18 +1293,6 @@ def contains( 4 False dtype: bool - Specifying `na` to be `False` instead of `NaN` replaces NaN values - with `False`. If Series or Index does not contain NaN values - the resultant dtype will be `bool`, otherwise, an `object` dtype. - - >>> s1.str.contains("og", na=False, regex=True) - 0 False - 1 True - 2 False - 3 False - 4 False - dtype: bool - Returning 'house' or 'dog' when either expression occurs in a string. >>> 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): Regex module flags, e.g. re.IGNORECASE. na : scalar, optional Fill value for missing values. The default depends on dtype of the - array. For object-dtype, ``numpy.nan`` is used. For the nullable - ``StringDtype``, ``pandas.NA`` is used. For the ``"str"`` dtype, - ``False`` is used. + array. For the ``"str"`` dtype, ``False`` is used. For object + dtype, ``numpy.nan`` is used. For the nullable ``StringDtype``, + ``pandas.NA`` is used. Returns ------- @@ -1431,9 +1419,9 @@ def fullmatch(self, pat, case: bool = True, flags: int = 0, na=lib.no_default): Regex module flags, e.g. re.IGNORECASE. na : scalar, optional Fill value for missing values. The default depends on dtype of the - array. For object-dtype, ``numpy.nan`` is used. For the nullable - ``StringDtype``, ``pandas.NA`` is used. For the ``"str"`` dtype, - ``False`` is used. + array. For the ``"str"`` dtype, ``False`` is used. For object + dtype, ``numpy.nan`` is used. For the nullable ``StringDtype``, + ``pandas.NA`` is used. Returns ------- @@ -2671,9 +2659,9 @@ def startswith( accepted. na : scalar, optional Object shown if element tested is not a string. The default depends - on dtype of the array. For object-dtype, ``numpy.nan`` is used. - For the nullable ``StringDtype``, ``pandas.NA`` is used. - For the ``"str"`` dtype, ``False`` is used. + on dtype of the array. For the ``"str"`` dtype, ``False`` is used. + For object dtype, ``numpy.nan`` is used. For the nullable + ``StringDtype``, ``pandas.NA`` is used. Returns ------- @@ -2710,15 +2698,6 @@ def startswith( 2 False 3 False dtype: bool - - Specifying `na` to be `False` instead of `NaN`. - - >>> s.str.startswith("b", na=False) - 0 True - 1 False - 2 False - 3 False - dtype: bool """ if not isinstance(pat, (str, tuple)): msg = f"expected a string or tuple, not {type(pat).__name__}" @@ -2742,9 +2721,9 @@ def endswith( accepted. na : scalar, optional Object shown if element tested is not a string. The default depends - on dtype of the array. For object-dtype, ``numpy.nan`` is used. - For the nullable ``StringDtype``, ``pandas.NA`` is used. - For the ``"str"`` dtype, ``False`` is used. + on dtype of the array. For the ``"str"`` dtype, ``False`` is used. + For object dtype, ``numpy.nan`` is used. For the nullable + ``StringDtype``, ``pandas.NA`` is used. Returns ------- @@ -2781,15 +2760,6 @@ def endswith( 2 True 3 False dtype: bool - - Specifying `na` to be `False` instead of `NaN`. - - >>> s.str.endswith("t", na=False) - 0 True - 1 False - 2 False - 3 False - dtype: bool """ if not isinstance(pat, (str, tuple)): msg = f"expected a string or tuple, not {type(pat).__name__}"