1414from textwrap import indent
1515
1616import numpy as np
17- from numpy import char as chararray
1817
1918from astropy .utils import lazyproperty
19+ from astropy .utils .compat import chararray , get_chararray
2020from astropy .utils .exceptions import AstropyUserWarning
2121
2222from .card import CARD_LENGTH , Card
@@ -696,14 +696,14 @@ def __init__(
696696 # input arrays can be just list or tuple, not required to be ndarray
697697 # does not include Object array because there is no guarantee
698698 # the elements in the object array are consistent.
699- if not isinstance (array , (np .ndarray , chararray . chararray , Delayed )):
699+ if not isinstance (array , (np .ndarray , chararray , Delayed )):
700700 try : # try to convert to a ndarray first
701701 if array is not None :
702702 array = np .array (array )
703703 except Exception :
704704 try : # then try to convert it to a strings array
705705 itemsize = int (recformat [1 :])
706- array = chararray . array (array , itemsize = itemsize )
706+ array = get_chararray (array , itemsize = itemsize )
707707 except ValueError :
708708 # then try variable length array
709709 # Note: This includes _FormatQ by inheritance
@@ -1388,7 +1388,7 @@ def _convert_to_valid_data_type(self, array):
13881388 fsize = dims [- 1 ]
13891389 else :
13901390 fsize = np .dtype (format .recformat ).itemsize
1391- return chararray . array (array , itemsize = fsize , copy = False )
1391+ return get_chararray (array , itemsize = fsize , copy = False )
13921392 else :
13931393 return _convert_array (array , np .dtype (format .recformat ))
13941394 elif "L" in format :
@@ -2082,7 +2082,7 @@ def __new__(cls, input, dtype="S"):
20822082 try :
20832083 # this handles ['abc'] and [['a','b','c']]
20842084 # equally, beautiful!
2085- input = [chararray . array (x , itemsize = 1 ) for x in input ]
2085+ input = [get_chararray (x , itemsize = 1 ) for x in input ]
20862086 except Exception :
20872087 raise ValueError (f"Inconsistent input data array: { input } " )
20882088
@@ -2105,10 +2105,10 @@ def __setitem__(self, key, value):
21052105 """
21062106 if isinstance (value , np .ndarray ) and value .dtype == self .dtype :
21072107 pass
2108- elif isinstance (value , chararray . chararray ) and value .itemsize == 1 :
2108+ elif isinstance (value , chararray ) and value .itemsize == 1 :
21092109 pass
21102110 elif self .element_dtype == "S" :
2111- value = chararray . array (value , itemsize = 1 )
2111+ value = get_chararray (value , itemsize = 1 )
21122112 else :
21132113 value = np .array (value , dtype = self .element_dtype )
21142114 np .ndarray .__setitem__ (self , key , value )
@@ -2262,7 +2262,7 @@ def _makep(array, descr_output, format, nrows=None):
22622262 else :
22632263 rowval = [0 ] * data_output .max
22642264 if format .dtype == "S" :
2265- data_output [idx ] = chararray . array (encode_ascii (rowval ), itemsize = 1 )
2265+ data_output [idx ] = get_chararray (encode_ascii (rowval ), itemsize = 1 )
22662266 else :
22672267 data_output [idx ] = np .array (rowval , dtype = format .dtype )
22682268
0 commit comments