-
Notifications
You must be signed in to change notification settings - Fork 839
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
Add dictionary support for C data interface #1407
Changes from 2 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 |
---|---|---|
|
@@ -79,6 +79,7 @@ def assert_pyarrow_leak(): | |
pa.field("c", pa.string()), | ||
] | ||
), | ||
pa.dictionary(pa.int8(), pa.string()), | ||
] | ||
|
||
_unsupported_pyarrow_types = [ | ||
|
@@ -122,14 +123,6 @@ def test_type_roundtrip_raises(pyarrow_type): | |
with pytest.raises(pa.ArrowException): | ||
rust.round_trip_type(pyarrow_type) | ||
|
||
|
||
def test_dictionary_type_roundtrip(): | ||
# the dictionary type conversion is incomplete | ||
pyarrow_type = pa.dictionary(pa.int32(), pa.string()) | ||
ty = rust.round_trip_type(pyarrow_type) | ||
assert ty == pa.int32() | ||
|
||
|
||
@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) | ||
|
@@ -263,3 +256,13 @@ def test_decimal_python(): | |
assert a == b | ||
del a | ||
del b | ||
|
||
def test_dictionary_python(): | ||
""" | ||
Python -> Rust -> Python | ||
""" | ||
a = pa.array(["a", "b", "a"], type=pa.dictionary(pa.int8(), pa.string())) | ||
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. same here - with validities? |
||
b = rust.round_trip_array(a) | ||
assert a == b | ||
del a | ||
del b |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,7 @@ impl TryFrom<ArrayData> for ffi::ArrowArray { | |
|
||
#[cfg(test)] | ||
mod tests { | ||
use crate::array::{DictionaryArray, Int32Array, StringArray}; | ||
use crate::error::Result; | ||
use crate::{ | ||
array::{ | ||
|
@@ -127,4 +128,14 @@ mod tests { | |
let data = array.data(); | ||
test_round_trip(data) | ||
} | ||
|
||
#[test] | ||
fn test_dictionary() -> Result<()> { | ||
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. would it be worth to have an example with validity (in both the keys and values), so that we cover the most complex use-case? 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. Good idea. Will add. |
||
let values = StringArray::from(vec!["foo", "bar", "zoo"]); | ||
let keys = Int32Array::from(vec![0, 1, 2, 2, 1, 0, 1, 2, 1, 2]); | ||
let array = DictionaryArray::try_new(&keys, &values)?; | ||
|
||
let data = array.data(); | ||
test_round_trip(data) | ||
} | ||
} |
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.
🎉