From 3d0b9ca3e4c3225dd572f16ed1f3613b3bca1690 Mon Sep 17 00:00:00 2001 From: Doug Boulware Date: Thu, 7 Dec 2023 09:53:24 -0700 Subject: [PATCH] Uset type in encoder and add check and conversion for np.bool_ --- scos_actions/metadata/utils.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/scos_actions/metadata/utils.py b/scos_actions/metadata/utils.py index ef4fd5e9..6253049a 100644 --- a/scos_actions/metadata/utils.py +++ b/scos_actions/metadata/utils.py @@ -33,14 +33,19 @@ def construct_geojson_point( def _enc_hook(obj: Any) -> Any: - if isinstance(obj, np.float64): + #While isinstance is recommended, it was causing a + #Recurrsion error and I don't think we have to worry + #about subytpes here. + if type(obj) == np.float64: return float(obj) + elif type(obj) == np.bool_: + return bool(obj) else: return obj # A reusable encoder with custom hook to ensure serialization -msgspec_enc = msgspec.json.Encoder() +msgspec_enc = msgspec.json.Encoder(enc_hook=_enc_hook) # A reusable decoder which outputs a Python dictionary msgspec_dec_dict = msgspec.json.Decoder(type=dict)