From 9acd71944c0e9e4807be4c5820ee6906f871d587 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Fri, 6 Oct 2023 22:54:19 +0200 Subject: [PATCH] Skip numpy types serialization errors on Message.Encoder. --- platypush/message/__init__.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/platypush/message/__init__.py b/platypush/message/__init__.py index 480fb1823..c7ee3e209 100644 --- a/platypush/message/__init__.py +++ b/platypush/message/__init__.py @@ -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 ''.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 ''.format(obj.__module__, obj.__name__) + except (ImportError, TypeError): + pass return