Skip to content

Commit dc33ac4

Browse files
authored
Merge pull request numpy#26033 from lysnikolaou/remove-partition-split-strings
MAINT: Remove partition and split-like functions from numpy.strings
2 parents bbcaf73 + 6f85750 commit dc33ac4

File tree

2 files changed

+38
-25
lines changed

2 files changed

+38
-25
lines changed

numpy/_core/defchararray.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@
2424
from numpy._core import overrides
2525
from numpy.strings import *
2626
from numpy.strings import multiply as strings_multiply
27+
from numpy._core.strings import (
28+
_partition as partition,
29+
_rpartition as rpartition,
30+
_split as split,
31+
_rsplit as rsplit,
32+
_splitlines as splitlines,
33+
_join as join,
34+
)
2735

2836
__all__ = [
2937
'equal', 'not_equal', 'greater_equal', 'less_equal',

numpy/_core/strings.py

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,13 @@
5454
"zfill",
5555

5656
# _vec_string - Will gradually become ufuncs as well
57-
"mod", "decode", "encode", "upper", "lower", "swapcase", "capitalize",
58-
"title", "join", "split", "rsplit", "splitlines", "partition",
59-
"rpartition", "translate",
57+
"upper", "lower", "swapcase", "capitalize", "title",
58+
59+
# _vec_string - Will probably not become ufuncs
60+
"mod", "decode", "encode", "translate",
61+
62+
# Removed from namespace until behavior has been crystalized
63+
# "join", "split", "rsplit", "splitlines", "partition", "rpartition",
6064
]
6165

6266

@@ -1145,7 +1149,7 @@ def replace(a, old, new, count=-1):
11451149
return _replace(arr, old, new, counts, out=out)
11461150

11471151

1148-
def join(sep, seq):
1152+
def _join(sep, seq):
11491153
"""
11501154
Return a string which is the concatenation of the strings in the
11511155
sequence `seq`.
@@ -1168,18 +1172,18 @@ def join(sep, seq):
11681172
11691173
Examples
11701174
--------
1171-
>>> np.strings.join('-', 'osd')
1172-
array('o-s-d', dtype='<U5')
1175+
>>> np.strings.join('-', 'osd') # doctest: +SKIP
1176+
array('o-s-d', dtype='<U5') # doctest: +SKIP
11731177
1174-
>>> np.strings.join(['-', '.'], ['ghc', 'osd'])
1175-
array(['g-h-c', 'o.s.d'], dtype='<U5')
1178+
>>> np.strings.join(['-', '.'], ['ghc', 'osd']) # doctest: +SKIP
1179+
array(['g-h-c', 'o.s.d'], dtype='<U5') # doctest: +SKIP
11761180
11771181
"""
11781182
return _to_bytes_or_str_array(
11791183
_vec_string(sep, np.object_, 'join', (seq,)), seq)
11801184

11811185

1182-
def split(a, sep=None, maxsplit=None):
1186+
def _split(a, sep=None, maxsplit=None):
11831187
"""
11841188
For each element in `a`, return a list of the words in the
11851189
string, using `sep` as the delimiter string.
@@ -1205,11 +1209,11 @@ def split(a, sep=None, maxsplit=None):
12051209
Examples
12061210
--------
12071211
>>> x = np.array("Numpy is nice!")
1208-
>>> np.strings.split(x, " ")
1209-
array(list(['Numpy', 'is', 'nice!']), dtype=object)
1212+
>>> np.strings.split(x, " ") # doctest: +SKIP
1213+
array(list(['Numpy', 'is', 'nice!']), dtype=object) # doctest: +SKIP
12101214
1211-
>>> np.strings.split(x, " ", 1)
1212-
array(list(['Numpy', 'is nice!']), dtype=object)
1215+
>>> np.strings.split(x, " ", 1) # doctest: +SKIP
1216+
array(list(['Numpy', 'is nice!']), dtype=object) # doctest: +SKIP
12131217
12141218
See Also
12151219
--------
@@ -1222,7 +1226,7 @@ def split(a, sep=None, maxsplit=None):
12221226
a, np.object_, 'split', [sep] + _clean_args(maxsplit))
12231227

12241228

1225-
def rsplit(a, sep=None, maxsplit=None):
1229+
def _rsplit(a, sep=None, maxsplit=None):
12261230
"""
12271231
For each element in `a`, return a list of the words in the
12281232
string, using `sep` as the delimiter string.
@@ -1255,8 +1259,9 @@ def rsplit(a, sep=None, maxsplit=None):
12551259
Examples
12561260
--------
12571261
>>> a = np.array(['aAaAaA', 'abBABba'])
1258-
>>> np.strings.rsplit(a, 'A')
1259-
array([list(['a', 'a', 'a', '']), list(['abB', 'Bba'])], dtype=object)
1262+
>>> np.strings.rsplit(a, 'A') # doctest: +SKIP
1263+
array([list(['a', 'a', 'a', '']), # doctest: +SKIP
1264+
list(['abB', 'Bba'])], dtype=object) # doctest: +SKIP
12601265
12611266
"""
12621267
# This will return an array of lists of different sizes, so we
@@ -1265,7 +1270,7 @@ def rsplit(a, sep=None, maxsplit=None):
12651270
a, np.object_, 'rsplit', [sep] + _clean_args(maxsplit))
12661271

12671272

1268-
def splitlines(a, keepends=None):
1273+
def _splitlines(a, keepends=None):
12691274
"""
12701275
For each element in `a`, return a list of the lines in the
12711276
element, breaking at line boundaries.
@@ -1294,7 +1299,7 @@ def splitlines(a, keepends=None):
12941299
a, np.object_, 'splitlines', _clean_args(keepends))
12951300

12961301

1297-
def partition(a, sep):
1302+
def _partition(a, sep):
12981303
"""
12991304
Partition each element in `a` around `sep`.
13001305
@@ -1323,8 +1328,8 @@ def partition(a, sep):
13231328
Examples
13241329
--------
13251330
>>> x = np.array(["Numpy is nice!"])
1326-
>>> np.strings.partition(x, " ")
1327-
array([['Numpy', ' ', 'is nice!']], dtype='<U8')
1331+
>>> np.strings.partition(x, " ") # doctest: +SKIP
1332+
array([['Numpy', ' ', 'is nice!']], dtype='<U8') # doctest: +SKIP
13281333
13291334
See Also
13301335
--------
@@ -1335,7 +1340,7 @@ def partition(a, sep):
13351340
_vec_string(a, np.object_, 'partition', (sep,)), a)
13361341

13371342

1338-
def rpartition(a, sep):
1343+
def _rpartition(a, sep):
13391344
"""
13401345
Partition (split) each element around the right-most separator.
13411346
@@ -1368,10 +1373,10 @@ def rpartition(a, sep):
13681373
Examples
13691374
--------
13701375
>>> a = np.array(['aAaAaA', ' aA ', 'abBABba'])
1371-
>>> np.strings.rpartition(a, 'A')
1372-
array([['aAaAa', 'A', ''],
1373-
[' a', 'A', ' '],
1374-
['abB', 'A', 'Bba']], dtype='<U5')
1376+
>>> np.strings.rpartition(a, 'A') # doctest: +SKIP
1377+
array([['aAaAa', 'A', ''], # doctest: +SKIP
1378+
[' a', 'A', ' '], # doctest: +SKIP
1379+
['abB', 'A', 'Bba']], dtype='<U5') # doctest: +SKIP
13751380
13761381
"""
13771382
return _to_bytes_or_str_array(

0 commit comments

Comments
 (0)