Skip to content

TYP: check_untyped_defs core.groupby.ops #36921

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 2 commits into from
Oct 7, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pandas/core/groupby/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"""

import collections
from typing import List, Optional, Sequence, Tuple, Type
from typing import Generic, List, Optional, Sequence, Tuple, Type

import numpy as np

Expand Down Expand Up @@ -866,7 +866,7 @@ def _is_indexed_like(obj, axes, axis: int) -> bool:
# Splitting / application


class DataSplitter:
Copy link
Member

Choose a reason for hiding this comment

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

does this allow us to be more specific in _get_sorted_data or _chop below?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, in general if the return type of a method is dependant on self.data and using the FrameOrSeries TypeVar.

we covered this before #29456 (review)

Copy link
Member

Choose a reason for hiding this comment

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

i guess more specific: is it worth doing that here?

Copy link
Member Author

@simonjayhawkins simonjayhawkins Oct 7, 2020

Choose a reason for hiding this comment

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

I think so, but the subsequent changes proved controversial last time.

atm. This PR just 'ties' the output of _get_sorted_data which is typed with the FrameOrSeries TypeVar with self.data.

hence 'Revealed type is 'FrameOrSeries`1' for sdata

and mypy no longer reports pandas\core\groupby\ops.py:889: error: Need type annotation for 'sdata' [var-annotated]

the return type of _get_sorted_data is the same as self.data.take. And Series.take returns a Series and DataFrame.take returns a DataFrame. (i.e. same type as caller)

(As an aside, take is defined in NDFrame and Series and similar for other indexing methods. What's the policy regarding method placement? Could they be moved from NDFrame to DataFrame if overridden in Series?)

will circle back round to this (if not merged b4) and add a commit with some more types to take advantage of making DataSplitter generic. If too controversial, can always roll back.

class DataSplitter(Generic[FrameOrSeries]):
def __init__(self, data: FrameOrSeries, labels, ngroups: int, axis: int = 0):
self.data = data
self.labels = ensure_int64(labels)
Expand Down
3 changes: 0 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,6 @@ check_untyped_defs=False
[mypy-pandas.core.groupby.grouper]
check_untyped_defs=False

[mypy-pandas.core.groupby.ops]
check_untyped_defs=False

[mypy-pandas.core.indexes.base]
check_untyped_defs=False

Expand Down