Skip to content

Commit 72b5833

Browse files
committed
use dtype=object for sequences first not accepted by np.asarray
1 parent 955019b commit 72b5833

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

numcodecs/json.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ def __init__(self, encoding='utf-8', skipkeys=False, ensure_ascii=True,
5454
self._decoder = _json.JSONDecoder(**self._decoder_config)
5555

5656
def encode(self, buf):
57-
buf = np.asarray(buf)
57+
try:
58+
buf = np.asarray(buf)
59+
except ValueError:
60+
buf = np.asarray(buf, dtype=object)
5861
items = buf.tolist()
5962
items.extend((buf.dtype.str, buf.shape))
6063
return self._encoder.encode(items).encode(self._text_encoding)

numcodecs/msgpacks.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ def __init__(self, use_single_float=False, use_bin_type=True, raw=False):
5252
self.raw = raw
5353

5454
def encode(self, buf):
55-
buf = np.asarray(buf)
55+
try:
56+
buf = np.asarray(buf)
57+
except ValueError:
58+
buf = np.asarray(buf, dtype=object)
5659
items = buf.tolist()
5760
items.extend((buf.dtype.str, buf.shape))
5861
return msgpack.packb(items, use_bin_type=self.use_bin_type,

0 commit comments

Comments
 (0)