Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support decimal uniq #15001

Merged
merged 1 commit into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions crates/polars-core/src/hashing/vector_hasher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ vec_hash_numeric!(UInt16Chunked);
vec_hash_numeric!(UInt8Chunked);
vec_hash_numeric!(Float64Chunked);
vec_hash_numeric!(Float32Chunked);
#[cfg(feature = "dtype-decimal")]
vec_hash_numeric!(Int128Chunked);

impl VecHash for StringChunked {
fn vec_hash(&self, random_state: RandomState, buf: &mut Vec<u64>) -> PolarsResult<()> {
Expand Down
10 changes: 10 additions & 0 deletions crates/polars-core/src/series/implementations/decimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ impl private::PrivateSeries for SeriesWrap<DecimalChunked> {
(&self.0).into_total_ord_inner()
}

fn vec_hash(&self, random_state: RandomState, buf: &mut Vec<u64>) -> PolarsResult<()> {
self.0.vec_hash(random_state, buf)?;
Ok(())
}

fn vec_hash_combine(&self, build_hasher: RandomState, hashes: &mut [u64]) -> PolarsResult<()> {
self.0.vec_hash_combine(build_hasher, hashes)?;
Ok(())
}

#[cfg(feature = "algorithm_group_by")]
unsafe fn agg_sum(&self, groups: &GroupsProxy) -> Series {
self.agg_helper(|ca| ca.agg_sum(groups))
Expand Down
13 changes: 13 additions & 0 deletions py-polars/tests/unit/datatypes/test_decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,19 @@ def test_decimal_sort() -> None:
].to_list() == [2, 1, 3]


def test_decimal_unique() -> None:
df = pl.DataFrame(
{
"foo": [1, 1, 2],
"bar": [D("3.4"), D("3.4"), D("4.5")],
}
)
assert df.unique().sort("bar").to_dict(as_series=False) == {
"foo": [1, 2],
"bar": [D("3.4"), D("4.5")],
}


def test_decimal_write_parquet_12375() -> None:
f = io.BytesIO()
df = pl.DataFrame(
Expand Down
Loading