Skip to content

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

Merged
merged 13 commits into from
Jan 2, 2020
Merged

Conversation

alimcmaster1
Copy link
Member

@alimcmaster1 alimcmaster1 changed the title CLN: OrderedDict -> Dict WIP: CLN: OrderedDict -> Dict Dec 27, 2019
@alimcmaster1 alimcmaster1 changed the title WIP: CLN: OrderedDict -> Dict CLN: OrderedDict -> Dict Dec 27, 2019
Copy link
Member

@WillAyd WillAyd left a 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

@@ -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 = {}
Copy link
Member

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

Copy link
Member Author

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

@@ -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 = {}
Copy link
Member

Choose a reason for hiding this comment

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

same comment

@@ -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]
Copy link
Member

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]?

Copy link
Member

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]").

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure - removed

@jbrockmendel
Copy link
Member

Ex @WillAyd's comments about typing, LGTM.

@simonjayhawkins simonjayhawkins added this to the 1.0 milestone Dec 28, 2019
@alimcmaster1 alimcmaster1 requested a review from WillAyd December 31, 2019 17:28
@TomAugspurger
Copy link
Contributor

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]] = {}
Copy link
Member

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?

Copy link
Member Author

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)

@jreback
Copy link
Contributor

jreback commented Jan 1, 2020

lgtm over to @WillAyd

@WillAyd WillAyd merged commit 4168e0c into pandas-dev:master Jan 2, 2020
@WillAyd
Copy link
Member

WillAyd commented Jan 2, 2020

Thanks @alimcmaster1

@alimcmaster1 alimcmaster1 deleted the mcmali-dict-two branch January 2, 2020 07:45
@ShaharNaveh ShaharNaveh mentioned this pull request Apr 8, 2020
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants