Skip to content

Commit

Permalink
GroupBy.agg: Return dict[Hashable, Any]
Browse files Browse the repository at this point in the history
Change return type annotation of GroupBy.agg() from dict[Any, Any] to dict[Hashable, Any]
  • Loading branch information
EwoutH committed Sep 19, 2024
1 parent d77c5b6 commit 817b532
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions mesa/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import warnings
import weakref
from collections import defaultdict
from collections.abc import Callable, Iterable, Iterator, MutableSet, Sequence
from collections.abc import Callable, Hashable, Iterable, Iterator, MutableSet, Sequence
from random import Random

# mypy
Expand Down Expand Up @@ -620,7 +620,7 @@ def count(self) -> dict[Any, int]:
"""
return {k: len(v) for k, v in self.groups.items()}

def agg(self, attr_name: str, func: Callable) -> dict[Any, Any]:
def agg(self, attr_name: str, func: Callable) -> dict[Hashable, Any]:
"""
Aggregate the values of a specific attribute across each group using the provided function.
Expand All @@ -629,7 +629,7 @@ def agg(self, attr_name: str, func: Callable) -> dict[Any, Any]:
func (Callable): The function to apply (e.g., sum, min, max, mean).
Returns:
dict: A dictionary mapping group names to the result of applying the aggregation function.
dict[Hashable, Any]: A dictionary mapping group names to the result of applying the aggregation function.
"""
return {
group_name: func([getattr(agent, attr_name) for agent in group])
Expand Down

0 comments on commit 817b532

Please sign in to comment.