@@ -93,8 +93,16 @@ def serialize(self, data, key, model_type):
93
93
:type model_type: str
94
94
:return: pymilo serialized output of data[key]
95
95
"""
96
+ if isinstance (data [key ], type ):
97
+ raw_type = str (data [key ])
98
+ raw_type = "numpy" + str (raw_type ).split ("numpy" )[- 1 ][:- 2 ]
99
+ if raw_type in NUMPY_TYPE_DICT .keys ():
100
+ data [key ] = {
101
+ "np-type" : "numpy.dtype" ,
102
+ "value" : raw_type
103
+ }
96
104
# 1. Handling numpy infinity, ransac
97
- if isinstance (data [key ], np .float64 ):
105
+ elif isinstance (data [key ], np .float64 ):
98
106
if np .inf == data [key ]:
99
107
data [key ] = {
100
108
"np-type" : "numpy.infinity" ,
@@ -209,7 +217,7 @@ def get_deserialized_dict(self, content):
209
217
return self .deep_deserialize_ndarray (content )
210
218
211
219
if check_str_in_iterable ("np-type" , content ) and check_str_in_iterable ("value" , content ):
212
- return NUMPY_TYPE_DICT [ content [ "np-type" ]] (content [ "value" ] )
220
+ return self . get_deserialized_regular_primary_types (content )
213
221
214
222
for key in content :
215
223
@@ -271,6 +279,8 @@ def get_deserialized_regular_primary_types(self, content):
271
279
:return: the associated np.int32|np.int64|np.inf
272
280
"""
273
281
if "np-type" in content :
282
+ if content ["np-type" ] == "numpy.dtype" :
283
+ return NUMPY_TYPE_DICT [content ["np-type" ]](NUMPY_TYPE_DICT [content ['value' ]])
274
284
return NUMPY_TYPE_DICT [content ["np-type" ]](content ['value' ])
275
285
276
286
def is_numpy_primary_type (self , content ):
@@ -359,8 +369,7 @@ def deserialize_primitive_type(self, primitive):
359
369
if is_primitive (primitive ):
360
370
return primitive
361
371
elif check_str_in_iterable ("np-type" , primitive ):
362
- return NUMPY_TYPE_DICT [primitive ["np-type" ]
363
- ](primitive ['value' ])
372
+ return self .get_deserialized_regular_primary_types (primitive )
364
373
else :
365
374
return primitive
366
375
0 commit comments