Skip to content

Commit

Permalink
Fixes null propagation in boolean casts
Browse files Browse the repository at this point in the history
  • Loading branch information
rchowell committed Feb 4, 2025
1 parent 2e682a3 commit 13e8638
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/arrow2/src/compute/cast/boolean_to.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ where
/// Casts the [`BooleanArray`] to a [`Utf8Array`], casting trues to `"true"` and falses to `"false"`
pub fn boolean_to_utf8<O: Offset>(from: &BooleanArray) -> Utf8Array<O> {
let iter = from.values().iter().map(|x| if x { "true" } else { "false" });
Utf8Array::from_trusted_len_values_iter(iter)
Utf8Array::from_trusted_len_values_iter(iter).with_validity(from.validity().cloned())
}

pub(super) fn boolean_to_utf8_dyn<O: Offset>(array: &dyn Array) -> Result<Box<dyn Array>> {
Expand All @@ -41,7 +41,7 @@ pub(super) fn boolean_to_utf8_dyn<O: Offset>(array: &dyn Array) -> Result<Box<dy
/// Casts the [`BooleanArray`] to a [`BinaryArray`], casting trues to `"1"` and falses to `"0"`
pub fn boolean_to_binary<O: Offset>(from: &BooleanArray) -> BinaryArray<O> {
let iter = from.values().iter().map(|x| if x { b"1" } else { b"0" });
BinaryArray::from_trusted_len_values_iter(iter)
BinaryArray::from_trusted_len_values_iter(iter).with_validity(from.validity().cloned())
}

pub(super) fn boolean_to_binary_dyn<O: Offset>(array: &dyn Array) -> Result<Box<dyn Array>> {
Expand Down
2 changes: 1 addition & 1 deletion tests/expressions/test_list_.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def test_list_constructor_heterogeneous():
def test_list_constructor_heterogeneous_with_cast():
df = daft.from_pydict({"x": [1, 2, 3], "y": [True, True, False]})
df = df.select(list_(col("x").cast(dt.string()), col("y").cast(dt.string())).alias("strs"))
assert df.to_pydict() == {"strs": [["1", "1"], ["2", "1"], ["3", "0"]]}
assert df.to_pydict() == {"strs": [["1", "true"], ["2", "true"], ["3", "false"]]}


def test_list_constructor_mixed_null_first():
Expand Down
4 changes: 2 additions & 2 deletions tests/series/test_cast.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ def test_series_cast_null(target_dtype) -> None:
[
(DataType.null(), [None, None, None]),
(DataType.bool(), [True, False, None]),
(DataType.string(), ["true", "false", "false"]),
(DataType.binary(), [b"1", b"0", b"0"]),
(DataType.string(), ["true", "false", None]),
(DataType.binary(), [b"1", b"0", None]),
(DataType.python(), [True, False, None]),
]
+ [(dtype, [1, 0, None]) for dtype in daft_int_types]
Expand Down

0 comments on commit 13e8638

Please sign in to comment.