77
88import numpy as np
99
10- # STRING_DTYPE is the in-memory datatype that will be used for V3 string arrays
10+ # _STRING_DTYPE is the in-memory datatype that will be used for V3 string arrays
1111# when reading data back from Zarr.
1212# Any valid string-like datatype should be fine for *setting* data.
1313
14- STRING_DTYPE : Union ["np.dtypes.StringDType" , "np.dtypes.ObjectDType" ]
15- NUMPY_SUPPORTS_VLEN_STRING : bool
14+ _STRING_DTYPE : Union ["np.dtypes.StringDType" , "np.dtypes.ObjectDType" ]
15+ _NUMPY_SUPPORTS_VLEN_STRING : bool
1616
1717
1818def cast_array (
@@ -23,24 +23,24 @@ def cast_array(
2323
2424try :
2525 # this new vlen string dtype was added in NumPy 2.0
26- STRING_DTYPE = np .dtypes .StringDType ()
27- NUMPY_SUPPORTS_VLEN_STRING = True
26+ _STRING_DTYPE = np .dtypes .StringDType ()
27+ _NUMPY_SUPPORTS_VLEN_STRING = True
2828
2929 def cast_array (
3030 data : np .ndarray [Any , np .dtype [Any ]],
3131 ) -> np .ndarray [Any , np .dtypes .StringDType | np .dtypes .ObjectDType ]:
32- out = data .astype (STRING_DTYPE , copy = False )
32+ out = data .astype (_STRING_DTYPE , copy = False )
3333 return cast (np .ndarray [Any , np .dtypes .StringDType ], out )
3434
3535except AttributeError :
3636 # if not available, we fall back on an object array of strings, as in Zarr < 3
37- STRING_DTYPE = np .dtypes .ObjectDType ()
38- NUMPY_SUPPORTS_VLEN_STRING = False
37+ _STRING_DTYPE = np .dtypes .ObjectDType ()
38+ _NUMPY_SUPPORTS_VLEN_STRING = False
3939
4040 def cast_array (
4141 data : np .ndarray [Any , np .dtype [Any ]],
4242 ) -> np .ndarray [Any , Union ["np.dtypes.StringDType" , "np.dtypes.ObjectDType" ]]:
43- out = data .astype (STRING_DTYPE , copy = False )
43+ out = data .astype (_STRING_DTYPE , copy = False )
4444 return cast (np .ndarray [Any , np .dtypes .ObjectDType ], out )
4545
4646
@@ -61,13 +61,13 @@ def cast_to_string_dtype(
6161 return cast_array (data )
6262 # out = data.astype(STRING_DTYPE, copy=False)
6363 # return cast(np.ndarray[Any, np.dtypes.StringDType | np.dtypes.ObjectDType], out)
64- if NUMPY_SUPPORTS_VLEN_STRING :
65- if np .issubdtype (data .dtype , STRING_DTYPE ):
64+ if _NUMPY_SUPPORTS_VLEN_STRING :
65+ if np .issubdtype (data .dtype , _STRING_DTYPE ):
6666 # already a valid string variable length string dtype
6767 return cast_array (data )
6868 if np .issubdtype (data .dtype , np .object_ ):
6969 # object arrays require more careful handling
70- if NUMPY_SUPPORTS_VLEN_STRING :
70+ if _NUMPY_SUPPORTS_VLEN_STRING :
7171 try :
7272 # cast to variable-length string dtype, fail if object contains non-string data
7373 # mypy says "error: Unexpected keyword argument "coerce" for "StringDType" [call-arg]"
0 commit comments