-
Notifications
You must be signed in to change notification settings - Fork 1k
Add support for using ListView arrays and types through FFI #8822
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -620,6 +620,16 @@ impl ArrayData { | |
| vec![ArrayData::new_null(f.data_type(), *list_len as usize * len)], | ||
| true, | ||
| ), | ||
| DataType::ListView(f) => ( | ||
| vec![zeroed(len * 4), zeroed(len * 4)], | ||
| vec![ArrayData::new_empty(f.data_type())], | ||
| true, | ||
| ), | ||
| DataType::LargeListView(f) => ( | ||
| vec![zeroed(len * 8), zeroed(len * 8)], | ||
| vec![ArrayData::new_empty(f.data_type())], | ||
| true, | ||
| ), | ||
| DataType::Struct(fields) => ( | ||
| vec![], | ||
| fields | ||
|
|
@@ -1783,7 +1793,7 @@ impl DataTypeLayout { | |
| }, | ||
| ], | ||
| can_contain_null_mask: true, | ||
| variadic: true, | ||
| variadic: false, | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a bug, see the spec, list views aren't represented by a variable number of buffers. |
||
| } | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,7 +27,9 @@ | |
|
|
||
| import arrow_pyarrow_integration_testing as rust | ||
|
|
||
| PYARROW_PRE_14 = int(pa.__version__.split('.')[0]) < 14 | ||
| PYARROW_MAJOR_VER = int(pa.__version__.split(".")[0]) | ||
| PYARROW_PRE_14 = PYARROW_MAJOR_VER < 14 | ||
| PYARROW_PRE_16 = PYARROW_MAJOR_VER < 16 | ||
|
|
||
|
|
||
| @contextlib.contextmanager | ||
|
|
@@ -112,8 +114,16 @@ def assert_pyarrow_leak(): | |
| ), | ||
| ] | ||
|
|
||
| _unsupported_pyarrow_types = [ | ||
| ] | ||
| if PYARROW_MAJOR_VER >= 16: | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did this to get everything green, but I think that it might be a good opportunity to only test with pyarrow 16 and above, which supports all relevant features here - |
||
| _supported_pyarrow_types.extend( | ||
| [ | ||
| pa.list_view(pa.uint64()), | ||
| pa.large_list_view(pa.uint64()), | ||
| pa.list_view(pa.string()), | ||
| pa.large_list_view(pa.string()), | ||
| ] | ||
| ) | ||
|
|
||
|
|
||
| # As of pyarrow 14, pyarrow implements the Arrow PyCapsule interface | ||
| # (https://arrow.apache.org/docs/format/CDataInterface/PyCapsuleInterface.html). | ||
|
|
@@ -158,12 +168,6 @@ def test_type_roundtrip_pycapsule(pyarrow_type): | |
| assert restored == pyarrow_type | ||
| assert restored is not pyarrow_type | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("pyarrow_type", _unsupported_pyarrow_types, ids=str) | ||
| def test_type_roundtrip_raises(pyarrow_type): | ||
| with pytest.raises(pa.ArrowException): | ||
| rust.round_trip_type(pyarrow_type) | ||
|
|
||
| @pytest.mark.parametrize('pyarrow_type', _supported_pyarrow_types, ids=str) | ||
| def test_field_roundtrip(pyarrow_type): | ||
| pyarrow_field = pa.field("test", pyarrow_type, nullable=True) | ||
|
|
@@ -337,6 +341,21 @@ def test_list_array(): | |
| del a | ||
| del b | ||
|
|
||
|
|
||
| @pytest.mark.skipif(PYARROW_PRE_16, reason="requires pyarrow 16") | ||
| def test_list_view_array(): | ||
| """ | ||
| Python -> Rust -> Python | ||
| """ | ||
| a = pa.array([[], None, [1, 2], [4, 5, 6]], pa.list_view(pa.int64())) | ||
| b = rust.round_trip_array(a) | ||
| b.validate(full=True) | ||
| assert a.to_pylist() == b.to_pylist() | ||
| assert a.type == b.type | ||
| del a | ||
| del b | ||
|
|
||
|
|
||
| def test_map_array(): | ||
| """ | ||
| Python -> Rust -> Python | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just nicer when working with IDEs.