Skip to content

Commit

Permalink
Satisfy mypy 1.11.1
Browse files Browse the repository at this point in the history
Temporarily ignore safe-super errors (may be python/mypy#14757).
  • Loading branch information
khaeru committed Aug 9, 2024
1 parent f4b767b commit 65a807f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
4 changes: 2 additions & 2 deletions genno/core/attrseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def clip(
if pandas_version() < Version("2.1.0"):
return self._replace(pd.Series(self).clip(min, max))
else:
return super(pd.Series, self).clip(min, max)
return super().clip(min, max) # type: ignore [safe-super]

def drop(self, label):
"""Like :meth:`xarray.DataArray.drop`."""
Expand Down Expand Up @@ -610,7 +610,7 @@ def where(
raise NotImplementedError("where(…, drop=True)")
elif axis is not None or inplace is not False:
raise NotImplementedError("where(…, axis=…) or where(…, inplace=…)")
return super().where(cond, other)
return super().where(cond, other) # type: ignore [safe-super]

@property
def xindexes(self): # pragma: no cover
Expand Down
2 changes: 2 additions & 0 deletions genno/core/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,10 @@ def decorator(func: Callable) -> "Operator":
# which will skip documenting items that have the same __doc__ as their
# class
result = update_wrapper(klass(), func, updated=())
assert isinstance(result, Operator) # For mypy

if helper:
# Register the provided `helper` method for the class
result.helper(helper)

return result
Expand Down
15 changes: 9 additions & 6 deletions genno/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -946,15 +946,18 @@ def select(
coords = qty.coords
idx = dict()
for dim, labels in indexers.items():
s = is_scalar(labels)
# Check coords equal to (scalar) label or contained in (iterable of) labels
op1 = partial(operator.eq if s else operator.contains, labels)
# Take either 1 item (scalar label) or all (collection of labels)
ig = operator.itemgetter(0 if s else slice(None))
if is_scalar(labels):
# Check coords equal to scalar label
op1 = partial(operator.eq, labels)
# Take 1 item
item: Union[int, slice] = 0
else:
# Check coords contained in collection of labels; take all
op1, item = partial(operator.contains, set(labels)), slice(None)

try:
# Use only the values from `indexers` (not) appearing in `qty.coords`
idx[dim] = ig(list(filter(lambda x: op2(op1(x)), coords[dim].data)))
idx[dim] = list(filter(lambda x: op2(op1(x)), coords[dim].data))[item]
except IndexError:
raise KeyError(f"value {labels!r} not found in index {dim!r}")

Expand Down

0 comments on commit 65a807f

Please sign in to comment.