Skip to content

Commit

Permalink
fix[rust]: keep logical type in deep-clone unstable series (#4520)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Aug 21, 2022
1 parent 91538f5 commit 7c8e59d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
11 changes: 7 additions & 4 deletions polars/polars-core/src/series/unstable.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::convert::TryFrom;
use std::marker::PhantomData;
use std::ptr::NonNull;

Expand Down Expand Up @@ -56,9 +55,13 @@ impl<'a> UnstableSeries<'a> {
}

pub fn deep_clone(&self) -> Series {
let array_ref = unsafe { (*self.container).chunks() }[0].clone();
let name = unsafe { (*self.container).name() };
Series::try_from((name, array_ref)).unwrap()
unsafe {
let s = &(*self.container);
debug_assert_eq!(s.chunks().len(), 1);
let array_ref = s.chunks().get_unchecked(0).clone();
let name = s.name();
Series::from_chunks_and_dtype_unchecked(name, vec![array_ref], s.dtype())
}
}

#[inline]
Expand Down
16 changes: 16 additions & 0 deletions py-polars/tests/test_datelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -1303,3 +1303,19 @@ def test_date_parse_omit_day() -> None:
assert df.select(pl.col("month").str.strptime(pl.Datetime, fmt="%Y-%m"))[
0, 0
] == datetime(2022, 1, 1)


def test_shift_and_fill_group_logicals() -> None:
df = pl.from_records(
[
(date(2001, 1, 2), "A"),
(date(2001, 1, 3), "A"),
(date(2001, 1, 4), "A"),
(date(2001, 1, 3), "B"),
(date(2001, 1, 4), "B"),
],
columns=["d", "s"],
)
assert df.select(
pl.col("d").shift_and_fill(-1, pl.col("d").max()).over("s")
).dtypes == [pl.Date]

0 comments on commit 7c8e59d

Please sign in to comment.