From 1ebbbfe47ff99369f6d5c65d4c65a5fc3c7a4bed Mon Sep 17 00:00:00 2001 From: Troy Raen Date: Tue, 21 May 2024 13:02:14 -0400 Subject: [PATCH] Add dtypes to `HipscatEncoder` (#274) * add dtypes to HipscatEncoder * add test coverage --- src/hipscat/io/write_metadata.py | 2 ++ tests/hipscat/io/test_write_metadata.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/hipscat/io/write_metadata.py b/src/hipscat/io/write_metadata.py index eb91f925..1e925ecd 100644 --- a/src/hipscat/io/write_metadata.py +++ b/src/hipscat/io/write_metadata.py @@ -24,6 +24,8 @@ class HipscatEncoder(json.JSONEncoder): def default(self, o): if isinstance(o, Path): return str(o) + if isinstance(o, (type, np.dtype, pd.core.dtypes.base.ExtensionDtype)): + return str(o) return super().default(o) # pragma: no cover diff --git a/tests/hipscat/io/test_write_metadata.py b/tests/hipscat/io/test_write_metadata.py index 307830de..37f2a920 100644 --- a/tests/hipscat/io/test_write_metadata.py +++ b/tests/hipscat/io/test_write_metadata.py @@ -27,6 +27,7 @@ def test_write_json_file(assert_text_file_matches, tmp_path): " 3,", " 5", " ]", + r' "integer_type": ""', "}", ] @@ -35,6 +36,7 @@ def test_write_json_file(assert_text_file_matches, tmp_path): dictionary["first_greek"] = "alpha" dictionary["first_number"] = 1 dictionary["first_five_fib"] = [1, 1, 2, 3, 5] + dictionary["integer_type"] = int json_filename = os.path.join(tmp_path, "dictionary.json") io.write_json_file(dictionary, json_filename)