Skip to content

Commit

Permalink
Merge pull request #141 from khaeru/issue/140
Browse files Browse the repository at this point in the history
Adjust for NumPy 2.0.0
  • Loading branch information
khaeru authored Aug 9, 2024
2 parents 061841f + 256c65a commit 18d3ec2
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 23 deletions.
8 changes: 0 additions & 8 deletions .github/workflows/pytest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,6 @@ jobs:
# from CI.
# - {version: "3.13.0-rc.1", extras: ""} # Development version

# Work around https://github.com/actions/setup-python/issues/696
exclude:
- {os: macos-latest, python: {version: "3.8", extras: ",sparse"}}
- {os: macos-latest, python: {version: "3.9", extras: ",sparse"}}
include:
- {os: macos-13, python: {version: "3.8", extras: ",sparse"}}
- {os: macos-13, python: {version: "3.9", extras: ",sparse"}}

fail-fast: false

runs-on: ${{ matrix.os }}
Expand Down
5 changes: 3 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.9.0
rev: v1.11.1
hooks:
- id: mypy
additional_dependencies:
Expand All @@ -9,6 +9,7 @@ repos:
- nbclient
- pint
- pytest
- requests-cache
- sdmx1
- Sphinx
- types-docutils
Expand All @@ -19,7 +20,7 @@ repos:
- xarray
args: []
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.1
rev: v0.5.7
hooks:
- id: ruff
- id: ruff-format
Expand Down
6 changes: 4 additions & 2 deletions doc/whatsnew.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
What's new
**********

.. Next release
.. ============
Next release
============

- genno is compatible and tested with `NumPy 2.0 <https://numpy.org/doc/stable/release/2.0.0-notes.html>`_, released 2024-06-16 (:issue:`140`, :pull:`141`).

v1.26.0 (2024-03-27)
====================
Expand Down
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
18 changes: 11 additions & 7 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 Expand Up @@ -1043,7 +1046,8 @@ def unique_units_from_dim(
assign = units[0]
else:
msg = (
f"Non-unique units {sorted(units)!r} for {type(qty).__name__} {qty.name!r}"
f"Non-unique units {sorted(map(str, units))!r} for {type(qty).__name__} "
+ repr(qty.name)
)
if fail == "raise":
raise ValueError(msg)
Expand Down
4 changes: 2 additions & 2 deletions genno/tests/core/test_computer.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,10 +429,10 @@ def test_require_compat():
c.require_compat("_test")

# Other forms
c.require_compat("genno.compat.pyam.operator")
c.require_compat("genno.compat.sdmx.operator")
assert 2 == len(c.modules)

import genno.compat.pyam.operator as mod
import genno.compat.sdmx.operator as mod

c.require_compat(mod)
assert 2 == len(c.modules)
Expand Down

0 comments on commit 18d3ec2

Please sign in to comment.