9
9
TYPE_CHECKING ,
10
10
Any ,
11
11
Callable ,
12
- DefaultDict ,
13
12
Literal ,
14
13
cast ,
15
14
)
63
62
Generator ,
64
63
Hashable ,
65
64
Iterable ,
65
+ MutableMapping ,
66
66
Sequence ,
67
67
)
68
68
@@ -1642,7 +1642,7 @@ def transform(self):
1642
1642
1643
1643
def reconstruct_func (
1644
1644
func : AggFuncType | None , ** kwargs
1645
- ) -> tuple [bool , AggFuncType , list [str ] | None , npt .NDArray [np .intp ] | None ]:
1645
+ ) -> tuple [bool , AggFuncType , tuple [str , ... ] | None , npt .NDArray [np .intp ] | None ]:
1646
1646
"""
1647
1647
This is the internal function to reconstruct func given if there is relabeling
1648
1648
or not and also normalize the keyword to get new order of columns.
@@ -1668,7 +1668,7 @@ def reconstruct_func(
1668
1668
-------
1669
1669
relabelling: bool, if there is relabelling or not
1670
1670
func: normalized and mangled func
1671
- columns: list of column names
1671
+ columns: tuple of column names
1672
1672
order: array of columns indices
1673
1673
1674
1674
Examples
@@ -1680,7 +1680,7 @@ def reconstruct_func(
1680
1680
(False, 'min', None, None)
1681
1681
"""
1682
1682
relabeling = func is None and is_multi_agg_with_relabel (** kwargs )
1683
- columns : list [str ] | None = None
1683
+ columns : tuple [str , ... ] | None = None
1684
1684
order : npt .NDArray [np .intp ] | None = None
1685
1685
1686
1686
if not relabeling :
@@ -1696,7 +1696,14 @@ def reconstruct_func(
1696
1696
raise TypeError ("Must provide 'func' or tuples of '(column, aggfunc)." )
1697
1697
1698
1698
if relabeling :
1699
- func , columns , order = normalize_keyword_aggregation (kwargs )
1699
+ # error: Incompatible types in assignment (expression has type
1700
+ # "MutableMapping[Hashable, list[Callable[..., Any] | str]]", variable has type
1701
+ # "Callable[..., Any] | str | list[Callable[..., Any] | str] |
1702
+ # MutableMapping[Hashable, Callable[..., Any] | str | list[Callable[..., Any] |
1703
+ # str]] | None")
1704
+ func , columns , order = normalize_keyword_aggregation ( # type: ignore[assignment]
1705
+ kwargs
1706
+ )
1700
1707
assert func is not None
1701
1708
1702
1709
return relabeling , func , columns , order
@@ -1730,7 +1737,11 @@ def is_multi_agg_with_relabel(**kwargs) -> bool:
1730
1737
1731
1738
def normalize_keyword_aggregation (
1732
1739
kwargs : dict ,
1733
- ) -> tuple [dict , list [str ], npt .NDArray [np .intp ]]:
1740
+ ) -> tuple [
1741
+ MutableMapping [Hashable , list [AggFuncTypeBase ]],
1742
+ tuple [str , ...],
1743
+ npt .NDArray [np .intp ],
1744
+ ]:
1734
1745
"""
1735
1746
Normalize user-provided "named aggregation" kwargs.
1736
1747
Transforms from the new ``Mapping[str, NamedAgg]`` style kwargs
@@ -1744,7 +1755,7 @@ def normalize_keyword_aggregation(
1744
1755
-------
1745
1756
aggspec : dict
1746
1757
The transformed kwargs.
1747
- columns : List [str]
1758
+ columns : tuple [str, ... ]
1748
1759
The user-provided keys.
1749
1760
col_idx_order : List[int]
1750
1761
List of columns indices.
@@ -1759,9 +1770,7 @@ def normalize_keyword_aggregation(
1759
1770
# Normalize the aggregation functions as Mapping[column, List[func]],
1760
1771
# process normally, then fixup the names.
1761
1772
# TODO: aggspec type: typing.Dict[str, List[AggScalar]]
1762
- # May be hitting https://github.com/python/mypy/issues/5958
1763
- # saying it doesn't have an attribute __name__
1764
- aggspec : DefaultDict = defaultdict (list )
1773
+ aggspec = defaultdict (list )
1765
1774
order = []
1766
1775
columns , pairs = list (zip (* kwargs .items ()))
1767
1776
0 commit comments