MCPcopy Create free account
hub / github.com/feast-dev/feast / test_count_distinct_result

Function test_count_distinct_result

sdk/python/tests/unit/test_aggregation_ops.py:115–130  ·  view source on GitHub ↗

count_distinct via nunique returns the number of unique values per group.

()

Source from the content-addressed store, hash-verified

113
114
115def 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
133def test_count_distinct_tiling_raises():

Callers

nothing calls this directly

Calls 4

PandasBackendClass · 0.90
DummyAggregationClass · 0.85
groupby_aggMethod · 0.45

Tested by

no test coverage detected