-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
CLN: OrderedDict -> Dict #30497
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: OrderedDict -> Dict #30497
Conversation
alimcmaster1
commented
Dec 27, 2019
- ref CLN: OrderedDict -> Dict #30469
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.
A few minor things but looks good overall
pandas/core/groupby/generic.py
Outdated
@@ -1119,7 +1119,7 @@ def _aggregate_frame(self, func, *args, **kwargs) -> DataFrame: | |||
axis = self.axis | |||
obj = self._obj_with_exclusions | |||
|
|||
result: OrderedDict = OrderedDict() | |||
result: 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.
We don't use the builtins for annotations, rather want to import Dict
from typing. Would be extra useful if you can figure out the subtypes that need to be added
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.
Sure - I ran the tests cases that touch this logic and think I've now got the right subtypes
pandas/core/groupby/generic.py
Outdated
@@ -1136,7 +1136,7 @@ def _aggregate_item_by_item(self, func, *args, **kwargs) -> DataFrame: | |||
# only for axis==0 | |||
|
|||
obj = self._obj_with_exclusions | |||
result: OrderedDict = OrderedDict() | |||
result: 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.
same comment
pandas/io/formats/html.py
Outdated
@@ -138,10 +137,10 @@ def _write_cell( | |||
else: | |||
start_tag = "<{kind}>".format(kind=kind) | |||
|
|||
esc: Union[OrderedDict[str, str], Dict] | |||
esc: Union[Dict[str, str], 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.
Arguably orthogonal but this is somewhat of a strange annotation - is it not always just Dict[str, 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.
This line can be removed now as it is no longer required to silence Incompatible types in assignment (expression has type "Dict[<nothing>, <nothing>]", variable has type "OrderedDict[str, 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.
Sure - removed
Ex @WillAyd's comments about typing, LGTM. |
Have all the typing comments been addressed? It seems like they have. |
@@ -1119,7 +1120,7 @@ def _aggregate_frame(self, func, *args, **kwargs) -> DataFrame: | |||
axis = self.axis | |||
obj = self._obj_with_exclusions | |||
|
|||
result: OrderedDict = OrderedDict() | |||
result: Dict[Union[int, str], Union[NDFrame, np.ndarray]] = {} |
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.
How is the key here a str
? I think just int to hold position no?
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.
Seems like there are cases where it can also be a string. (test_preserve_categories
in test_categorical.py
)
categories = list("abc")
df = DataFrame({"A": Categorical(list("ba"), categories=categories, ordered=True)})
df.groupby("A", sort=True, observed=False)
lgtm over to @WillAyd |
Thanks @alimcmaster1 |