Skip to content

Let custom passthrough aggregations declare their output dtype #428

Description

@paco-barreras

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions