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=(",", ":"))