@@ -235,6 +235,8 @@ def find(a, sub, start=0, end=None):
235
235
236
236
"""
237
237
end = end if end is not None else MAX
238
+ a = np .asanyarray (a )
239
+ sub = np .asanyarray (sub , dtype = getattr (sub , "dtype" , a .dtype ))
238
240
return _find_ufunc (a , sub , start , end )
239
241
240
242
@@ -265,6 +267,8 @@ def rfind(a, sub, start=0, end=None):
265
267
266
268
"""
267
269
end = end if end is not None else MAX
270
+ a = np .asanyarray (a )
271
+ sub = np .asanyarray (sub , dtype = getattr (sub , "dtype" , a .dtype ))
268
272
return _rfind_ufunc (a , sub , start , end )
269
273
270
274
@@ -277,6 +281,7 @@ def index(a, sub, start=0, end=None):
277
281
a : array-like, with ``StringDType``, ``bytes_``, or ``str_`` dtype
278
282
279
283
sub : array-like, with ``StringDType``, ``bytes_``, or ``str_`` dtype
284
+ The substring to search for.
280
285
281
286
start, end : array_like, with any integer dtype, optional
282
287
@@ -297,6 +302,8 @@ def index(a, sub, start=0, end=None):
297
302
298
303
"""
299
304
end = end if end is not None else MAX
305
+ a = np .asanyarray (a )
306
+ sub = np .asanyarray (sub , dtype = getattr (sub , "dtype" , a .dtype ))
300
307
return _index_ufunc (a , sub , start , end )
301
308
302
309
@@ -307,9 +314,10 @@ def rindex(a, sub, start=0, end=None):
307
314
308
315
Parameters
309
316
----------
310
- a : array-like, with `np. bytes_` or `np. str_` dtype
317
+ a : array-like, with ``StringDType``, `` bytes_``, or `` str_` ` dtype
311
318
312
- sub : array-like, with `np.bytes_` or `np.str_` dtype
319
+ sub : array-like, with ``StringDType``, ``bytes_``, or ``str_`` dtype
320
+ The substring to search for.
313
321
314
322
start, end : array-like, with any integer dtype, optional
315
323
@@ -327,9 +335,11 @@ def rindex(a, sub, start=0, end=None):
327
335
>>> a = np.array(["Computer Science"])
328
336
>>> np.strings.rindex(a, "Science", start=0, end=None)
329
337
array([9])
330
-
338
+
331
339
"""
332
340
end = end if end is not None else MAX
341
+ a = np .asanyarray (a )
342
+ sub = np .asanyarray (sub , dtype = getattr (sub , "dtype" , a .dtype ))
333
343
return _rindex_ufunc (a , sub , start , end )
334
344
335
345
@@ -373,6 +383,8 @@ def count(a, sub, start=0, end=None):
373
383
374
384
"""
375
385
end = end if end is not None else MAX
386
+ a = np .asanyarray (a )
387
+ sub = np .asanyarray (sub , dtype = getattr (sub , "dtype" , a .dtype ))
376
388
return _count_ufunc (a , sub , start , end )
377
389
378
390
@@ -386,6 +398,7 @@ def startswith(a, prefix, start=0, end=None):
386
398
a : array-like, with ``StringDType``, ``bytes_``, or ``str_`` dtype
387
399
388
400
prefix : array-like, with ``StringDType``, ``bytes_``, or ``str_`` dtype
401
+ The substring to search for.
389
402
390
403
start, end : array_like, with any integer dtype
391
404
With ``start``, test beginning at that position. With ``end``,
@@ -402,6 +415,8 @@ def startswith(a, prefix, start=0, end=None):
402
415
403
416
"""
404
417
end = end if end is not None else MAX
418
+ a = np .asanyarray (a )
419
+ prefix = np .asanyarray (prefix , dtype = getattr (prefix , "dtype" , a .dtype ))
405
420
return _startswith_ufunc (a , prefix , start , end )
406
421
407
422
@@ -415,6 +430,7 @@ def endswith(a, suffix, start=0, end=None):
415
430
a : array-like, with ``StringDType``, ``bytes_``, or ``str_`` dtype
416
431
417
432
suffix : array-like, with ``StringDType``, ``bytes_``, or ``str_`` dtype
433
+ The substring to search for.
418
434
419
435
start, end : array_like, with any integer dtype
420
436
With ``start``, test beginning at that position. With ``end``,
@@ -441,6 +457,8 @@ def endswith(a, suffix, start=0, end=None):
441
457
442
458
"""
443
459
end = end if end is not None else MAX
460
+ a = np .asanyarray (a )
461
+ suffix = np .asanyarray (suffix , dtype = getattr (suffix , "dtype" , a .dtype ))
444
462
return _endswith_ufunc (a , suffix , start , end )
445
463
446
464
@@ -627,7 +645,7 @@ def center(a, width, fillchar=' '):
627
645
"""
628
646
a = np .asanyarray (a )
629
647
width = np .maximum (str_len (a ), width )
630
- fillchar = np .asanyarray (fillchar , dtype = a .dtype )
648
+ fillchar = np .asanyarray (fillchar , getattr ( fillchar , " dtype" , a .dtype ) )
631
649
632
650
if np .any (str_len (fillchar ) != 1 ):
633
651
raise TypeError (
@@ -683,7 +701,7 @@ def ljust(a, width, fillchar=' '):
683
701
"""
684
702
a = np .asanyarray (a )
685
703
width = np .maximum (str_len (a ), width )
686
- fillchar = np .asanyarray (fillchar , dtype = a .dtype )
704
+ fillchar = np .asanyarray (fillchar , getattr ( fillchar , " dtype" , a .dtype ) )
687
705
688
706
if np .any (str_len (fillchar ) != 1 ):
689
707
raise TypeError (
@@ -739,7 +757,7 @@ def rjust(a, width, fillchar=' '):
739
757
"""
740
758
a = np .asanyarray (a )
741
759
width = np .maximum (str_len (a ), width )
742
- fillchar = np .asanyarray (fillchar , dtype = a .dtype )
760
+ fillchar = np .asanyarray (fillchar , getattr ( fillchar , " dtype" , a .dtype ) )
743
761
744
762
if np .any (str_len (fillchar ) != 1 ):
745
763
raise TypeError (
@@ -838,7 +856,8 @@ def lstrip(a, chars=None):
838
856
"""
839
857
if chars is None :
840
858
return _lstrip_whitespace (a )
841
- return _lstrip_chars (a , chars )
859
+ a = np .asanyarray (a )
860
+ return _lstrip_chars (a , np .asanyarray (chars , getattr (chars , "dtype" , a .dtype )))
842
861
843
862
844
863
def rstrip (a , chars = None ):
@@ -879,7 +898,8 @@ def rstrip(a, chars=None):
879
898
"""
880
899
if chars is None :
881
900
return _rstrip_whitespace (a )
882
- return _rstrip_chars (a , chars )
901
+ a = np .asanyarray (a )
902
+ return _rstrip_chars (a , np .asanyarray (chars , getattr (chars , "dtype" , a .dtype )))
883
903
884
904
885
905
def strip (a , chars = None ):
@@ -924,7 +944,8 @@ def strip(a, chars=None):
924
944
"""
925
945
if chars is None :
926
946
return _strip_whitespace (a )
927
- return _strip_chars (a , chars )
947
+ a = np .asanyarray (a )
948
+ return _strip_chars (a , np .asanyarray (chars , getattr (chars , "dtype" , a .dtype )))
928
949
929
950
930
951
def upper (a ):
@@ -1120,9 +1141,9 @@ def replace(a, old, new, count=-1):
1120
1141
1121
1142
Parameters
1122
1143
----------
1123
- a : array_like, with ``bytes_`` or ``str_`` dtype
1144
+ a : array_like, with ``StringDType``, `` bytes_`` or ``str_`` dtype
1124
1145
1125
- old, new : array_like, with ``bytes_`` or ``str_`` dtype
1146
+ old, new : array_like, with ``StringDType``, `` bytes_`` or ``str_`` dtype
1126
1147
1127
1148
count : array_like, with ``int_`` dtype
1128
1149
If the optional argument ``count`` is given, only the first
@@ -1147,7 +1168,7 @@ def replace(a, old, new, count=-1):
1147
1168
>>> a = np.array(["The dish is fresh", "This is it"])
1148
1169
>>> np.strings.replace(a, 'is', 'was')
1149
1170
array(['The dwash was fresh', 'Thwas was it'], dtype='<U19')
1150
-
1171
+
1151
1172
"""
1152
1173
arr = np .asanyarray (a )
1153
1174
a_dt = arr .dtype
@@ -1361,8 +1382,7 @@ def partition(a, sep):
1361
1382
1362
1383
"""
1363
1384
a = np .asanyarray (a )
1364
- # TODO switch to copy=False when issues around views are fixed
1365
- sep = np .array (sep , dtype = a .dtype , copy = True , subok = True )
1385
+ sep = np .asanyarray (sep , dtype = getattr (sep , "dtype" , a .dtype ))
1366
1386
if a .dtype .char == "T" :
1367
1387
return _partition (a , sep )
1368
1388
@@ -1426,8 +1446,7 @@ def rpartition(a, sep):
1426
1446
1427
1447
"""
1428
1448
a = np .asanyarray (a )
1429
- # TODO switch to copy=False when issues around views are fixed
1430
- sep = np .array (sep , dtype = a .dtype , copy = True , subok = True )
1449
+ sep = np .asanyarray (sep , dtype = getattr (sep , "dtype" , a .dtype ))
1431
1450
if a .dtype .char == "T" :
1432
1451
return _rpartition (a , sep )
1433
1452
0 commit comments