8000 Merge pull request #23861 from seberg/np2-cleanup · numpy/numpy@8a38a79 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8a38a79

Browse files
authored
Merge pull request #23861 from seberg/np2-cleanup
MAINT: Remove all "NumPy 2" as that should be main now
2 parents e6088dc + 4941977 commit 8a38a79

File tree

10 files changed

+11
-75
lines changed

10 files changed

+11
-75
lines changed

.github/workflows/build_test.yml

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -289,26 +289,6 @@ jobs:
289289
python-version: ${{ env.PYTHON_VERSION }}
290290
- uses: ./.github/actions
291291

292-
numpy2_flag:
293-
needs: [smoke_test]
294-
runs-on: ubuntu-latest
295-
if: github.event_name != 'push'
296-
env:
297-
# Test for numpy-2.0 feature-flagged behavior.
298-
NPY_NUMPY_2_BEHAVIOR: 1
299-
# Using the future "weak" state doesn't pass tests
300-
# currently unfortunately
301-
NPY_PROMOTION_STATE: legacy
302-
steps:
303-
- uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
304-
with:
305-
submodules: recursive
306-
fetch-depth: 0
307-
- uses: actions/setup-python@bd6b4b6205c4dbad673328db7b31b7fab9e241c0 # v4.6.1
308-
with:
309-
python-version: ${{ env.PYTHON_VERSION }}
310-
- uses: ./.github/actions
311-
312292
no_openblas:
313293
needs: [smoke_test]
314294
runs-on: ubuntu-latest
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
* ``np.gradient()`` now returns a tuple rather than list making the
2+
return value immutable.
3+

doc/source/reference/global_state.rst

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,3 @@ memory allocation policy, the default will be to call ``free``. If
8282
``NUMPY_WARN_IF_NO_MEM_POLICY`` is set to ``"1"``, a ``RuntimeWarning`` will
8383
be emitted. A better alternative is to use a ``PyCapsule`` with a deallocator
8484
and set the ``ndarray.base``.
85-
86-
87-
Testing planned future behavior
88-
===============================
89-
90-
NumPy has some code paths which are planned to be activated in the future
91-
but are not yet the default behavior.
92-
You can try testing some of these which may be shipped with a new "major"
93-
release (NumPy 2.0) by setting an environment before importing NumPy:
94-
95-
NPY_NUMPY_2_BEHAVIOR=1
96-
97-
By default this will also activate the :ref:`NEP 50 <NEP50>` related setting
98-
``NPY_PROMOTION_STATE`` (please see the NEP for details on this).

numpy/__init__.py

Lines changed: 2 additions & 3 deletions
< 6855 td data-grid-cell-id="diff-09a2c2e86cca91dac0c336e4dad47197ba3cd837ff6c85abf8525cc3b879d3e6-431-431-2" data-line-anchor="diff-09a2c2e86cca91dac0c336e4dad47197ba3cd837ff6c85abf8525cc3b879d3e6R431" data-selected="false" role="gridcell" style="background-color:var(--bgColor-default);padding-right:24px" tabindex="-1" valign="top" class="focusable-grid-cell diff-text-cell right-side-diff-cell left-side">
core._set_promotion_state(
Original file line numberDiff line numberDiff line change
@@ -427,10 +427,9 @@ def _mac_os_check():
427427
# it is tidier organized.
428428
core.multiarray._multiarray_umath._reload_guard()
429429

430-
# default to "weak" promotion for "NumPy 2".
430+
# TODO: Switch to defaulting to "weak".
431431
432-
os.environ.get("NPY_PROMOTION_STATE",
433-
"weak" if _using_numpy2_behavior() else "legacy"))
432+
os.environ.get("NPY_PROMOTION_STATE", "legacy"))
434433

435434
# Tell PyInstaller where to find hook-numpy.py
436435
def _pyinstaller_hooks_dir():

numpy/core/multiarray.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
fastCopyAndTranspose, _flagdict, from_dlpack, _place, _reconstruct,
1818
_vec_string, _ARRAY_API, _monotonicity, _get_ndarray_c_version,
1919
_get_madvise_hugepage, _set_madvise_hugepage,
20-
_get_promotion_state, _set_promotion_state, _using_numpy2_behavior
20+
_get_promotion_state, _set_promotion_state
2121
)
2222

2323
__all__ = [
@@ -42,7 +42,7 @@
4242
'set_legacy_print_mode', 'set_numeric_ops', 'set_string_function',
4343
'set_typeDict', 'shares_memory', 'tracemalloc_domain', 'typeinfo',
4444
'unpackbits', 'unravel_index', 'vdot', 'where', 'zeros',
45-
'_get_promotion_state', '_set_promotion_state', '_using_numpy2_behavior']
45+
'_get_promotion_state', '_set_promotion_state']
4646

4747
# For backward compatibility, make sure pickle imports these functions from here
4848
_reconstruct.__module__ = 'numpy.core.multiarray'
@@ -72,7 +72,6 @@
7272
zeros.__module__ = 'numpy'
7373
_get_promotion_state.__module__ = 'numpy'
7474
_set_promotion_state.__module__ = 'numpy'
75-
_using_numpy2_behavior.__module__ = 'numpy'
7675

