Skip to content

Commit 9120e6a

Browse files
committed
another attempt to avoid problems encoding ndarrays
1 parent 044f5d7 commit 9120e6a

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

larch/utils/jsonutils.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,11 @@ def encode4js(obj):
9999
if obj is None:
100100
return None
101101
if isinstance(obj, np.ndarray):
102+
out = {'__class__': 'Array', '__shape__': obj.shape}
102103
try:
103-
out = {'__class__': 'Array', '__shape__': obj.shape,
104-
'__dtype__': obj.dtype.name}
104+
out['__dtype__'] = obj.dtype.name
105105
except:
106-
print('error encoding ndarray: ', obj, obj.shape, obj.dtype)
107-
out = {'__class__': 'Array', '__shape__': obj.shape}
106+
out['__dtype__'] = 'object'
108107
out['value'] = obj.flatten().tolist()
109108
if 'complex' in obj.dtype.name:
110109
out['value'] = [(obj.real).tolist(), (obj.imag).tolist()]

0 commit comments

Comments
 (0)