Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewgazelka committed Sep 28, 2024
1 parent 2666f19 commit 9aee66d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
20 changes: 20 additions & 0 deletions daft/expressions/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2930,6 +2930,26 @@ def value_counts(self) -> Expression:
Expression: A Map<X, UInt64> expression where the keys are unique elements from the
original list of type X, and the values are UInt64 counts representing
the number of times each element appears in the list.
Example:
>>> import daft
>>> df = daft.from_pydict({"letters": [["a", "b", "a"], ["b", "c", "b", "c"]]})
>>> df.with_column("value_counts", df["letters"].list.value_counts()).collect()
╭──────────────┬───────────────────╮
│ letters ┆ value_counts │
│ --- ┆ --- │
│ List[Utf8] ┆ Map[Utf8: UInt64] │
╞══════════════╪═══════════════════╡
│ [a, b, a] ┆ [{key: a, │
│ ┆ value: 2, │
│ ┆ }, {key: … │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ [b, c, b, c] ┆ [{key: b, │
│ ┆ value: 2, │
│ ┆ }, {key: … │
╰──────────────┴───────────────────╯
<BLANKLINE>
(Showing first 2 of 2 rows)
"""
return Expression._from_pyexpr(native.list_value_counts(self._expr))

Expand Down
2 changes: 0 additions & 2 deletions src/daft-core/src/array/ops/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,13 +331,11 @@ impl ListArray {

let keys = self.flat_child.filter(&boolean_array)?;

// todo: probably inefficient
let keys = Series::try_from_field_and_arrow_array(
Field::new("key", key_type.clone()),
keys.to_arrow(),
)?;

// todo: probably inefficient
let values = Series::try_from_field_and_arrow_array(
Field::new("value", count_type.clone()),
values.to_arrow(),
Expand Down

0 comments on commit 9aee66d

Please sign in to comment.