Skip to content

Commit 59ed7d5

Browse files
committed
Move fix to infer dtype
1 parent 981d89e commit 59ed7d5

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

xarray/coding/strings.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818

1919
def create_vlen_dtype(element_type):
20+
if element_type not in (str, bytes):
21+
raise TypeError("Unsupported type for vlen_dtype: `{}`".format(element_type))
2022
# based on h5py.special_dtype
2123
return np.dtype("O", metadata={"element_type": element_type})
2224

@@ -29,11 +31,7 @@ def check_vlen_dtype(dtype):
2931

3032

3133
def is_unicode_dtype(dtype):
32-
return (
33-
dtype.kind == "U"
34-
or check_vlen_dtype(dtype) == str
35-
or check_vlen_dtype(dtype) == np.str_
36-
)
34+
return dtype.kind == "U" or check_vlen_dtype(dtype) == str
3735

3836

3937
def is_bytes_dtype(dtype):

xarray/conventions.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,10 @@ def _infer_dtype(array, name=None):
157157
return np.dtype(float)
158158

159159
element = array[(0,) * array.ndim]
160-
if isinstance(element, (bytes, str)):
160+
if isinstance(element, bytes):
161161
return strings.create_vlen_dtype(type(element))
162+
elif isinstance(element, str):
163+
return strings.create_vlen_dtype(str)
162164

163165
dtype = np.array(element).dtype
164166
if dtype.kind != "O":

0 commit comments

Comments
 (0)