Problem
summarize_stops allows a passthrough column to use a custom aggregation through passthrough_agg, but the aggregation cannot declare its output dtype.
_get_empty_stop_df currently assigns each passthrough output the dtype of its input column. _cast_to_stop_schema then casts populated results back to that dtype. For example, applying "mean" to an Int64 passthrough column can produce 1.5, which is then rounded and cast back to Int64 as 2. When every label is noise, the aggregation never runs, so its output dtype cannot be inferred from a value.
Proposed change
Add an optional passthrough_dtypes mapping to summarize_stops, keyed by passthrough column name. A declared dtype must be used by _get_empty_stop_df when constructing an empty result and by _cast_to_stop_schema when casting a populated result.
Behavior when no dtype is declared
Preserve the current rules:
- A passthrough column without an entry in
passthrough_agg uses the first value in each cluster and retains the input column dtype.
- A passthrough column with an entry in
passthrough_agg, but no entry in passthrough_dtypes, is still assumed to return the input column dtype.
- Existing calls that only pass
passthrough_cols or passthrough_agg do not need to change.
Tests
- Move
test_summarize_stops_custom_aggregation_can_change_dtype from strict xfail to passing by declaring {"score": "Float64"} for an Int64 column aggregated with "mean".
- Check that populated and all-noise results have the same columns and dtypes.
- Retain coverage for aggregations that do not change dtype, including string and nullable-integer
location_id values.
Problem
summarize_stopsallows a passthrough column to use a custom aggregation throughpassthrough_agg, but the aggregation cannot declare its output dtype._get_empty_stop_dfcurrently assigns each passthrough output the dtype of its input column._cast_to_stop_schemathen casts populated results back to that dtype. For example, applying"mean"to anInt64passthrough column can produce1.5, which is then rounded and cast back toInt64as2. When every label is noise, the aggregation never runs, so its output dtype cannot be inferred from a value.Proposed change
Add an optional
passthrough_dtypesmapping tosummarize_stops, keyed by passthrough column name. A declared dtype must be used by_get_empty_stop_dfwhen constructing an empty result and by_cast_to_stop_schemawhen casting a populated result.Behavior when no dtype is declared
Preserve the current rules:
passthrough_agguses the first value in each cluster and retains the input column dtype.passthrough_agg, but no entry inpassthrough_dtypes, is still assumed to return the input column dtype.passthrough_colsorpassthrough_aggdo not need to change.Tests
test_summarize_stops_custom_aggregation_can_change_dtypefrom strictxfailto passing by declaring{"score": "Float64"}for anInt64column aggregated with"mean".location_idvalues.