Skip to content

MAINT: various backports and tweaks #146

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 1 commit into from
Feb 20, 2025
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
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
intersphinx_mapping = {
"python": ("https://docs.python.org/3", None),
"array-api": ("https://data-apis.org/array-api/draft", None),
"dask": ("https://docs.dask.org/en/stable", None),
"numpy": ("https://numpy.org/doc/stable", None),
"jax": ("https://jax.readthedocs.io/en/latest", None),
}
Expand Down
5,322 changes: 3,118 additions & 2,204 deletions pixi.lock
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ran pixi update. Notably this bumps dask to 2025.2.0.

Large diffs are not rendered by default.

11 changes: 1 addition & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,6 @@ markers = [

[tool.coverage]
run.source = ["array_api_extra"]
report.exclude_also = [
'\.\.\.',
'if TYPE_CHECKING:',
]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Caused large sections of code to be incorrectly skipped


# mypy

Expand Down Expand Up @@ -314,10 +310,5 @@ checks = [
"ES01", # most docstrings do not need an extended summary
]
exclude = [ # don't report on objects that match any of these regex
'.*test_at.*',
'.*test_funcs.*',
'.*test_testing.*',
'.*test_utils.*',
'.*test_version.*',
'.*test_vendor.*',
'.*test_*',
]
4 changes: 2 additions & 2 deletions src/array_api_extra/_lib/_at.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ def _op(
Right-hand side of the operation.
copy : bool or None
Whether to copy the input array. See the class docstring for details.
xp : array_namespace or None
The array namespace for the input array.
xp : array_namespace, optional
The array namespace for the input array. Default: infer.

Returns
-------
Expand Down
12 changes: 6 additions & 6 deletions src/array_api_extra/_lib/_utils/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
from typing import cast

from . import _compat
from ._compat import is_array_api_obj, is_numpy_array
from ._compat import array_namespace, is_array_api_obj, is_numpy_array
from ._typing import Array

__all__ = ["in1d", "mean"]
__all__ = ["asarrays", "in1d", "is_python_scalar", "mean"]


def in1d(
Expand All @@ -33,7 +33,7 @@ def in1d(
https://github.com/numpy/numpy/blob/v1.26.0/numpy/lib/arraysetops.py#L524-L758
"""
if xp is None:
xp = _compat.array_namespace(x1, x2)
xp = array_namespace(x1, x2)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: this causes coverage to fail, as this line isn't covered by unit tests


# This code is run to make the code significantly faster
if x2.shape[0] < 10 * x1.shape[0] ** 0.145:
Expand Down Expand Up @@ -84,7 +84,7 @@ def mean(
Complex mean, https://github.com/data-apis/array-api/issues/846.
"""
if xp is None:
xp = _compat.array_namespace(x)
xp = array_namespace(x)

if xp.isdtype(x.dtype, "complex floating"):
x_real = xp.real(x)
Expand Down Expand Up @@ -124,8 +124,8 @@ def asarrays(
----------
a, b : Array | int | float | complex | bool
Input arrays or scalars. At least one must be an array.
xp : ModuleType
The standard-compatible namespace for the returned arrays.
xp : array_namespace, optional
The standard-compatible namespace for `x`. Default: infer.

Returns
-------
Expand Down
3 changes: 2 additions & 1 deletion src/array_api_extra/_lib/_utils/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# To be changed to a Protocol later (see data-apis/array-api#589)
Array = Any # type: ignore[no-any-explicit]
Device = Any # type: ignore[no-any-explicit]
DType = Any # type: ignore[no-any-explicit]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

used by both #86 and #141

Index = Any # type: ignore[no-any-explicit]

__all__ = ["Array", "Device", "Index"]
__all__ = ["Array", "DType", "Device", "Index"]
4 changes: 2 additions & 2 deletions src/array_api_extra/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

__all__ = ["lazy_xp_function", "patch_lazy_xp_functions"]

if TYPE_CHECKING:
if TYPE_CHECKING: # pragma: no cover
# TODO move ParamSpec outside TYPE_CHECKING
# depends on scikit-learn abandoning Python 3.9
# https://github.com/scikit-learn/scikit-learn/pull/27910#issuecomment-2568023972
Expand Down Expand Up @@ -169,7 +169,7 @@ def xp(request, monkeypatch):
Pytest fixture, as acquired by the test itself or by one of its fixtures.
monkeypatch : pytest.MonkeyPatch
Pytest fixture, as acquired by the test itself or by one of its fixtures.
xp : module
xp : array_namespace
Array namespace to be tested.

See Also
Expand Down
18 changes: 16 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,11 @@ def xp(
if library == Backend.NUMPY_READONLY:
return NumPyReadOnly() # type: ignore[return-value] # pyright: ignore[reportReturnType]
xp = pytest.importorskip(library.value)
# Possibly wrap module with array_api_compat
xp = array_namespace(xp.empty(0))

# On Dask and JAX, monkey-patch all functions tagged by `lazy_xp_function`
# in the global scope of the module containing the test function.
patch_lazy_xp_functions(request, monkeypatch, xp=xp)

if library == Backend.JAX:
Expand All @@ -124,8 +128,18 @@ def xp(
# suppress unused-ignore to run mypy in -e lint as well as -e dev
jax.config.update("jax_enable_x64", True) # type: ignore[no-untyped-call,unused-ignore]

# Possibly wrap module with array_api_compat
return array_namespace(xp.empty(0))
return xp


@pytest.fixture(params=[Backend.DASK]) # Can select the test with `pytest -k dask`
def da(
request: pytest.FixtureRequest, monkeypatch: pytest.MonkeyPatch
) -> ModuleType: # numpydoc ignore=PR01,RT01
"""Variant of the `xp` fixture that only yields dask.array."""
xp = pytest.importorskip("dask.array")
xp = array_namespace(xp.empty(0))
patch_lazy_xp_functions(request, monkeypatch, xp=xp)
return xp
Comment on lines +134 to +142
Copy link
Contributor Author

Choose a reason for hiding this comment

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

used by both #86 and #141



@pytest.fixture
Expand Down
Loading