Skip to content

Commit

Permalink
Add dtypes to HipscatEncoder (#274)
Browse files Browse the repository at this point in the history
* add dtypes to HipscatEncoder

* add test coverage
  • Loading branch information
troyraen authored May 21, 2024
1 parent 9d7dfdd commit 1ebbbfe
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/hipscat/io/write_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
2 changes: 2 additions & 0 deletions tests/hipscat/io/test_write_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def test_write_json_file(assert_text_file_matches, tmp_path):
" 3,",
" 5",
" ]",
r' "integer_type": "<class \'int\'>"',
"}",
]

Expand All @@ -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)
Expand Down

0 comments on commit 1ebbbfe

Please sign in to comment.