-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
CLN: groupby #29626
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CLN: groupby #29626
Conversation
Hello @jbrockmendel! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found: There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻 Comment last updated at 2019-11-17 15:40:56 UTC |
pandas/core/groupby/generic.py
Outdated
def _aggregate_named(self, func, *args, **kwargs): | ||
result = OrderedDict() | ||
def _aggregate_named(self, func, *args, **kwargs) -> OrderedDict: | ||
result = OrderedDict() # type: OrderedDict |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can just be a dict now
pandas/core/groupby/generic.py
Outdated
@@ -377,8 +383,8 @@ def _get_index() -> Index: | |||
result = Series(data=values, index=_get_index(), name=self._selection_name) | |||
return self._reindex_output(result) | |||
|
|||
def _aggregate_named(self, func, *args, **kwargs): | |||
result = OrderedDict() | |||
def _aggregate_named(self, func, *args, **kwargs) -> dict: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use typing.Dict
instead of the built-in? Would also be great if you can identify key / value types if not too much incremental effort
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do. In cases where we can do Dict[foo, bar]
i get why that's better. In cases where we can't say anything meaningful, is it just for consistency or is there some other upside?
pandas/core/groupby/generic.py
Outdated
def _aggregate_named(self, func, *args, **kwargs): | ||
result = OrderedDict() | ||
def _aggregate_named(self, func, *args, **kwargs) -> Dict: | ||
result = {} # type: Dict |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can use the new style of typing now, e.g. result: Dict = {}
, though odd that mypy can't infer that. better to be even specific, Dict[str, ]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just FYI mypy will always complain for an empty container creation as it can't infer the subtypes
@@ -443,18 +449,16 @@ def transform(self, func, *args, **kwargs): | |||
result.index = self._selected_obj.index | |||
return result | |||
|
|||
def _transform_fast(self, func, func_nm) -> Series: | |||
def _transform_fast(self, func: Callable, func_nm: str) -> Series: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the arguments and/or return type of Callable
can be provided it is very helpful; not sure how much incremental effort that is
pandas/core/groupby/generic.py
Outdated
def _aggregate_named(self, func, *args, **kwargs): | ||
result = OrderedDict() | ||
def _aggregate_named(self, func, *args, **kwargs) -> Dict: | ||
result = {} # type: Dict |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just FYI mypy will always complain for an empty container creation as it can't infer the subtypes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that there are a few conflicts between this and #29124
@@ -1579,7 +1591,7 @@ def _insert_inaxis_grouper_inplace(self, result): | |||
if in_axis: | |||
result.insert(0, name, lev) | |||
|
|||
def _wrap_aggregated_output(self, output, names=None): | |||
def _wrap_aggregated_output(self, output: dict, names=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dict -> typing.Dict and ideally with subtypes if possible (here and below)
Closing in favor of #29124 |
splitting this off of branches that do non-CLN stuff