Skip to content

Commit b45290a

Browse files
committed
fix rsplit doc
1 parent f9762d8 commit b45290a

File tree

1 file changed

+43
-19
lines changed

1 file changed

+43
-19
lines changed

pandas/core/strings/accessor.py

+43-19
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)
@@ -671,26 +671,14 @@ def cat(
671671
- If ``True``, return DataFrame/MultiIndex expanding dimensionality.
672672
- If ``False``, return Series/Index, containing lists of strings.
673673
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
674+
%(regex_argument)s
684675
685676
Returns
686677
-------
687678
Series, Index, DataFrame or MultiIndex
688679
Type matches caller unless ``expand=True`` (see Notes).
689680
690-
Raises
691-
------
692-
ValueError
693-
* if `regex` is False and `pat` is a compiled regex
681+
%(raises_split)s
694682
695683
See Also
696684
--------
@@ -714,8 +702,7 @@ def cat(
714702
If using ``expand=True``, Series and Index callers return DataFrame and
715703
MultiIndex objects, respectively.
716704
717-
Use of `regex=False` with a `pat` as a compiled regex will raise
718-
an error.
705+
%(regex_pat_note)s
719706
720707
Examples
721708
--------
@@ -831,7 +818,34 @@ def cat(
831818
0 foojpgbar.jpg
832819
"""
833820

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

853-
@Appender(_shared_docs["str_split"] % {"side": "end", "method": "rsplit"})
867+
@Appender(
868+
_shared_docs["str_split"]
869+
% {
870+
"side": "end",
871+
"pat_regex": "",
872+
"regex_argument": "",
873+
"raises_split": "",
874+
"regex_pat_note": "",
875+
"method": "rsplit",
876+
}
877+
)
854878
@forbid_nonstring_types(["bytes"])
855879
def rsplit(self, pat=None, n=-1, expand=False):
856880
result = self._data.array._str_rsplit(pat, n=n)

0 commit comments

Comments
 (0)