7776

7877
# We can't verify dispatcher signatures because NumPy's C functions don't

numpy/core/numeric.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
fromstring, inner, lexsort, matmul, may_share_memory,
1919
min_scalar_type, ndarray, nditer, nested_iters, promote_types,
2020
putmask, result_type, set_numeric_ops, shares_memory, vdot, where,
21-
zeros, normalize_axis_index, _get_promotion_state, _set_promotion_state,
22-
_using_numpy2_behavior)
21+
zeros, normalize_axis_index, _get_promotion_state, _set_promotion_state)
2322

2423
from . import overrides
2524
from . import umath
@@ -56,8 +55,7 @@
5655
'False_', 'True_', 'bitwise_not', 'CLIP', 'RAISE', 'WRAP', 'MAXDIMS',
5756
'BUFSIZE', 'ALLOW_THREADS', 'full', 'full_like',
5857
'matmul', 'shares_memory', 'may_share_memory', 'MAY_SHARE_BOUNDS',
59-
'MAY_SHARE_EXACT', '_get_promotion_state', '_set_promotion_state',
60-
'_using_numpy2_behavior']
58+
'MAY_SHARE_EXACT', '_get_promotion_state', '_set_promotion_state']
6159

6260

6361
def _zeros_like_dispatcher(a, dtype=None, order=None, subok=None, shape=None):

numpy/core/src/multiarray/multiarraymodule.c

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,6 @@ _umath_strings_richcompare(
103103
* future.
104104
*/
105105
int npy_legacy_print_mode = INT_MAX;
106-
/*
107-
* Global variable to check whether NumPy 2.0 behavior is opted in.
108-
* This flag is considered a runtime constant.
109-
*/
110-
int npy_numpy2_behavior = NPY_FALSE;
111106

112107

113108
static PyObject *
@@ -4511,14 +4506,6 @@ _reload_guard(PyObject *NPY_UNUSED(self), PyObject *NPY_UNUSED(args)) {
45114506
}
45124507

45134508

4514-
static PyObject *
4515-
_using_numpy2_behavior(
4516-
PyObject *NPY_UNUSED(self), PyObject *NPY_UNUSED(args))
4517-
{
4518-
return PyBool_FromLong(npy_numpy2_behavior);
4519-
}
4520-
4521-
45224509
static struct PyMethodDef array_module_methods[] = {
45234510
{"_get_implementing_args",
45244511
(PyCFunction)array__get_implementing_args,
@@ -4744,8 +4731,6 @@ static struct PyMethodDef array_module_methods[] = {
47444731
{"_reload_guard", (PyCFunction)_reload_guard,
47454732
METH_NOARGS,
47464733
"Give a warning on reload and big warning in sub-interpreters."},
4747-
{"_using_numpy2_behavior", (PyCFunction)_using_numpy2_behavior,
4748-
METH_NOARGS, NULL},
47494734
{"from_dlpack", (PyCFunction)from_dlpack,
47504735
METH_O, NULL},
47514736
{NULL, NULL, 0, NULL} /* sentinel */
@@ -5023,12 +5008,6 @@ initialize_static_globals(void)
50235008
return -1;
50245009
}
50255010

5026-
/* Initialize from certain environment variabels: */
5027-
char *env = getenv("NPY_NUMPY_2_BEHAVIOR");
5028-
if (env != NULL && strcmp(env, "0") != 0) {
5029-
npy_numpy2_behavior = NPY_TRUE;
5030-
}
5031-
50325011
return 0;
50335012
}
50345013

numpy/core/src/multiarray/multiarraymodule.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#ifndef NUMPY_CORE_SRC_MULTIARRAY_MULTIARRAYMODULE_H_
22
#define NUMPY_CORE_SRC_MULTIARRAY_MULTIARRAYMODULE_H_
33

4-
NPY_VISIBILITY_HIDDEN extern int npy_numpy2_behavior;
5-
64
NPY_VISIBILITY_HIDDEN extern PyObject * npy_ma_str_current_allocator;
75
NPY_VISIBILITY_HIDDEN extern PyObject * npy_ma_str_array;
86
NPY_VISIBILITY_HIDDEN extern PyObject * npy_ma_str_array_function;

numpy/lib/function_base.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,10 +1311,7 @@ def gradient(f, *varargs, axis=None, edge_order=1):
13111311

13121312
if len_axes == 1:
13131313
return outvals[0]
1314-
elif np._using_numpy2_behavior():
1315-
return tuple(outvals)
1316-
else:
1317-
return outvals
1314+
return tuple(outvals)
13181315

13191316

13201317
def _diff_dispatcher(a, n=None, axis=None, prepend=None, append=None):

numpy/lib/tests/test_function_base.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,10 +1219,7 @@ def test_x_signed_int_big_jump(self, x_dtype):
12191219

12201220
def test_return_type(self):
12211221
res = np.gradient(([1, 2], [2, 3]))
1222-
if np._using_numpy2_behavior():
1223-
assert type(res) is tuple
1224-
else:
1225-
assert type(res) is list
1222+
assert type(res) is tuple
12261223

12271224

12281225
class TestAngle:

0 commit comments

Comments
 (0)
0