Thanks to visit codestin.com
Credit goes to github.com

Skip to content

CLN Make _NumPyAPIWrapper naming consistent to _ArrayAPIWrapper #26039

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
Apr 2, 2023
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
10 changes: 5 additions & 5 deletions sklearn/utils/_array_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def take(self, X, indices, *, axis):
return self._namespace.stack(selected, axis=axis)


class _NumPyApiWrapper:
class _NumPyAPIWrapper:
"""Array API compat wrapper for any numpy version

NumPy < 1.22 does not expose the numpy.array_api namespace. This
Expand Down Expand Up @@ -98,7 +98,7 @@ def get_namespace(*arrays):
See: https://numpy.org/neps/nep-0047-array-api-standard.html

If `arrays` are regular numpy arrays, an instance of the
`_NumPyApiWrapper` compatibility wrapper is returned instead.
`_NumPyAPIWrapper` compatibility wrapper is returned instead.

Namespace support is not enabled by default. To enabled it
call:
Expand All @@ -110,7 +110,7 @@ def get_namespace(*arrays):
with sklearn.config_context(array_api_dispatch=True):
# your code here

Otherwise an instance of the `_NumPyApiWrapper`
Otherwise an instance of the `_NumPyAPIWrapper`
compatibility wrapper is always returned irrespective of
the fact that arrays implement the `__array_namespace__`
protocol or not.
Expand All @@ -133,7 +133,7 @@ def get_namespace(*arrays):
# Returns a tuple: (array_namespace, is_array_api)

if not get_config()["array_api_dispatch"]:
return _NumPyApiWrapper(), False
return _NumPyAPIWrapper(), False

namespaces = {
x.__array_namespace__() if hasattr(x, "__array_namespace__") else None
Expand All @@ -152,7 +152,7 @@ def get_namespace(*arrays):
(xp,) = namespaces
if xp is None:
# Use numpy as default
return _NumPyApiWrapper(), False
return _NumPyAPIWrapper(), False

return _ArrayAPIWrapper(xp), True

Expand Down
4 changes: 2 additions & 2 deletions sklearn/utils/tests/test_array_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from sklearn.base import BaseEstimator
from sklearn.utils._array_api import get_namespace
from sklearn.utils._array_api import _NumPyApiWrapper
from sklearn.utils._array_api import _NumPyAPIWrapper
from sklearn.utils._array_api import _ArrayAPIWrapper
from sklearn.utils._array_api import _asarray_with_order
from sklearn.utils._array_api import _convert_to_numpy
Expand All @@ -27,7 +27,7 @@ def test_get_namespace_ndarray():
with config_context(array_api_dispatch=array_api_dispatch):
xp_out, is_array_api = get_namespace(X_np)
assert not is_array_api
assert isinstance(xp_out, _NumPyApiWrapper)
assert isinstance(xp_out, _NumPyAPIWrapper)


def test_get_namespace_array_api():
Expand Down