count_distinct via nunique returns the number of unique values per group.
()
| 113 | |
| 114 | |
| 115 | def test_count_distinct_result(): |
| 116 | """count_distinct via nunique returns the number of unique values per group.""" |
| 117 | from feast.infra.compute_engines.backends.pandas_backend import PandasBackend |
| 118 | |
| 119 | agg_specs = [DummyAggregation(function="count_distinct", column="item_id")] |
| 120 | agg_ops = aggregation_specs_to_agg_ops( |
| 121 | agg_specs, |
| 122 | time_window_unsupported_error_message="no windows", |
| 123 | ) |
| 124 | |
| 125 | df = pd.DataFrame({"user": ["A", "A", "B"], "item_id": [1, 2, 1]}) |
| 126 | result = PandasBackend().groupby_agg(df, ["user"], agg_ops) |
| 127 | result = result.set_index("user") |
| 128 | |
| 129 | assert result.loc["A", "count_distinct_item_id"] == 2 |
| 130 | assert result.loc["B", "count_distinct_item_id"] == 1 |
| 131 | |
| 132 | |
| 133 | def test_count_distinct_tiling_raises(): |
nothing calls this directly
no test coverage detected