forked from platypush/platypush
Skip numpy types serialization errors on Message.Encoder.
This commit is contained in:
parent
e5a5ac5ffb
commit
9acd71944c
1 changed files with 14 additions and 14 deletions
|
@ -34,21 +34,21 @@ class Message:
|
|||
def parse_numpy(obj):
|
||||
try:
|
||||
import numpy as np
|
||||
except ImportError:
|
||||
return
|
||||
|
||||
if isinstance(obj, np.floating):
|
||||
return float(obj)
|
||||
if isinstance(obj, np.integer):
|
||||
return int(obj)
|
||||
if isinstance(obj, np.ndarray):
|
||||
return obj.tolist()
|
||||
if isinstance(obj, decimal.Decimal):
|
||||
return float(obj)
|
||||
if isinstance(obj, (bytes, bytearray)):
|
||||
return '0x' + ''.join([f'{x:02x}' for x in obj])
|
||||
if callable(obj):
|
||||
return '<function at {}.{}>'.format(obj.__module__, obj.__name__)
|
||||
if isinstance(obj, np.floating):
|
||||
return float(obj)
|
||||
if isinstance(obj, np.integer):
|
||||
return int(obj)
|
||||
if isinstance(obj, np.ndarray):
|
||||
return obj.tolist()
|
||||
if isinstance(obj, decimal.Decimal):
|
||||
return float(obj)
|
||||
if isinstance(obj, (bytes, bytearray)):
|
||||
return '0x' + ''.join([f'{x:02x}' for x in obj])
|
||||
if callable(obj):
|
||||
return '<function at {}.{}>'.format(obj.__module__, obj.__name__)
|
||||
except (ImportError, TypeError):
|
||||
pass
|
||||
|
||||
return
|
||||
|
||||
|
|
Loading…
Reference in a new issue