Skip to content

Commit

Permalink
feat: Add unique operations for Decimal dtype (#20855)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukemanley authored Jan 23, 2025
1 parent 24fccc4 commit e4dcec5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
15 changes: 15 additions & 0 deletions crates/polars-core/src/series/implementations/decimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,21 @@ impl SeriesTrait for SeriesWrap<DecimalChunked> {
self.0.has_nulls()
}

#[cfg(feature = "algorithm_group_by")]
fn unique(&self) -> PolarsResult<Series> {
Ok(self.apply_physical_to_s(|ca| ca.unique().unwrap()))
}

#[cfg(feature = "algorithm_group_by")]
fn n_unique(&self) -> PolarsResult<usize> {
self.0.n_unique()
}

#[cfg(feature = "algorithm_group_by")]
fn arg_unique(&self) -> PolarsResult<IdxCa> {
self.0.arg_unique()
}

fn is_null(&self) -> BooleanChunked {
self.0.is_null()
}
Expand Down
8 changes: 8 additions & 0 deletions py-polars/tests/unit/datatypes/test_decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,3 +651,11 @@ def test_fill_null() -> None:
assert s.fill_null(strategy="forward").to_list() == [D("1.2"), D("1.2"), D("1.4")]
assert s.fill_null(strategy="backward").to_list() == [D("1.2"), D("1.4"), D("1.4")]
assert s.fill_null(strategy="mean").to_list() == [D("1.2"), D("1.3"), D("1.4")]


def test_unique() -> None:
ser = pl.Series([D("1.1"), D("1.1"), D("2.2")])

assert ser.unique().to_list() == [D("1.1"), D("2.2")]
assert ser.n_unique() == 2
assert ser.arg_unique().to_list() == [0, 2]

0 comments on commit e4dcec5

Please sign in to comment.