@@ -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,9 @@ 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 (
861
+ a , np .asanyarray (chars , getattr (chars , "dtype" , a .dtype )))
842
862
843
863
844
864
def rstrip (a , chars = None ):
@@ -879,7 +899,9 @@ def rstrip(a, chars=None):
879
899
"""
880
900
if chars is None :
881
901
return _rstrip_whitespace (a )
882
- return _rstrip_chars (a , chars )
902
+ a = np .asanyarray (a )
903
+ return _rstrip_chars (
904
+ a , np .asanyarray (chars , getattr (chars , "dtype" , a .dtype )))
883
905
884
906
885
907
def strip (a , chars = None ):
@@ -924,7 +946,9 @@ def strip(a, chars=None):
924
946
"""
925
947
if chars is None :
926
948
return _strip_whitespace (a )
927
- return _strip_chars (a , chars )
949
+ a = np .asanyarray (a )
950
+ return _strip_chars (
951
+ a , np .asanyarray (chars , getattr (chars , "dtype" , a .dtype )))
928
952
929
953
930
954
def upper (a ):
@@ -1120,9 +1144,9 @@ def replace(a, old, new, count=-1):
1120
1144
1121
1145
Parameters
1122
1146
----------
1123
- a : array_like, with ``bytes_`` or ``str_`` dtype
1147
+ a : array_like, with ``StringDType``, `` bytes_`` or ``str_`` dtype
1124
1148
1125
- old, new : array_like, with ``bytes_`` or ``str_`` dtype
1149
+ old, new : array_like, with ``StringDType``, `` bytes_`` or ``str_`` dtype
1126
1150
1127
1151
count : array_like, with ``int_`` dtype
1128
1152
If the optional argument ``count`` is given, only the first
@@ -1147,7 +1171,7 @@ def replace(a, old, new, count=-1):
1147
1171
>>> a = np.array(["The dish is fresh", "This is it"])
1148
1172
>>> np.strings.replace(a, 'is', 'was')
1149
1173
array(['The dwash was fresh', 'Thwas was it'], dtype='<U19')
1150
-
1174
+
1151
1175
"""
1152
1176
arr = np .asanyarray (a )
1153
1177
a_dt = arr .dtype
@@ -1361,8 +1385,7 @@ def partition(a, sep):
1361
1385
1362
1386
"""
1363
1387
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 )
1388
+ sep = np .asanyarray (sep , dtype = getattr (sep , "dtype" , a .dtype ))
1366
1389
if a .dtype .char == "T" :
1367
1390
return _partition (a , sep )
1368
1391
@@ -1426,8 +1449,7 @@ def rpartition(a, sep):
1426
1449
1427
1450
"""
1428
1451
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 )
1452
+ sep = np .asanyarray (sep , dtype = getattr (sep , "dtype" , a .dtype ))
1431
1453
if a .dtype .char == "T" :
1432
1454
return _rpartition (a , sep )
1433
1455
0 commit comments