Skip to content

Commit b4dedc8

Browse files
committed
fix rsplit doc
1 parent f9762d8 commit b4dedc8

File tree

1 file changed

+44
-25
lines changed

1 file changed

+44
-25
lines changed

pandas/core/strings/accessor.py

+44-25
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ def cat(
659659
660660
Parameters
661661
----------
662-
pat : str or compiled regex, optional
662+
pat : str%(pat_regex)s, optional
663663
String or regular expression to split on.
664664
If not specified, split on whitespace.
665665
n : int, default -1 (all)
@@ -670,28 +670,12 @@ def cat(
670670
671671
- If ``True``, return DataFrame/MultiIndex expanding dimensionality.
672672
- If ``False``, return Series/Index, containing lists of strings.
673-
674-
regex : bool, default None
675-
Determines if the passed-in pattern is a regular expression:
676-
677-
- If ``True``, assumes the passed-in pattern is a regular expression
678-
- If ``False``, treats the pattern as a literal string.
679-
- If ``None`` and `pat` length is 1, treats `pat` as a literal string.
680-
- If ``None`` and `pat` length is not 1, treats `pat` as a regular expression.
681-
- Cannot be set to False if `pat` is a compiled regex
682-
683-
.. versionadded:: 1.4.0
684-
673+
%(regex_argument)s
685674
Returns
686675
-------
687676
Series, Index, DataFrame or MultiIndex
688677
Type matches caller unless ``expand=True`` (see Notes).
689-
690-
Raises
691-
------
692-
ValueError
693-
* if `regex` is False and `pat` is a compiled regex
694-
678+
%(raises_split)s
695679
See Also
696680
--------
697681
Series.str.split : Split strings around given separator/delimiter.
@@ -713,10 +697,7 @@ def cat(
713697
714698
If using ``expand=True``, Series and Index callers return DataFrame and
715699
MultiIndex objects, respectively.
716-
717-
Use of `regex=False` with a `pat` as a compiled regex will raise
718-
an error.
719-
700+
%(regex_pat_note)s
720701
Examples
721702
--------
722703
>>> s = pd.Series(
@@ -831,7 +812,35 @@ def cat(
831812
0 foojpgbar.jpg
832813
"""
833814

834-
@Appender(_shared_docs["str_split"] % {"side": "beginning", "method": "split"})
815+
@Appender(
816+
_shared_docs["str_split"]
817+
% {
818+
"side": "beginning",
819+
"pat_regex": " or compiled regex",
820+
"regex_argument": """
821+
regex : bool, default None
822+
Determines if the passed-in pattern is a regular expression:
823+
824+
- If ``True``, assumes the passed-in pattern is a regular expression
825+
- If ``False``, treats the pattern as a literal string.
826+
- If ``None`` and `pat` length is 1, treats `pat` as a literal string.
827+
- If ``None`` and `pat` length is not 1, treats `pat` as a regular expression.
828+
- Cannot be set to False if `pat` is a compiled regex
829+
830+
.. versionadded:: 1.4.0
831+
""",
832+
"raises_split": """
833+
Raises
834+
------
835+
ValueError
836+
* if `regex` is False and `pat` is a compiled regex
837+
""",
838+
"regex_pat_note": """
839+
Use of `regex =False` with a `pat` as a compiled regex will raise an error.
840+
""",
841+
"method": "split",
842+
}
843+
)
835844
@forbid_nonstring_types(["bytes"])
836845
def split(
837846
self,
@@ -850,7 +859,17 @@ def split(
850859
result = self._data.array._str_split(pat, n, expand, regex)
851860
return self._wrap_result(result, returns_string=expand, expand=expand)
852861

853-
@Appender(_shared_docs["str_split"] % {"side": "end", "method": "rsplit"})
862+
@Appender(
863+
_shared_docs["str_split"]
864+
% {
865+
"side": "end",
866+
"pat_regex": "",
867+
"regex_argument": "",
868+
"raises_split": "",
869+
"regex_pat_note": "",
870+
"method": "rsplit",
871+
}
872+
)
854873
@forbid_nonstring_types(["bytes"])
855874
def rsplit(self, pat=None, n=-1, expand=False):
856875
result = self._data.array._str_rsplit(pat, n=n)

0 commit comments

Comments
 (0)