File tree Expand file tree Collapse file tree 2 files changed +8
-11
lines changed Expand file tree Collapse file tree 2 files changed +8
-11
lines changed Original file line number Diff line number Diff line change @@ -96,9 +96,9 @@ def __init__(self, values) -> None:
9696 else :
9797 raise NotImplementedError (f"Unsupported pandas version: { pd .__version__ } " )
9898
99- def __arrow_array__ (self ):
99+ def __arrow_array__ (self , type = None ):
100100 """Convert to an arrow array. This is required for pyarrow extension."""
101- return self .pa_data
101+ return pa . array ( self .pa_data , type = JSONArrowType ())
102102
103103 @classmethod
104104 def _box_pa (
@@ -159,12 +159,7 @@ def _serialize_json(value):
159159 def _deserialize_json (value ):
160160 """A static method that converts a JSON string back into its original value."""
161161 if not pd .isna (value ):
162- # Attempt to interpret the value as a JSON object.
163- # If it's not valid JSON, treat it as a regular string.
164- try :
165- return json .loads (value )
166- except json .JSONDecodeError :
167- return value
162+ return json .loads (value )
168163 else :
169164 return value
170165
@@ -279,9 +274,6 @@ def __arrow_ext_serialize__(self) -> bytes:
279274 def __arrow_ext_deserialize__ (cls , storage_type , serialized ) -> JSONArrowType :
280275 return JSONArrowType ()
281276
282- def __hash__ (self ) -> int :
283- return hash (str (self ))
284-
285277 def to_pandas_dtype (self ):
286278 return JSONDtype ()
287279
Original file line number Diff line number Diff line change @@ -118,6 +118,11 @@ def test_as_numpy_array():
118118 pd ._testing .assert_equal (result , expected )
119119
120120
121+ def test_json_arrow_array ():
122+ data = db_dtypes .JSONArray ._from_sequence (JSON_DATA .values ())
123+ assert isinstance (data .__arrow_array__ (), pa .ExtensionArray )
124+
125+
121126def test_json_arrow_storage_type ():
122127 arrow_json_type = db_dtypes .JSONArrowType ()
123128 assert arrow_json_type .extension_name == "dbjson"
You can’t perform that action at this time.
0 commit comments