-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
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
Changes from all commits
31b3c32
50e2678
5f38ee9
865e860
5120925
0e10726
9674c00
b9ed0c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
import copy | ||
from functools import partial | ||
from itertools import product | ||
from typing import Any, Callable, DefaultDict, Dict, List, Optional, Tuple | ||
from uuid import uuid1 | ||
|
||
import numpy as np | ||
|
@@ -21,10 +22,11 @@ | |
from pandas.core.dtypes.generic import ABCSeries | ||
|
||
import pandas as pd | ||
from pandas._typing import Axis, FrameOrSeries | ||
from pandas.api.types import is_dict_like, is_list_like | ||
import pandas.core.common as com | ||
from pandas.core.generic import _shared_docs | ||
from pandas.core.indexing import _maybe_numeric_slice, _non_reducing_slice | ||
from pandas.core.indexing import _IndexSlice, _maybe_numeric_slice, _non_reducing_slice | ||
|
||
jinja2 = import_optional_dependency("jinja2", extra="DataFrame.style requires jinja2.") | ||
|
||
|
@@ -47,6 +49,11 @@ def _mpl(func): | |
raise ImportError(no_mpl_message.format(func.__name__)) | ||
|
||
|
||
_ApplyArgs = Tuple[ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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] | ||
] | ||
|
||
|
||
class Styler: | ||
""" | ||
Helps style a DataFrame or Series according to the data with HTML and CSS. | ||
|
@@ -122,8 +129,8 @@ def __init__( | |
table_attributes=None, | ||
cell_ids=True, | ||
): | ||
self.ctx = defaultdict(list) | ||
self._todo = [] | ||
self.ctx = defaultdict(list) # type: DefaultDict[Tuple[int, int], List[str]] | ||
self._todo = [] # type: List[Tuple[Callable, _ApplyArgs, Dict[str, Any]]] | ||
|
||
if not isinstance(data, (pd.Series, pd.DataFrame)): | ||
raise TypeError("``data`` must be a Series or DataFrame") | ||
|
@@ -144,7 +151,7 @@ def __init__( | |
self.precision = precision | ||
self.table_attributes = table_attributes | ||
self.hidden_index = False | ||
self.hidden_columns = [] | ||
self.hidden_columns = [] # type: List[int] | ||
self.cell_ids = cell_ids | ||
|
||
# display_funcs maps (row, col) -> formatting function | ||
|
@@ -155,7 +162,9 @@ def default_display_func(x): | |
else: | ||
return x | ||
|
||
self._display_funcs = defaultdict(lambda: default_display_func) | ||
self._display_funcs = defaultdict( | ||
lambda: default_display_func | ||
) # type: DefaultDict[Tuple[int, int], Callable] | ||
|
||
def _repr_html_(self): | ||
""" | ||
|
@@ -244,7 +253,7 @@ def format_attr(pair): | |
idx_lengths = _get_level_lengths(self.index) | ||
col_lengths = _get_level_lengths(self.columns, hidden_columns) | ||
|
||
cell_context = dict() | ||
cell_context = dict() # type: Dict[str, Dict] | ||
|
||
n_rlvls = self.data.index.nlevels | ||
n_clvls = self.data.columns.nlevels | ||
|
@@ -626,7 +635,13 @@ def _apply(self, func, axis=0, subset=None, **kwargs): | |
self._update_ctx(result) | ||
return self | ||
|
||
def apply(self, func, axis=0, subset=None, **kwargs): | ||
def apply( | ||
self, | ||
func: Callable[[FrameOrSeries], FrameOrSeries], | ||
axis: Axis = 0, | ||
subset: Optional[_IndexSlice] = None, | ||
**kwargs | ||
) -> "Styler": | ||
""" | ||
Apply a function column-wise, row-wise, or table-wise, | ||
updating the HTML representation with the result. | ||
|
Uh oh!
There was an error while loading. Please reload this page.