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

Conversation

simonjayhawkins
Copy link
Member

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

@simonjayhawkins simonjayhawkins added the Typing type annotations, mypy/pyright type checking label Oct 6, 2020
@simonjayhawkins simonjayhawkins added this to the 1.2 milestone Oct 6, 2020
@@ -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.

@jbrockmendel jbrockmendel merged commit 5bf4e7f into pandas-dev:master Oct 7, 2020
@jbrockmendel
Copy link
Member

thanks @simonjayhawkins

@simonjayhawkins simonjayhawkins deleted the core.groupby.ops branch October 7, 2020 15:45
kesmit13 pushed a commit to kesmit13/pandas that referenced this pull request Nov 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Typing type annotations, mypy/pyright type checking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants