@@ -659,8 +659,8 @@ def cat(
659
659
660
660
Parameters
661
661
----------
662
- pat : str or compiled regex , optional
663
- String or regular expression to split on .
662
+ pat : str%(pat_regex)s , optional
663
+ %(pat_description)s .
664
664
If not specified, split on whitespace.
665
665
n : int, default -1 (all)
666
666
Limit number of splits in output.
@@ -670,28 +670,12 @@ def cat(
670
670
671
671
- If ``True``, return DataFrame/MultiIndex expanding dimensionality.
672
672
- 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
685
674
Returns
686
675
-------
687
676
Series, Index, DataFrame or MultiIndex
688
677
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
695
679
See Also
696
680
--------
697
681
Series.str.split : Split strings around given separator/delimiter.
@@ -713,10 +697,7 @@ def cat(
713
697
714
698
If using ``expand=True``, Series and Index callers return DataFrame and
715
699
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
720
701
Examples
721
702
--------
722
703
>>> s = pd.Series(
@@ -790,7 +771,37 @@ def cat(
790
771
0 this is a regular sentence None
791
772
1 https://docs.python.org/3/tutorial index.html
792
773
2 NaN NaN
774
+ %(regex_examples)s"""
775
+
776
+ @Appender (
777
+ _shared_docs ["str_split" ]
778
+ % {
779
+ "side" : "beginning" ,
780
+ "pat_regex" : " or compiled regex" ,
781
+ "pat_description" : "String or regular expression to split on" ,
782
+ "regex_argument" : """
783
+ regex : bool, default None
784
+ Determines if the passed-in pattern is a regular expression:
785
+
786
+ - If ``True``, assumes the passed-in pattern is a regular expression
787
+ - If ``False``, treats the pattern as a literal string.
788
+ - If ``None`` and `pat` length is 1, treats `pat` as a literal string.
789
+ - If ``None`` and `pat` length is not 1, treats `pat` as a regular expression.
790
+ - Cannot be set to False if `pat` is a compiled regex
793
791
792
+ .. versionadded:: 1.4.0
793
+ """ ,
794
+ "raises_split" : """
795
+ Raises
796
+ ------
797
+ ValueError
798
+ * if `regex` is False and `pat` is a compiled regex
799
+ """ ,
800
+ "regex_pat_note" : """
801
+ Use of `regex =False` with a `pat` as a compiled regex will raise an error.
802
+ """ ,
803
+ "method" : "split" ,
804
+ "regex_examples" : r"""
794
805
Remember to escape special characters when explicitly using regular expressions.
795
806
796
807
>>> s = pd.Series(["foo and bar plus baz"])
@@ -829,9 +840,9 @@ def cat(
829
840
>>> s.str.split(r"\.jpg", regex=False, expand=True)
830
841
0
831
842
0 foojpgbar.jpg
832
- """
833
-
834
- @ Appender ( _shared_docs [ "str_split" ] % { "side" : "beginning" , "method" : "split" } )
843
+ """ ,
844
+ }
845
+ )
835
846
@forbid_nonstring_types (["bytes" ])
836
847
def split (
837
848
self ,
@@ -850,7 +861,19 @@ def split(
850
861
result = self ._data .array ._str_split (pat , n , expand , regex )
851
862
return self ._wrap_result (result , returns_string = expand , expand = expand )
852
863
853
- @Appender (_shared_docs ["str_split" ] % {"side" : "end" , "method" : "rsplit" })
864
+ @Appender (
865
+ _shared_docs ["str_split" ]
866
+ % {
867
+ "side" : "end" ,
868
+ "pat_regex" : "" ,
869
+ "pat_description" : "String to split on" ,
870
+ "regex_argument" : "" ,
871
+ "raises_split" : "" ,
872
+ "regex_pat_note" : "" ,
873
+ "method" : "rsplit" ,
874
+ "regex_examples" : "" ,
875
+ }
876
+ )
854
877
@forbid_nonstring_types (["bytes" ])
855
878
def rsplit (self , pat = None , n = - 1 , expand = False ):
856
879
result = self ._data .array ._str_rsplit (pat , n = n )
0 commit comments