Skip to content

Commit 4b92d03

Browse files
committed
Deleted str_split/str_rsplit docstring and simplified shared docstring
1 parent 6535292 commit 4b92d03

File tree

1 file changed

+36
-83
lines changed

1 file changed

+36
-83
lines changed

pandas/core/strings.py

Lines changed: 36 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,24 +1343,7 @@ def str_pad(arr, width, side='left', fillchar=' '):
13431343

13441344

13451345
def str_split(arr, pat=None, n=None):
1346-
"""
1347-
Split strings around given separator/delimiter.
1348-
1349-
Parameters
1350-
----------
1351-
pat : str, optional
1352-
String or regular expression to split on; If not specified,
1353-
split on whitespace.
1354-
n : int, default -1 (all)
1355-
Limit number of splits in output; ``None``, 0 and -1 will
1356-
be interpreted as return all splits.
1357-
expand : bool, default False
1358-
Expand the splitted strings into separate columns.
1359-
1360-
Returns
1361-
-------
1362-
Series, Index, DataFrame or MultiIndex
1363-
"""
1346+
13641347
if pat is None:
13651348
if n is None or n == 0:
13661349
n = -1
@@ -1380,24 +1363,7 @@ def str_split(arr, pat=None, n=None):
13801363

13811364

13821365
def str_rsplit(arr, pat=None, n=None):
1383-
"""
1384-
Split strings around given separator/delimiter (starting from
1385-
the right).
1386-
1387-
Parameters
1388-
----------
1389-
pat : string, default None
1390-
Separator to split on; If None, splits on whitespace.
1391-
n : int, default -1 (all)
1392-
None, 0 and -1 will be interpreted as return all splits.
1393-
expand : bool, default False
1394-
If True, return DataFrame/MultiIndex expanding dimensionality.
1395-
If False, return Series/Index.
1396-
1397-
Returns
1398-
-------
1399-
Series/Index or DataFrame/MultiIndex of objects
1400-
"""
1366+
14011367
if n is None or n == 0:
14021368
n = -1
14031369
f = lambda x: x.rsplit(pat, n)
@@ -2279,33 +2245,36 @@ def cat(self, others=None, sep=None, na_rep=None, join=None):
22792245
22802246
See Also
22812247
--------
2282-
%(also)s
2248+
split : Splits string at the first occurrence of delimiter
2249+
rsplit : Splits string at the last occurrence of delimiter
22832250
22842251
Examples
22852252
--------
2286-
%(example)s
2287-
""")
2253+
>>> s = pd.Series(["this is good text", "but this is even better"])
22882254
2289-
@Appender(_shared_docs['str_split'] % {
2290-
'side': 'beginning',
2291-
'method': 'split',
2292-
'also': 'rsplit : Splits string at the last occurrence of delimiter',
2293-
'example':
2294-
""">>> s = pd.Series(["this is good text", "but this is even better"])
2295-
2296-
By default, split will return an object of the same size
2255+
By default, split and rsplit will return an object of the same size
22972256
having lists containing the split elements
22982257
22992258
>>> s.str.split()
23002259
0 [this, is, good, text]
23012260
1 [but, this, is, even, better]
23022261
dtype: object
23032262
2263+
>>> s.str.rsplit()
2264+
0 [this, is, good, text]
2265+
1 [but, this, is, even, better]
2266+
dtype: object
2267+
23042268
>>> s.str.split("random")
23052269
0 [this is good text]
23062270
1 [but this is even better]
23072271
dtype: object
23082272
2273+
>>> s.str.rsplit("random")
2274+
0 [this is good text]
2275+
1 [but this is even better]
2276+
dtype: object
2277+
23092278
When using ``expand=True``, the split and rsplit elements will
23102279
expand out into separate columns.
23112280
@@ -2328,6 +2297,11 @@ def cat(self, others=None, sep=None, na_rep=None, join=None):
23282297
1 [but th, is even better]
23292298
dtype: object
23302299
2300+
>>> s.str.rsplit("is", n=1)
2301+
0 [this , good text]
2302+
1 [but this , even better]
2303+
dtype: object
2304+
23312305
If NaN is present, it is propagated throughout the columns
23322306
during the split.
23332307
@@ -2337,48 +2311,27 @@ def cat(self, others=None, sep=None, na_rep=None, join=None):
23372311
0 1 2 3
23382312
0 this is good text
23392313
1 but this is even better
2340-
2 NaN NaN NaN NaN """})
2314+
2 NaN NaN NaN NaN
2315+
2316+
>>> s.str.rsplit(n=3, expand=True)
2317+
0 1 2 3
2318+
0 this is good text
2319+
1 but this is even better
2320+
2 NaN NaN NaN NaN
2321+
""")
2322+
2323+
@Appender(_shared_docs['str_split'] % {
2324+
'side': 'beginning',
2325+
'method': 'split'
2326+
})
23412327
def split(self, pat=None, n=-1, expand=False):
23422328
result = str_split(self._data, pat, n=n)
23432329
return self._wrap_result(result, expand=expand)
23442330

23452331
@Appender(_shared_docs['str_split'] % {
23462332
'side': 'end',
2347-
'method': 'rsplit',
2348-
'also': 'split : Splits string at the first occurrence of delimiter',
2349-
'example':
2350-
""">>> s = pd.Series(["this is good text", "but this is even better"])
2351-
2352-
By default, rsplit will return an object of the same size
2353-
having lists containing the split elements
2354-
2355-
>>> s.str.rsplit()
2356-
0 [this, is, good, text]
2357-
1 [but, this, is, even, better]
2358-
dtype: object
2359-
2360-
>>> s.str.rsplit("random")
2361-
0 [this is good text]
2362-
1 [but this is even better]
2363-
dtype: object
2364-
2365-
Parameter `n` can be used to limit the number of splits in the output.
2366-
2367-
>>> s.str.rsplit("is", n=1)
2368-
0 [this , good text]
2369-
1 [but this , even better]
2370-
dtype: object
2371-
2372-
If NaN is present, it is propagated throughout the columns
2373-
during the split.
2374-
2375-
>>> s = pd.Series(["this is good text", "but this is even better", np.nan])
2376-
2377-
>>> s.str.rsplit(n=3, expand=True)
2378-
0 1 2 3
2379-
0 this is good text
2380-
1 but this is even better
2381-
2 NaN NaN NaN NaN """})
2333+
'method': 'rsplit'
2334+
})
23822335
def rsplit(self, pat=None, n=-1, expand=False):
23832336
result = str_rsplit(self._data, pat, n=n)
23842337
return self._wrap_result(result, expand=expand)

0 commit comments

Comments
 (0)