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 all 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
13 changes: 8 additions & 5 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 All @@ -31,7 +30,7 @@ class FrozenList(PandasObject, list):
# Side note: This has to be of type list. Otherwise,
# it messes up PyTables type checks.

def union(self, other):
def union(self, other) -> "FrozenList":
"""
Returns a FrozenList with other concatenated to the end of self.

Expand All @@ -49,7 +48,7 @@ def union(self, other):
other = list(other)
return type(self)(super().__add__(other))

def difference(self, other):
def difference(self, other) -> "FrozenList":
"""
Returns a FrozenList with elements from other removed from self.

Expand Down Expand Up @@ -101,7 +100,9 @@ def __hash__(self):
def _disabled(self, *args, **kwargs):
"""This method will not function because object is immutable."""
raise TypeError(
"'%s' does not support mutable operations." % self.__class__.__name__
"'{cls}' does not support mutable operations.".format(
cls=self.__class__.__name__
)
)

def __str__(self):
Expand Down Expand Up @@ -132,7 +133,9 @@ def __new__(cls, data, dtype=None, copy=False):

def _disabled(self, *args, **kwargs):
"""This method will not function because object is immutable."""
raise TypeError("'%s' does not support mutable operations." % self.__class__)
raise TypeError(
"'{cls}' does not support mutable operations.".format(cls=self.__class__)
)

__setitem__ = __setslice__ = __delitem__ = __delslice__ = _disabled
put = itemset = fill = _disabled
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