File tree 2 files changed +8
-11
lines changed
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:
96
96
else :
97
97
raise NotImplementedError (f"Unsupported pandas version: { pd .__version__ } " )
98
98
99
- def __arrow_array__ (self ):
99
+ def __arrow_array__ (self , type = None ):
100
100
"""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 ())
102
102
103
103
@classmethod
104
104
def _box_pa (
@@ -159,12 +159,7 @@ def _serialize_json(value):
159
159
def _deserialize_json (value ):
160
160
"""A static method that converts a JSON string back into its original value."""
161
161
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 )
168
163
else :
169
164
return value
170
165
@@ -279,9 +274,6 @@ def __arrow_ext_serialize__(self) -> bytes:
279
274
def __arrow_ext_deserialize__ (cls , storage_type , serialized ) -> JSONArrowType :
280
275
return JSONArrowType ()
281
276
282
- def __hash__ (self ) -> int :
283
- return hash (str (self ))
284
-
285
277
def to_pandas_dtype (self ):
286
278
return JSONDtype ()
287
279
Original file line number Diff line number Diff line change @@ -118,6 +118,11 @@ def test_as_numpy_array():
118
118
pd ._testing .assert_equal (result , expected )
119
119
120
120
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
+
121
126
def test_json_arrow_storage_type ():
122
127
arrow_json_type = db_dtypes .JSONArrowType ()
123
128
assert arrow_json_type .extension_name == "dbjson"
You can’t perform that action at this time.
0 commit comments