@@ -6788,7 +6788,7 @@ returns a rank 1 numpy character array of length NUMCHARS with datatype `'S1'`
67886788 arr[0 :len (string)] = tuple (string)
67896789 return arr
67906790
6791- def stringtochar (a ,encoding = ' utf-8 ' ,n_strlen = None ):
6791+ def stringtochar (a ,encoding = None ,n_strlen = None ):
67926792 """
67936793**`stringtochar(a,encoding='utf-8',n_strlen=None)`**
67946794
@@ -6809,10 +6809,15 @@ used to represent each string in the input array).
68096809returns a numpy character array with datatype `'S1'` or `'U1'`
68106810and shape `a.shape + (N,)`, where N is the length of each string in a."""
68116811 dtype = a.dtype.kind
6812- if n_strlen is None :
6813- n_strlen = a.dtype.itemsize
68146812 if dtype not in [" S" ," U" ]:
68156813 raise ValueError (" type must string or unicode ('S' or 'U')" )
6814+ if encoding is None :
6815+ if dtype == ' S' :
6816+ encoding = ' ascii'
6817+ else :
6818+ encoding = ' utf-8'
6819+ if n_strlen is None :
6820+ n_strlen = a.dtype.itemsize
68166821 if encoding in [' none' ,' None' ,' bytes' ]:
68176822 b = numpy.array(tuple (a.tobytes()),' S1' )
68186823 elif encoding == ' ascii' :
@@ -6827,7 +6832,7 @@ and shape `a.shape + (N,)`, where N is the length of each string in a."""
68276832 b = numpy.array([[bb[i:i+ 1 ] for i in range (n_strlen)] for bb in bbytes])
68286833 return b
68296834
6830- def chartostring (b ,encoding = ' utf-8 ' ):
6835+ def chartostring (b ,encoding = None ):
68316836 """
68326837**`chartostring(b,encoding='utf-8')`**
68336838
@@ -6846,6 +6851,11 @@ returns a numpy string array with datatype `'UN'` (or `'SN'`) and shape
68466851 dtype = b.dtype.kind
68476852 if dtype not in [" S" ," U" ]:
68486853 raise ValueError (" type must be string or unicode ('S' or 'U')" )
6854+ if encoding is None :
6855+ if dtype == ' S' :
6856+ encoding = ' ascii'
6857+ else :
6858+ encoding = ' utf-8'
68496859 bs = b.tobytes()
68506860 slen = int (b.shape[- 1 ])
68516861 if encoding in [' none' ,' None' ,' bytes' ]:
0 commit comments