Skip to content

Commit

Permalink
unique counts for logical types (#3694)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Jun 14, 2022
1 parent 86167e2 commit 0307a57
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion polars/polars-core/src/series/ops/unique.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl Series {
#[cfg(feature = "unique_counts")]
#[cfg_attr(docsrs, doc(cfg(feature = "unique_counts")))]
pub fn unique_counts(&self) -> IdxCa {
if self.dtype().is_numeric() {
if self.dtype().to_physical().is_numeric() {
if self.bit_repr_is_large() {
let ca = self.bit_repr_large();
unique_counts(ca.into_iter())
Expand Down
23 changes: 23 additions & 0 deletions py-polars/tests/test_datelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -981,3 +981,26 @@ def test_datetime_instance_selection() -> None:

for tu in ["ns", "us", "ms"]:
assert df.select(pl.col([pl.Datetime(tu)])).dtypes == [pl.Datetime(tu)]


def test_unique_counts_on_dates() -> None:
assert pl.DataFrame(
{
"dt_ns": pl.date_range(datetime(2020, 1, 1), datetime(2020, 3, 1), "1mo"),
}
).with_columns(
[
pl.col("dt_ns").dt.cast_time_unit("us").alias("dt_us"),
pl.col("dt_ns").dt.cast_time_unit("ms").alias("dt_ms"),
pl.col("dt_ns").cast(pl.Date).alias("date"),
]
).select(
pl.all().unique_counts().sum()
).to_dict(
False
) == {
"dt_ns": [3],
"dt_us": [3],
"dt_ms": [3],
"date": [3],
}

0 comments on commit 0307a57

Please sign in to comment.