From 8f8cad4e9363d94f903250a2221546efb7fd157c Mon Sep 17 00:00:00 2001 From: Alex Merose Date: Mon, 17 Jan 2022 10:41:29 -0800 Subject: [PATCH 1/2] Added check to ensure output is not a numpy type. --- weather_mv/loader_pipeline/pipeline_test.py | 1 + 1 file changed, 1 insertion(+) diff --git a/weather_mv/loader_pipeline/pipeline_test.py b/weather_mv/loader_pipeline/pipeline_test.py index b4893e24..8b955710 100644 --- a/weather_mv/loader_pipeline/pipeline_test.py +++ b/weather_mv/loader_pipeline/pipeline_test.py @@ -108,6 +108,7 @@ def setUp(self) -> None: def assertRowsEqual(self, actual: t.Dict, expected: t.Dict): for key in expected.keys(): self.assertAlmostEqual(actual[key], expected[key], places=4) + self.assertNotIsInstance(actual[key], np.dtype) class ExtractRowsTest(ExtractRowsTestBase): From 95fd2f78be17f940a88376a1bd574716c09bf723 Mon Sep 17 00:00:00 2001 From: Alex Merose Date: Mon, 17 Jan 2022 16:47:00 -0800 Subject: [PATCH 2/2] JSON Error Fix: Converting timedelta to float. --- weather_mv/loader_pipeline/pipeline.py | 2 +- weather_mv/loader_pipeline/pipeline_test.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/weather_mv/loader_pipeline/pipeline.py b/weather_mv/loader_pipeline/pipeline.py index 100b1c21..29242250 100644 --- a/weather_mv/loader_pipeline/pipeline.py +++ b/weather_mv/loader_pipeline/pipeline.py @@ -185,7 +185,7 @@ def to_json_serializable_type(value: t.Any) -> t.Any: return None elif type(value) == np.timedelta64: # Return time delta in seconds. - return value / np.timedelta64(1, 's') + return float(value / np.timedelta64(1, 's')) # This check must happen after processing np.timedelta64 and np.datetime64. elif np.issubdtype(type(value), np.integer): return int(value) diff --git a/weather_mv/loader_pipeline/pipeline_test.py b/weather_mv/loader_pipeline/pipeline_test.py index 8b955710..d332ee08 100644 --- a/weather_mv/loader_pipeline/pipeline_test.py +++ b/weather_mv/loader_pipeline/pipeline_test.py @@ -106,9 +106,12 @@ def setUp(self) -> None: self.test_data_folder = f'{next(iter(weather_mv.__path__))}/test_data' def assertRowsEqual(self, actual: t.Dict, expected: t.Dict): + self.assertEqual(actual.keys(), expected.keys()) for key in expected.keys(): self.assertAlmostEqual(actual[key], expected[key], places=4) self.assertNotIsInstance(actual[key], np.dtype) + self.assertNotIsInstance(actual[key], np.float64) + self.assertNotIsInstance(actual[key], np.float32) class ExtractRowsTest(ExtractRowsTestBase):