From 6f7d912e20a4f134287f4db1560c4efe49afff57 Mon Sep 17 00:00:00 2001 From: Steve Nyemba Date: Mon, 1 Apr 2024 14:06:34 -0500 Subject: [PATCH] bug fix/refactoring commong IEncoder --- transport/common.py | 17 +++++++++++++++++ transport/nosql/mongodb.py | 16 +++++++++++++++- transport/other/callback.py | 2 +- 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 transport/common.py diff --git a/transport/common.py b/transport/common.py new file mode 100644 index 0000000..e17c615 --- /dev/null +++ b/transport/common.py @@ -0,0 +1,17 @@ +import json + + +class IEncoder (json.JSONEncoder): + def default (self,object): + if type(object) == np.integer : + return int(object) + elif type(object) == np.floating: + return float(object) + elif type(object) == np.ndarray : + return object.tolist() + elif type(object) == datetime : + return object.isoformat() + else: + return super(IEncoder,self).default(object) + + diff --git a/transport/nosql/mongodb.py b/transport/nosql/mongodb.py index 2784cd2..00d20ba 100644 --- a/transport/nosql/mongodb.py +++ b/transport/nosql/mongodb.py @@ -17,7 +17,21 @@ import sys import json import re from multiprocessing import Lock, RLock -from transport.common import IEncoder +# from transport.common import IEncoder + +class IEncoder (json.JSONEncoder): + def default (self,object): + if type(object) == np.integer : + return int(object) + elif type(object) == np.floating: + return float(object) + elif type(object) == np.ndarray : + return object.tolist() + elif type(object) == datetime : + return object.isoformat() + else: + return super(IEncoder,self).default(object) + class Mongo : lock = RLock() diff --git a/transport/other/callback.py b/transport/other/callback.py index 29b03fc..c56c175 100644 --- a/transport/other/callback.py +++ b/transport/other/callback.py @@ -1,6 +1,6 @@ import queue from threading import Thread, Lock -from transport.common import Reader,Writer +# from transport.common import Reader,Writer import numpy as np import pandas as pd