Skip to content

fix(data): add missing Optional and return type annotations to aggreg…#64374

Open
AyushKashyapII wants to merge 2 commits into
ray-project:masterfrom
AyushKashyapII:fix/type-annotations-aggregation-api
Open

fix(data): add missing Optional and return type annotations to aggreg…#64374
AyushKashyapII wants to merge 2 commits into
ray-project:masterfrom
AyushKashyapII:fix/type-annotations-aggregation-api

Conversation

@AyushKashyapII

Copy link
Copy Markdown
Contributor

Summary

Fixes incorrect and missing type annotations in the Ray Data aggregation API (aggregate.py and grouped_data.py), addressing issue #64369.

These are not just style additions — several parameters had provably wrong types that mypy would flag: they defaulted to None but None was not included in the type union.

Changes in aggregate.py

  • AggregateFn.__init__: wrapped accumulate_row and accumulate_block
    with Optional[...] — both defaulted to None but were typed as bare
    Callable[...], which excludes None
  • Added -> None to __init__ of all 16 public aggregate classes:
    AggregateFn, AggregateFnV2, Count, AsList, Sum, Min, Max,
    Mean, Std, AbsMax, Quantile, Unique, CountDistinct,
    ValueCounter, MissingValuePercentage, ZeroPercentage,
    ApproximateQuantile, ApproximateTopK

Changes in grouped_data.py

  • GroupedData.__init__: added -> None
  • GroupedData._aggregate_on: corrected on param to
    Optional[Union[str, List[str]]] and added missing -> Dataset return type
  • GroupedData.map_groups: corrected compute param to
    Optional[Union[str, ComputeStrategy]]
  • GroupedData.sum, min, max, mean, std: corrected on param to
    Optional[Union[str, List[str]]] in all five methods

Why these are real errors, not just style

# Before — mypy error: Incompatible default for argument "on"
def sum(self, on: Union[str, List[str]] = None, ...) -> Dataset: ...
#                                         ^^^^
#            None is not assignable to Union[str, List[str]]

# After — correct
def sum(self, on: Optional[Union[str, List[str]]] = None, ...) -> Dataset: ...

Zero runtime impact
Python ignores annotations at runtime. All changed classes were
imported and instantiated locally to confirm no regressions.

…ation API

Signed-off-by: Ayush KAshyap <kashyap11ayush02@gmail.com>
@AyushKashyapII AyushKashyapII requested a review from a team as a code owner June 26, 2026 16:58

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request improves type annotations across python/ray/data/aggregate.py and python/ray/data/grouped_data.py. Specifically, it adds explicit -> None return type annotations to various __init__ constructors and wraps parameters that default to None with Optional types (such as accumulate_row, accumulate_block, on, and compute). There are no review comments, so I have no feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@ray-gardener ray-gardener Bot added docs An issue or change related to documentation data Ray Data-related issues community-contribution Contributed by the community labels Jun 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Contributed by the community data Ray Data-related issues docs An issue or change related to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant