We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4b84e4a commit e17595eCopy full SHA for e17595e
db_dtypes/json.py
@@ -229,3 +229,16 @@ def _reduce(
229
if name in ["min", "max"]:
230
raise TypeError("JSONArray does not support min/max reducntion.")
231
super()._reduce(name, skipna=skipna, keepdims=keepdims, **kwargs)
232
+
233
+ def __array__(self, dtype=None, copy: bool | None = None) -> np.ndarray:
234
+ """Correctly construct numpy arrays when passed to `np.asarray()`."""
235
+ pa_type = self.pa_data.type
236
+ data = self
237
+ if dtype is None:
238
+ empty = pa.array([], type=pa_type).to_numpy(zero_copy_only=False)
239
+ dtype = empty.dtype
240
+ result = np.empty(len(data), dtype=dtype)
241
+ mask = data.isna()
242
+ result[mask] = pd.NA
243
+ result[~mask] = data[~mask].pa_data.to_numpy()
244
+ return result
0 commit comments