From 0840eb76a3e373a1f5ce08ec076e8854e3daa231 Mon Sep 17 00:00:00 2001 From: Chelsea Lin Date: Tue, 21 Jan 2025 20:21:58 +0000 Subject: [PATCH] feat: add __hash__ property for JSONArrowType --- db_dtypes/json.py | 3 +++ tests/unit/test_json.py | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/db_dtypes/json.py b/db_dtypes/json.py index 145eec3..99e0c67 100644 --- a/db_dtypes/json.py +++ b/db_dtypes/json.py @@ -274,6 +274,9 @@ def __arrow_ext_serialize__(self) -> bytes: def __arrow_ext_deserialize__(cls, storage_type, serialized) -> JSONArrowType: return JSONArrowType() + def __hash__(self) -> int: + return hash(str(self)) + def to_pandas_dtype(self): return JSONDtype() diff --git a/tests/unit/test_json.py b/tests/unit/test_json.py index 055eef0..ff2c867 100644 --- a/tests/unit/test_json.py +++ b/tests/unit/test_json.py @@ -129,6 +129,11 @@ def test_json_arrow_storage_type(): assert pa.types.is_string(arrow_json_type.storage_type) +def test_json_arrow_hash(): + arr = pa.array([], type=db_dtypes.JSONArrowType()) + assert hash(arr.type) == hash(db_dtypes.JSONArrowType()) + + def test_json_arrow_constructors(): data = [ json.dumps(value, sort_keys=True, separators=(",", ":"))