Skip to content

CLN: fix mypy warnings/errors #29327

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 5 commits into from
Nov 2, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
2 changes: 1 addition & 1 deletion pandas/core/groupby/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ def _get_axes(group):
return group.axes


def _is_indexed_like(obj, axes):
def _is_indexed_like(obj, axes) -> bool:
if isinstance(obj, Series):
if len(axes) > 1:
return False
Expand Down
7 changes: 3 additions & 4 deletions pandas/core/indexes/frozen.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
- .levels & .codes (FrozenNDArray)

"""

import warnings

import numpy as np
Expand Down Expand Up @@ -68,7 +67,7 @@ def difference(self, other):
return type(self)(temp)

# TODO: Consider deprecating these in favor of `union` (xref gh-15506)
__add__ = __iadd__ = union
__add__ = __iadd__ = union # type: ignore
Copy link
Member

Choose a reason for hiding this comment

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

The error now is essentially because union is unannotated, plus maybe a few more issues with subclass. In any case we should annotate instead of ignoring, especially since there's no rush on this one (current mypy in CI is still only 0.72)

Copy link
Member Author

Choose a reason for hiding this comment

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

sounds good, ill see if annotating union does the trick

Copy link
Member Author

Choose a reason for hiding this comment

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

looks like it worked for union, but not for _disabled. removed the "type: ignore"s


def __getitem__(self, n):
if isinstance(n, slice):
Expand Down Expand Up @@ -110,8 +109,8 @@ def __str__(self):
def __repr__(self):
return "%s(%s)" % (self.__class__.__name__, str(self))

__setitem__ = __setslice__ = __delitem__ = __delslice__ = _disabled
pop = append = extend = remove = sort = insert = _disabled
__setitem__ = __setslice__ = __delitem__ = __delslice__ = _disabled # type: ignore
pop = append = extend = remove = sort = insert = _disabled # type: ignore


class FrozenNDArray(PandasObject, np.ndarray):
Expand Down
33 changes: 17 additions & 16 deletions pandas/io/formats/css.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,23 @@ class CSSWarning(UserWarning):
pass


def _side_expander(prop_fmt: str):
def expand(self, prop, value):
tokens = value.split()
try:
mapping = self.SIDE_SHORTHANDS[len(tokens)]
except KeyError:
warnings.warn(
'Could not expand "{prop}: {val}"'.format(prop=prop, val=value),
CSSWarning,
)
return
for key, idx in zip(self.SIDES, mapping):
yield prop_fmt.format(key), tokens[idx]

return expand


class CSSResolver:
"""A callable for parsing and resolving CSS to atomic properties

Expand Down Expand Up @@ -213,22 +230,6 @@ def atomize(self, declarations):
}
SIDES = ("top", "right", "bottom", "left")

def _side_expander(prop_fmt):
def expand(self, prop, value):
tokens = value.split()
try:
mapping = self.SIDE_SHORTHANDS[len(tokens)]
except KeyError:
warnings.warn(
'Could not expand "{prop}: {val}"'.format(prop=prop, val=value),
CSSWarning,
)
return
for key, idx in zip(self.SIDES, mapping):
yield prop_fmt.format(key), tokens[idx]

return expand

expand_border_color = _side_expander("border-{:s}-color")
expand_border_style = _side_expander("border-{:s}-style")
expand_border_width = _side_expander("border-{:s}-width")
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/io/msgpack/test_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def default(obj):
typecode = 123 # application specific typecode
data = tobytes(obj)
return ExtType(typecode, data)
raise TypeError("Unknown type object {obj!r}".format(obj))
raise TypeError("Unknown type object {obj!r}".format(obj=obj))

def ext_hook(code, data):
print("ext_hook called", code, data)
Expand Down