From 1da1663196c95b3811ca84d9e335f32cfeb05e32 Mon Sep 17 00:00:00 2001 From: Ralf Gommers Date: Sun, 12 Mar 2023 22:01:22 +0000 Subject: MAINT: remove `NUMPY_EXPERIMENTAL_ARRAY_FUNCTION` env var As discussed in https://mail.python.org/archives/list/numpy-discussion@python.org/thread/UKZJACAP5FUG7KP2AQDPE4P5ADNWLOHZ/ This flag was always meant to be temporary, and cleaning it up is long overdue. --- numpy/lib/function_base.py | 33 ++++++++++++++++----------------- numpy/lib/shape_base.py | 8 -------- numpy/lib/tests/test_twodim_base.py | 11 ++--------- 3 files changed, 18 insertions(+), 34 deletions(-) (limited to 'numpy/lib') diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index 405790025..f0f374f97 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -4910,23 +4910,22 @@ def trapz(y, x=None, dx=1.0, axis=-1): return ret -if overrides.ARRAY_FUNCTION_ENABLED: - # If array-function is enabled (normal), we wrap everything into a C - # callable, which has no __code__ or other attributes normal Python funcs - # have. SciPy however, tries to "clone" `trapz` into a new Python function - # which requires `__code__` and a few other attributes. - # So we create a dummy clone and copy over its attributes allowing - # SciPy <= 1.10 to work: https://github.com/scipy/scipy/issues/17811 - assert not hasattr(trapz, "__code__") - - def _fake_trapz(y, x=None, dx=1.0, axis=-1): - return trapz(y, x=x, dx=dx, axis=axis) - - trapz.__code__ = _fake_trapz.__code__ - trapz.__globals__ = _fake_trapz.__globals__ - trapz.__defaults__ = _fake_trapz.__defaults__ - trapz.__closure__ = _fake_trapz.__closure__ - trapz.__kwdefaults__ = _fake_trapz.__kwdefaults__ +# __array_function__ has no __code__ or other attributes normal Python funcs we +# wrap everything into a C callable. SciPy however, tries to "clone" `trapz` +# into a new Python function which requires `__code__` and a few other +# attributes. So we create a dummy clone and copy over its attributes allowing +# SciPy <= 1.10 to work: https://github.com/scipy/scipy/issues/17811 +assert not hasattr(trapz, "__code__") + +def _fake_trapz(y, x=None, dx=1.0, axis=-1): + return trapz(y, x=x, dx=dx, axis=axis) + + +trapz.__code__ = _fake_trapz.__code__ +trapz.__globals__ = _fake_trapz.__globals__ +trapz.__defaults__ = _fake_trapz.__defaults__ +trapz.__closure__ = _fake_trapz.__closure__ +trapz.__kwdefaults__ = _fake_trapz.__kwdefaults__ def _meshgrid_dispatcher(*xi, copy=None, sparse=None, indexing=None): diff --git a/numpy/lib/shape_base.py b/numpy/lib/shape_base.py index 154faa1dd..5d8a41bfe 100644 --- a/numpy/lib/shape_base.py +++ b/numpy/lib/shape_base.py @@ -643,10 +643,6 @@ def column_stack(tup): [3, 4]]) """ - if not overrides.ARRAY_FUNCTION_ENABLED: - # reject non-sequences (and make tuple) - tup = _arrays_for_stack_dispatcher(tup) - arrays = [] for v in tup: arr = asanyarray(v) @@ -713,10 +709,6 @@ def dstack(tup): [[3, 4]]]) """ - if not overrides.ARRAY_FUNCTION_ENABLED: - # reject non-sequences (and make tuple) - tup = _arrays_for_stack_dispatcher(tup) - arrs = atleast_3d(*tup) if not isinstance(arrs, list): arrs = [arrs] diff --git a/numpy/lib/tests/test_twodim_base.py b/numpy/lib/tests/test_twodim_base.py index 141f508fd..eb008c600 100644 --- a/numpy/lib/tests/test_twodim_base.py +++ b/numpy/lib/tests/test_twodim_base.py @@ -4,20 +4,14 @@ from numpy.testing import ( assert_equal, assert_array_equal, assert_array_max_ulp, assert_array_almost_equal, assert_raises, assert_ - ) - +) from numpy import ( arange, add, fliplr, flipud, zeros, ones, eye, array, diag, histogram2d, tri, mask_indices, triu_indices, triu_indices_from, tril_indices, tril_indices_from, vander, - ) - +) import numpy as np - -from numpy.core.tests.test_overrides import requires_array_function - - import pytest @@ -283,7 +277,6 @@ class TestHistogram2d: assert_array_equal(H, answer) assert_array_equal(xe, array([0., 0.25, 0.5, 0.75, 1])) - @requires_array_function def test_dispatch(self): class ShouldDispatch: def __array_function__(self, function, types, args, kwargs): -- cgit v1.2.1