Skip to content

Commit

Permalink
dont keep ref if no validity
Browse files Browse the repository at this point in the history
  • Loading branch information
nameexhaustion committed Apr 30, 2024
1 parent 28c2faf commit a9b6d65
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
6 changes: 5 additions & 1 deletion crates/polars-arrow/src/mmap/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,11 @@ fn mmap_primitive<P: NativeType, T: AsRef<[u8]>>(
};
// Now we need to keep the new buffer alive
struct Two<A, B>(A, B);
let owned_data = Arc::new(Two(data, values));
let owned_data = Arc::new(Two(
// We can drop the original ref if we don't have a validity
validity.and(Some(data)),
values,
));
let bytes_ptr = owned_data.1.as_ptr() as *mut u8;

unsafe {
Expand Down
28 changes: 20 additions & 8 deletions py-polars/tests/unit/io/test_ipc.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,12 +316,24 @@ def test_ipc_decimal_15920(
) -> None:
monkeypatch.setenv("POLARS_ACTIVATE_DECIMAL", "1")
tmp_path.mkdir(exist_ok=True)
D = Decimal

df = pl.Series(
"x", [D("10.1"), None, D("11.2")], dtype=pl.Decimal(18, 2)
).to_frame()

path = f"{tmp_path}/data"
df.write_ipc(path)
assert_frame_equal(pl.read_ipc(path), df)
base_df = pl.Series(
"x",
[
*[
Decimal(x)
for x in [
"10.1", "11.2", "12.3", "13.4", "14.5", "15.6", "16.7", "17.8", "18.9", "19.0",
"20.1", "21.2", "22.3", "23.4", "24.5", "25.6", "26.7", "27.8", "28.9", "29.0",
"30.1", "31.2", "32.3", "33.4", "34.5", "35.6", "36.7", "37.8", "38.9", "39.0"
]
],
*(50 * [None])
],
dtype=pl.Decimal(18, 2),
).to_frame() # fmt: skip

for df in [base_df, base_df.drop_nulls()]:
path = f"{tmp_path}/data"
df.write_ipc(path)
assert_frame_equal(pl.read_ipc(path), df)

0 comments on commit a9b6d65

Please sign in to comment.