8000 TYPING: check-untyped-defs for io.formats by simonjayhawkins · Pull Request #28129 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

TYPING: check-untyped-defs for io.formats #28129

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

Closed
wants to merge 8 commits into from
Closed
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
Prev Previous commit
Next Next commit
move aliases
  • Loading branch information
simonjayhawkins committed Aug 25, 2019
commit 50e26785f145d722bf983603c6772ac0cfc29b06
12 changes: 8 additions & 4 deletions pandas/io/formats/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,9 @@
from pandas.core.generic import _shared_docs
from pandas.core.indexing import _IndexSlice, _maybe_numeric_slice, _non_reducing_slice

ApplyArgs = Tuple[Callable[[FrameOrSeries], FrameOrSeries], Axis, Optional[_IndexSlice]]
Kwargs = Dict[str, Any]

jinja2 = import_optional_dependency("jinja2", extra="DataFrame.style requires jinja2.")


try:
import matplotlib.pyplot as plt
from matplotlib import colors
Expand All @@ -51,6 +49,12 @@ def _mpl(func):
raise ImportError(no_mpl_message.format(func.__name__))


_ApplyArgs = Tuple[
Copy link
Member

Choose a reason for hiding this comment

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

I assume this is a function of the code itself and not necessarily the annotation, but I find this pretty tough to digest. Is it documented already somewhere how this works? If not can you comment?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd rather not in this pass. I don't know this module well enough yet.

This pass is just check-untyped-defs as "Working through this flag in advance may lead to less surprises as annotations are added" xref #27568

Also the sooner we resolve these issues, the sooner we can enable this setting in CI to ensure that code modified in functions without annotations is checked for PRs.

Callable[[FrameOrSeries], FrameOrSeries], Axis, Optional[_IndexSlice]
]
_Kwargs = Dict[str, Any]
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we should create this for Args and Kwargs. Doesn't PEP 484 have a different way of handling anyway?

https://www.python.org/dev/peps/pep-0484/#arbitrary-argument-lists-and-default-argument-values

Copy link
Member Author

Choose a reason for hiding this comment

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

The Kwargs alias is not for annotating kwargs in function signiture. The kwargs dict is stored in a local variable. I appreciate this could be confusing.

It was to make self._todo = [] # type: List[Tuple[Callable, _ApplyArgs, _Kwargs]] more readable.

i'll inline _Kwargs to avoid this confusion.



class Styler:
"""
Helps style a DataFrame or Series according to the data with HTML and CSS.
Expand Down Expand Up @@ -127,7 +131,7 @@ def __init__(
cell_ids=True,
):
self.ctx = defaultdict(list) # type: DefaultDict[Tuple[int, int], List[str]]
self._todo = [] # type: List[Tuple[Callable, ApplyArgs, Kwargs]]
self._todo = [] # type: List[Tuple[Callable, _ApplyArgs, _Kwargs]]

if not isinstance(data, (pd.Series, pd.DataFrame)):
raise TypeError("``data`` must be a Series or DataFrame")
Expand Down
0