Skip to content

TYP: define subset arg in Styler #41433

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 4 commits into from
May 17, 2021
Merged

Conversation

attack68
Copy link
Contributor

This works but someone with more knowledge might be able to point out a better definition of the type for Subset,

i.e. here Subset = Union[slice, Sequence, Index]

It types all the subset args in Styler

@jreback jreback added Styler conditional formatting using DataFrame.style Typing type annotations, mypy/pyright type checking labels May 12, 2021
@jreback jreback added this to the 1.3 milestone May 12, 2021
@jreback
Copy link
Contributor

jreback commented May 12, 2021

cc @simonjayhawkins if any comments

slice_ = [part if pred(part) else [part] for part in slice_]
# error: Item "slice" of "Union[slice, Sequence[Any]]" has no attribute
# "__iter__" (not iterable) -> is specifically list_like in conditional
slice_ = [p if pred(p) else [p] for p in slice_] # type: ignore[union-attr]
Copy link
Contributor

Choose a reason for hiding this comment

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

if you return this directly it should work (as you are re-assigning to a different type)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it wasnt the reassignment it was the fact that slice_ is not always considered to be iterable inside the loop comprehension. Albeit in this clause we have already checked that it is list_like so is iterable here...

@jreback jreback merged commit 72af5b0 into pandas-dev:master May 17, 2021
@jreback
Copy link
Contributor

jreback commented May 17, 2021

thanks @attack68

if you can create a followon issue to try to integrate this to the rest of pandas; e.g. move Subset to _typing and then use it in .dropna, and so on (e.g. where ever we use a subset argument), may need to add a todo list

@simonjayhawkins
Copy link
Member

This works but someone with more knowledge might be able to point out a better definition of the type for Subset,

would/could/should this be the same as PositionalIndexer in pandas._typing

TLouf pushed a commit to TLouf/pandas that referenced this pull request Jun 1, 2021
Co-authored-by: JHM Darbyshire (iMac) <[email protected]>
JulianWgs pushed a commit to JulianWgs/pandas that referenced this pull request Jul 3, 2021
Co-authored-by: JHM Darbyshire (iMac) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Styler conditional formatting using DataFrame.style Typing type annotations, mypy/pyright type checking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants