Skip to content

Commit

Permalink
fix(rust): Fix panic when computing min() of Duration series. (#16455)
Browse files Browse the repository at this point in the history
  • Loading branch information
BGR360 authored May 24, 2024
1 parent 8d4529c commit 05c2f87
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
5 changes: 1 addition & 4 deletions crates/polars-core/src/series/implementations/duration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,10 +407,7 @@ impl SeriesTrait for SeriesWrap<DurationChunked> {
fn min_reduce(&self) -> PolarsResult<Scalar> {
let sc = self.0.min_reduce();
let v = sc.value().as_duration(self.0.time_unit());
Ok(Scalar::new(
self.dtype().clone(),
v.as_duration(self.0.time_unit()),
))
Ok(Scalar::new(self.dtype().clone(), v))
}
fn std_reduce(&self, ddof: u8) -> PolarsResult<Scalar> {
let sc = self.0.std_reduce(ddof);
Expand Down
14 changes: 13 additions & 1 deletion py-polars/tests/unit/dataframe/test_describe.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ def test_df_describe(lazy: bool) -> None:
],
"g": [date(2020, 1, 1), date(2021, 7, 5), date(2022, 12, 31)],
"h": [time(10, 30), time(15, 0), time(20, 30)],
"i": [1_000_000, 2_000_000, 3_000_000],
},
schema_overrides={"e": pl.Categorical},
schema_overrides={"e": pl.Categorical, "i": pl.Duration},
)

frame: pl.DataFrame | pl.LazyFrame = df.lazy() if lazy else df
Expand Down Expand Up @@ -93,6 +94,17 @@ def test_df_describe(lazy: bool) -> None:
"20:30:00",
"20:30:00",
],
"i": [
"3",
"0",
"0:00:02",
None,
"0:00:01",
"0:00:02",
"0:00:02",
"0:00:03",
"0:00:03",
],
}
)
assert_frame_equal(result, expected)
Expand Down

0 comments on commit 05c2f87

Please sign in to comment.