Skip to content

Commit 8785442

Browse files
remove numpy 1 support (#119)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 71d0331 commit 8785442

File tree

14 files changed

+58
-60
lines changed

14 files changed

+58
-60
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ repos:
66
- id: trailing-whitespace
77
- id: no-commit-to-branch
88
- repo: https://github.com/astral-sh/ruff-pre-commit
9-
rev: v0.12.12
9+
rev: v0.13.0
1010
hooks:
1111
- id: ruff-check
1212
args: [--fix, --exit-non-zero-on-fix]

docs/conf.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@
8585
source_directory="docs/",
8686
)
8787

88-
_np_aliases = {"bool_": "bool"}
8988
_np_nocls = {"float64": "attr"}
9089
_optional_types = {
9190
"CupyArray": "cupy.ndarray",
@@ -111,7 +110,7 @@ def find_type_alias(name: str) -> tuple[str, str, str | None] | tuple[None, None
111110
return "class", path, None
112111
return "data", f"fast_array_utils.{name}", None
113112
if name.startswith("np."):
114-
name = _np_aliases.get(name[3:], name[3:])
113+
name = name.removeprefix("np.")
115114
return _np_nocls.get(name, "class"), f"numpy.{name}", f"np.{name}"
116115
if name in npt.__all__:
117116
return "data", f"numpy.typing.{name}", None

pyproject.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ classifiers = [
2424
"Programming Language :: Python :: 3.13",
2525
]
2626
dynamic = [ "description", "readme", "version" ]
27-
dependencies = [ "numpy>=1.25.2" ]
27+
dependencies = [ "numpy>=2" ]
2828
optional-dependencies.accel = [ "numba>=0.57" ]
29+
optional-dependencies.dask = [ "dask>=2023.6.1" ]
2930
optional-dependencies.doc = [
3031
"furo>=2024.8.6",
3132
"pytest>=8.4",
@@ -34,7 +35,7 @@ optional-dependencies.doc = [
3435
"sphinx-autodoc-typehints>=3.2",
3536
"sphinx-autofixture>=0.4.1",
3637
]
37-
optional-dependencies.full = [ "dask", "fast-array-utils[accel,sparse]", "h5py", "zarr" ]
38+
optional-dependencies.full = [ "fast-array-utils[accel,dask,sparse]", "h5py", "zarr" ]
3839
optional-dependencies.sparse = [ "scipy>=1.11" ]
3940
optional-dependencies.test = [
4041
"anndata",
@@ -99,7 +100,7 @@ overrides.matrix.resolution.features = [
99100
]
100101
overrides.matrix.resolution.dependencies = [
101102
# TODO: move to min dep once this is fixed: https://github.com/tlambert03/hatch-min-requirements/issues/5
102-
{ if = [ "lowest" ], value = "dask==2023.5.1" },
103+
{ if = [ "lowest" ], value = "dask==2023.6.1" },
103104
]
104105

105106
[[tool.hatch.envs.hatch-test.matrix]]
@@ -144,13 +145,12 @@ lint.per-file-ignores."typings/**/*.pyi" = [ "A002", "F403", "F405", "N801" ] #
144145
lint.allowed-confusables = [ "×", "" ]
145146
lint.flake8-bugbear.extend-immutable-calls = [ "testing.fast_array_utils.Flags" ]
146147
lint.flake8-copyright.notice-rgx = "SPDX-License-Identifier: MPL-2\\.0"
147-
lint.flake8-tidy-imports.banned-api."numpy.bool".msg = "Use `np.bool_` instead for numpy>=1.24<2 compatibility"
148148
lint.flake8-type-checking.exempt-modules = [ ]
149149
lint.flake8-type-checking.strict = true
150150
lint.isort.known-first-party = [ "fast_array_utils" ]
151151
lint.isort.lines-after-imports = 2
152-
lint.isort.required-imports = [ "from __future__ import annotations" ]
153152
lint.pydocstyle.convention = "numpy"
153+
lint.future-annotations = true
154154

155155
[tool.pytest.ini_options]
156156
addopts = [

src/fast_array_utils/stats/__init__.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,19 @@
2929
@overload
3030
def is_constant(x: NDArray[Any] | types.CSBase | types.CupyArray, /, *, axis: None = None) -> bool: ...
3131
@overload
32-
def is_constant(x: NDArray[Any] | types.CSBase, /, *, axis: Literal[0, 1]) -> NDArray[np.bool_]: ...
32+
def is_constant(x: NDArray[Any] | types.CSBase, /, *, axis: Literal[0, 1]) -> NDArray[np.bool]: ...
3333
@overload
3434
def is_constant(x: types.CupyArray, /, *, axis: Literal[0, 1]) -> types.CupyArray: ...
3535
@overload
36-
def is_constant(x: types.DaskArray, /, *, axis: Literal[0, 1, None] = None) -> types.DaskArray: ...
36+
def is_constant(x: types.DaskArray, /, *, axis: Literal[0, 1] | None = None) -> types.DaskArray: ...
3737

3838

3939
def is_constant(
4040
x: NDArray[Any] | types.CSBase | types.CupyArray | types.DaskArray,
4141
/,
4242
*,
43-
axis: Literal[0, 1, None] = None,
44-
) -> bool | NDArray[np.bool_] | types.CupyArray | types.DaskArray:
43+
axis: Literal[0, 1] | None = None,
44+
) -> bool | NDArray[np.bool] | types.CupyArray | types.DaskArray:
4545
"""Check whether values in array are constant.
4646
4747
Parameters
@@ -80,7 +80,7 @@ def is_constant(
8080
# TODO(flying-sheep): support CSDataset (TODO)
8181
# https://github.com/scverse/fast-array-utils/issues/52
8282
@overload
83-
def mean(x: CpuArray | GpuArray | DiskArray, /, *, axis: Literal[None] = None, dtype: DTypeLike | None = None) -> np.number[Any]: ...
83+
def mean(x: CpuArray | GpuArray | DiskArray, /, *, axis: None = None, dtype: DTypeLike | None = None) -> np.number[Any]: ...
8484
@overload
8585
def mean(x: CpuArray | DiskArray, /, *, axis: Literal[0, 1], dtype: DTypeLike | None = None) -> NDArray[np.number[Any]]: ...
8686
@overload
@@ -93,7 +93,7 @@ def mean(
9393
x: CpuArray | GpuArray | DiskArray | types.DaskArray,
9494
/,
9595
*,
96-
axis: Literal[0, 1, None] = None,
96+
axis: Literal[0, 1] | None = None,
9797
dtype: DTypeLike | None = None,
9898
) -> NDArray[np.number[Any]] | types.CupyArray | np.number[Any] | types.DaskArray:
9999
"""Mean over both or one axis.
@@ -131,24 +131,24 @@ def mean(
131131
from ._mean import mean_
132132

133133
validate_axis(x.ndim, axis)
134-
return mean_(x, axis=axis, dtype=dtype) # type: ignore[no-any-return] # literally the same type, wtf mypy
134+
return mean_(x, axis=axis, dtype=dtype)
135135

136136

137137
@overload
138-
def mean_var(x: CpuArray | GpuArray, /, *, axis: Literal[None] = None, correction: int = 0) -> tuple[np.float64, np.float64]: ...
138+
def mean_var(x: CpuArray | GpuArray, /, *, axis: None = None, correction: int = 0) -> tuple[np.float64, np.float64]: ...
139139
@overload
140140
def mean_var(x: CpuArray, /, *, axis: Literal[0, 1], correction: int = 0) -> tuple[NDArray[np.float64], NDArray[np.float64]]: ...
141141
@overload
142142
def mean_var(x: GpuArray, /, *, axis: Literal[0, 1], correction: int = 0) -> tuple[types.CupyArray, types.CupyArray]: ...
143143
@overload
144-
def mean_var(x: types.DaskArray, /, *, axis: Literal[0, 1, None] = None, correction: int = 0) -> tuple[types.DaskArray, types.DaskArray]: ...
144+
def mean_var(x: types.DaskArray, /, *, axis: Literal[0, 1] | None = None, correction: int = 0) -> tuple[types.DaskArray, types.DaskArray]: ...
145145

146146

147147
def mean_var(
148148
x: CpuArray | GpuArray | types.DaskArray,
149149
/,
150150
*,
151-
axis: Literal[0, 1, None] = None,
151+
axis: Literal[0, 1] | None = None,
152152
correction: int = 0,
153153
) -> (
154154
tuple[np.float64, np.float64]
@@ -218,14 +218,14 @@ def sum(x: GpuArray, /, *, axis: Literal[0, 1], dtype: DTypeLike | None = None,
218218

219219

220220
@overload
221-
def sum(x: types.DaskArray, /, *, axis: Literal[0, 1, None] = None, dtype: DTypeLike | None = None, keep_cupy_as_array: bool = False) -> types.DaskArray: ...
221+
def sum(x: types.DaskArray, /, *, axis: Literal[0, 1] | None = None, dtype: DTypeLike | None = None, keep_cupy_as_array: bool = False) -> types.DaskArray: ...
222222

223223

224224
def sum(
225225
x: CpuArray | GpuArray | DiskArray | types.DaskArray,
226226
/,
227227
*,
228-
axis: Literal[0, 1, None] = None,
228+
axis: Literal[0, 1] | None = None,
229229
dtype: DTypeLike | None = None,
230230
keep_cupy_as_array: bool = False,
231231
) -> NDArray[Any] | types.CupyArray | np.number[Any] | types.DaskArray:

src/fast_array_utils/stats/_is_constant.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ def is_constant_(
2424
a: NDArray[Any] | types.CSBase | types.CupyArray | types.DaskArray,
2525
/,
2626
*,
27-
axis: Literal[0, 1, None] = None,
28-
) -> bool | NDArray[np.bool_] | types.CupyArray | types.DaskArray: # pragma: no cover
27+
axis: Literal[0, 1] | None = None,
28+
) -> bool | NDArray[np.bool] | types.CupyArray | types.DaskArray: # pragma: no cover
2929
raise NotImplementedError
3030

3131

3232
@is_constant_.register(np.ndarray | types.CupyArray)
33-
def _is_constant_ndarray(a: NDArray[Any] | types.CupyArray, /, *, axis: Literal[0, 1, None] = None) -> bool | NDArray[np.bool_] | types.CupyArray:
33+
def _is_constant_ndarray(a: NDArray[Any] | types.CupyArray, /, *, axis: Literal[0, 1] | None = None) -> bool | NDArray[np.bool] | types.CupyArray:
3434
# Should eventually support nd, not now.
3535
match axis:
3636
case None:
@@ -41,13 +41,13 @@ def _is_constant_ndarray(a: NDArray[Any] | types.CupyArray, /, *, axis: Literal[
4141
return _is_constant_rows(a)
4242

4343

44-
def _is_constant_rows(a: NDArray[Any] | types.CupyArray) -> NDArray[np.bool_] | types.CupyArray:
44+
def _is_constant_rows(a: NDArray[Any] | types.CupyArray) -> NDArray[np.bool] | types.CupyArray:
4545
b = np.broadcast_to(a[:, 0][:, np.newaxis], a.shape)
46-
return cast("NDArray[np.bool_]", (a == b).all(axis=1))
46+
return cast("NDArray[np.bool]", (a == b).all(axis=1))
4747

4848

4949
@is_constant_.register(types.CSBase)
50-
def _is_constant_cs(a: types.CSBase, /, *, axis: Literal[0, 1, None] = None) -> bool | NDArray[np.bool_]:
50+
def _is_constant_cs(a: types.CSBase, /, *, axis: Literal[0, 1] | None = None) -> bool | NDArray[np.bool]:
5151
from . import is_constant
5252

5353
if len(a.shape) == 1: # pragma: no cover
@@ -68,9 +68,9 @@ def _is_constant_cs(a: types.CSBase, /, *, axis: Literal[0, 1, None] = None) ->
6868

6969

7070
@numba.njit(cache=True)
71-
def _is_constant_cs_major(a: types.CSBase, shape: tuple[int, int]) -> NDArray[np.bool_]:
71+
def _is_constant_cs_major(a: types.CSBase, shape: tuple[int, int]) -> NDArray[np.bool]:
7272
n = len(a.indptr) - 1
73-
result = np.ones(n, dtype=np.bool_)
73+
result = np.ones(n, dtype=np.bool)
7474
for i in numba.prange(n):
7575
start = a.indptr[i]
7676
stop = a.indptr[i + 1]
@@ -83,13 +83,13 @@ def _is_constant_cs_major(a: types.CSBase, shape: tuple[int, int]) -> NDArray[np
8383

8484

8585
@is_constant_.register(types.DaskArray)
86-
def _is_constant_dask(a: types.DaskArray, /, *, axis: Literal[0, 1, None] = None) -> types.DaskArray:
86+
def _is_constant_dask(a: types.DaskArray, /, *, axis: Literal[0, 1] | None = None) -> types.DaskArray:
8787
import dask.array as da
8888

8989
from . import is_constant
9090

9191
if axis is not None:
92-
return da.map_blocks(partial(is_constant, axis=axis), a, drop_axis=axis, meta=np.array([], dtype=np.bool_))
92+
return da.map_blocks(partial(is_constant, axis=axis), a, drop_axis=axis, meta=np.array([], dtype=np.bool))
9393

9494
rv = (
9595
(a == a[0, 0].compute()).all()

src/fast_array_utils/stats/_mean.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# SPDX-License-Identifier: MPL-2.0
22
from __future__ import annotations
33

4-
from typing import TYPE_CHECKING, no_type_check
4+
from typing import TYPE_CHECKING
55

66
import numpy as np
77

@@ -17,14 +17,13 @@
1717
from ..typing import CpuArray, DiskArray, GpuArray
1818

1919

20-
@no_type_check # mypy is very confused
2120
def mean_(
2221
x: CpuArray | GpuArray | DiskArray | types.DaskArray,
2322
/,
2423
*,
25-
axis: Literal[0, 1, None] = None,
24+
axis: Literal[0, 1] | None = None,
2625
dtype: DTypeLike | None = None,
2726
) -> NDArray[np.number[Any]] | np.number[Any] | types.DaskArray:
2827
total = sum_(x, axis=axis, dtype=dtype)
2928
n = np.prod(x.shape) if axis is None else x.shape[axis]
30-
return total / n
29+
return total / n # type: ignore[call-overload,operator,return-value]

src/fast_array_utils/stats/_mean_var.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def mean_var_(
2323
x: CpuArray | GpuArray | types.DaskArray,
2424
/,
2525
*,
26-
axis: Literal[0, 1, None] = None,
26+
axis: Literal[0, 1] | None = None,
2727
correction: int = 0,
2828
) -> (
2929
tuple[NDArray[np.float64], NDArray[np.float64]]

src/fast_array_utils/stats/_sum.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@
1717

1818
from ..typing import CpuArray, DiskArray, GpuArray
1919

20-
ComplexAxis: TypeAlias = tuple[Literal[0], Literal[1]] | tuple[Literal[0, 1]] | Literal[0, 1, None]
20+
ComplexAxis: TypeAlias = tuple[Literal[0], Literal[1]] | tuple[Literal[0, 1]] | Literal[0, 1] | None
2121

2222

2323
@singledispatch
2424
def sum_(
2525
x: CpuArray | GpuArray | DiskArray | types.DaskArray,
2626
/,
2727
*,
28-
axis: Literal[0, 1, None] = None,
28+
axis: Literal[0, 1] | None = None,
2929
dtype: DTypeLike | None = None,
3030
keep_cupy_as_array: bool = False,
3131
) -> NDArray[Any] | np.number[Any] | types.CupyArray | types.DaskArray:
@@ -43,7 +43,7 @@ def _sum_cupy(
4343
x: GpuArray,
4444
/,
4545
*,
46-
axis: Literal[0, 1, None] = None,
46+
axis: Literal[0, 1] | None = None,
4747
dtype: DTypeLike | None = None,
4848
keep_cupy_as_array: bool = False,
4949
) -> types.CupyArray | np.number[Any]:
@@ -56,7 +56,7 @@ def _sum_cs(
5656
x: types.CSBase,
5757
/,
5858
*,
59-
axis: Literal[0, 1, None] = None,
59+
axis: Literal[0, 1] | None = None,
6060
dtype: DTypeLike | None = None,
6161
keep_cupy_as_array: bool = False,
6262
) -> NDArray[Any] | np.number[Any]:
@@ -76,7 +76,7 @@ def _sum_dask(
7676
x: types.DaskArray,
7777
/,
7878
*,
79-
axis: Literal[0, 1, None] = None,
79+
axis: Literal[0, 1] | None = None,
8080
dtype: DTypeLike | None = None,
8181
keep_cupy_as_array: bool = False,
8282
) -> types.DaskArray:
@@ -129,7 +129,7 @@ def sum_dask_inner(
129129
return cast("NDArray[Any] | types.CupyArray", rv.reshape(shape))
130130

131131

132-
def normalize_axis(axis: ComplexAxis, ndim: int) -> Literal[0, 1, None]:
132+
def normalize_axis(axis: ComplexAxis, ndim: int) -> Literal[0, 1] | None:
133133
"""Adapt `axis` parameter passed by Dask to what we support."""
134134
match axis:
135135
case int() | None:
@@ -145,7 +145,7 @@ def normalize_axis(axis: ComplexAxis, ndim: int) -> Literal[0, 1, None]:
145145
return axis
146146

147147

148-
def get_shape(a: NDArray[Any] | np.number[Any] | types.CupyArray, *, axis: Literal[0, 1, None], keepdims: bool) -> tuple[int] | tuple[int, int]:
148+
def get_shape(a: NDArray[Any] | np.number[Any] | types.CupyArray, *, axis: Literal[0, 1] | None, keepdims: bool) -> tuple[int] | tuple[int, int]:
149149
"""Get the output shape of an axis-flattening operation."""
150150
match keepdims, a.ndim:
151151
case False, 0:

0 commit comments

Comments
 (0)