rok commented on code in PR #44070:
URL: https://github.com/apache/arrow/pull/44070#discussion_r1756937853
##########
python/pyarrow/tests/test_extension_type.py:
##########
@@ -1926,3 +1926,90 @@ def test_bool8_scalar():
assert pa.scalar(1, type=pa.bool8()).as_py() is True
assert pa.scalar(2, type=pa.bool8()).as_py() is True
assert pa.scalar(None, type=pa.bool8()).as_py() is None
+
+
[email protected]("storage_type", (
+ pa.utf8(), pa.large_utf8(), pa.string_view(), pa.string(),
pa.large_string()))
+def test_json(storage_type, pickle_module):
+ data = ['{"a": 1}', '{"b": 2}', None]
+ storage = pa.array(data, type=storage_type)
+ json_type = pa.json(storage_type)
+ json_arr_class = json_type.__arrow_ext_class__()
+
+ assert pa.json() == pa.json(pa.utf8())
+ assert json_type.extension_name == "arrow.json"
+ assert json_type.storage_type == storage_type
+ assert json_type.__class__ is pa.JsonType
+
+ assert json_type == pa.json(storage_type)
+ assert json_type != storage_type
+
+ array = pa.ExtensionArray.from_storage(json_type, storage)
+ assert isinstance(array, pa.JsonArray)
+
+ assert array.to_pylist() == data
+ assert array[0].as_py() == data[0]
+ assert array[2].as_py() is None
+
+ # Pickle roundtrip
+ result = pickle_module.loads(pickle_module.dumps(json_type))
+ assert result == json_type
+
+ # IPC roundtrip
+ buf = ipc_write_batch(pa.RecordBatch.from_arrays([array], ["ext"]))
+ batch = ipc_read_batch(buf)
+ reconstructed_array = batch.column(0)
+ assert reconstructed_array.type == json_type
+ assert reconstructed_array == array
+ assert isinstance(array, json_arr_class)
+
+ assert json_type.__arrow_ext_scalar_class__() == pa.JsonScalar
+ assert isinstance(array[0], pa.JsonScalar)
+
+ # cast storage -> extension type
+ result = storage.cast(json_type)
+ assert result == array
+
+ # cast extension type -> storage type
+ if storage_type != pa.string_view():
+ inner = array.cast(storage_type)
+ assert inner == storage
+
+
[email protected]("storage_type", (
+ pa.utf8(), pa.large_utf8(), pa.string(), pa.large_string()))
[email protected]
+def test_parquet_json(tmpdir, storage_type):
Review Comment:
Moved.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]