8000 API: Switch to NEP 50 behavior by default by seberg · Pull Request #23912 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

API: Switch to NEP 50 behavior by default #23912

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 27 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
197e61c
API: Switch to "weak" promotion state by default
seberg Jun 9, 2023
af5fe2e
MAINT,TST: Fix issues due to out-of-range integers
seberg Jun 9, 2023
14f6aa1
MAINT: Robustify histogram unsigned-subtract and fix test for NEP 50
seberg Jun 9, 2023
0cc124d
TST: Adjust tests for direct NEP 50 changes
seberg Jun 9, 2023
e19fd64
TST: Straight forward NEP 50 fixup or longdouble+int scalar tests
seberg Jun 9, 2023
1f07c93
STY: Remove unnecessary indentation level
seberg Jun 26, 2023
e445e80
API: Use weak scalar logic in where (and fix up error paths slightly)
seberg Jun 26, 2023
346a146
TST: Adept where test to NEP 50
seberg Jun 26, 2023
166e806
MAINT: Require `select` for NEP 50 support
seberg Jul 12, 2023
6cf68f3
Fix percentile and quantile 8000
mhvk Jul 12, 2023
623e0f0
TST: xfail test that checks `can_cast()` beahvior with pyints
seberg Sep 28, 2023
0f18c6f
MAINT: Also adopt `q` handling from the main quantile/percnetile to n…
seberg Sep 28, 2023
94b7f90
MAINT: Address review comments by Marten
seberg Sep 28, 2023
841a280
TST: Fix one more tests
seberg Sep 28, 2023
09418fc
TYP: Fix typing passing test which cannot pass anymore
seberg Sep 28, 2023
df8f9d6
DOC: Fix docs that cause an integer overflow
seberg Sep 28, 2023
8a1497f
MAINT: Avoid overflow in comparison with int64 on shorter platforms
seberg Sep 28, 2023
0aa93fa
DOC: Fix docstring pointing out quirks that got less bad with NEP 50
seberg Sep 28, 2023
375de5d
TST: Undo test changes related to comparising to out-of-bound ints
seberg Oct 12, 2023
0e6d569
MAINT: Undo now unnecessary random number cast to int64
seberg Oct 12, 2023
a907624
API: Disable `can_cast` with Python scalars (for now)
seberg Oct 12, 2023
dcb8de2
TST: Adjust test to avoid overflow (and bad results on BSD)
seberg Oct 12, 2023
6707f39
BENCH: Explicitly skip reversed (arg)partition case because they fail
seberg Oct 12, 2023
ba47e60
MAINT: Address review comments
seberg Oct 20, 2023
bf0ff21
MAINT: Clean up error path (DescrFromType cannot fail for simple buil…
seberg Oct 23, 2023
35e105f
MAINT: Address Nathans review comments
seberg Oct 24, 2023
b5c8398
MAINT: appease linter
ngoldbaum Oct 24, 2023
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
Prev Previous commit
Next Next commit
MAINT: Address review comments
  • Loading branch information
seberg committed Oct 20, 2023
commit ba47e60841d7b3e0d08090a99650166ff66d6f3e
14 changes: 7 additions & 7 deletions numpy/_core/src/multiarray/multiarraymodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -3254,6 +3254,7 @@ PyArray_Where(PyObject *condition, PyObject *x, PyObject *y)
{
PyArrayObject *arr, *ax, *ay = NULL;
Copy link
Member

Choose a reason for hiding this comment

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

Might as well initialize all of these to NULL, leaving it like this is a little confusing

Copy link
Member Author

Choose a reason for hiding this comment

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

Added, although I can't say I prefer it when it isn't needed for cleanup (the "uninitialized" warnings work pretty well anyway).

PyObject *ret = NULL;
PyArray_Descr *common_dt = NULL;

arr = (PyArrayObject *)PyArray_FROM_O(condition);
if (arr == NULL) {
Expand Down Expand Up @@ -3295,23 +3296,20 @@ PyArray_Where(PyObject *condition, PyObject *x, PyObject *y)
NPY_ITER_READONLY | NPY_ITER_ALIGNED,
NPY_ITER_READONLY | NPY_ITER_ALIGNED
};
PyArray_Descr * common_dt = PyArray_ResultType(2, &op_in[2],
0, NULL);
common_dt = PyArray_ResultType(2, &op_in[2], 0, NULL);
PyArray_Descr * op_dt[4] = {common_dt, PyArray_DescrFromType(NPY_BOOL),
Copy link
Member

Choose a reason for hiding this comment

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

Couldn't hurt to add a \* creating a built in dtype like this cannot fail *\ above this line.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, we really should probably just have a name for it...

common_dt, common_dt};
NpyIter * iter;
NPY_BEGIN_THREADS_DEF;

if (common_dt == NULL || op_dt[1] == NULL) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Might as well move these failures up to single tests right after definition

Py_XDECREF(op_dt[1]);
Py_XDECREF(common_dt);
goto fail;
}
iter = NpyIter_MultiNew(4, op_in, flags,
NPY_KEEPORDER, NPY_UNSAFE_CASTING,
op_flags, op_dt);
iter = NpyIter_MultiNew(
4, op_in, flags, NPY_KEEPORDER, NPY_UNSAFE_CASTING,
op_flags, op_dt);
Py_DECREF(op_dt[1]);
Py_DECREF(common_dt);
if (iter == NULL) {
goto fail;
}
Expand Down Expand Up @@ -3420,6 +3418,7 @@ PyArray_Where(PyObject *condition, PyObject *x, PyObject *y)
Py_DECREF(arr);
Py_DECREF(ax);
Py_DECREF(ay);
Py_DECREF(common_dt);
NPY_cast_info_xfree(&cast_info);

if (NpyIter_Deallocate(iter) != NPY_SUCCEED) {
Expand All @@ -3433,6 +3432,7 @@ PyArray_Where(PyObject *condition, PyObject *x, PyObject *y)
Py_DECREF(arr);
Py_XDECREF(ax);
Py_XDECREF(ay);
Py_XDECREF(common_dt);
NPY_cast_info_xfree(&cast_info);
return NULL;
}
Expand Down
2 changes: 1 addition & 1 deletion numpy/_core/tests/test_dtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -1466,7 +1466,7 @@ def test_complex_pyscalar_promote_rational(self):
@pytest.mark.parametrize("val", [2, 2**32, 2**63, 2**64, 2*100])
def test_python_integer_promotion(self, val):
# If we only pass scalars (mainly python ones!), NEP 50 means
# that we get either the default integer
# that we get the default integer
expected_dtype = np.dtype(int) # the default integer
assert np.result_type(val, 0) == expected_dtype
# With NEP 50, the NumPy scalar wins though:
Expand Down
2 changes: 1 addition & 1 deletion numpy/_core/tests/test_numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -1423,7 +1423,7 @@ def test_can_cast_structured_to_simple(self):
casting='unsafe'))

@pytest.mark.xfail(np._get_promotion_state() != "legacy",
reason="NEP 50: no int/float/complex (yet)")
reason="NEP 50: no python int/float/complex support (yet)")
def test_can_cast_values(self):
# gh-5917
for dt in sctypes['int'] + sctypes['uint']:
Expand Down
2 changes: 1 addition & 1 deletion numpy/_core/tests/test_umath.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,13 +423,13 @@ def test_unsigned_signed_direct_comparison(
assert py_comp(arr, -1) == expected
assert np_comp(arr, -1) == expected


scalar = arr[0]
assert isinstance(scalar, np.integer)
# The Python operator here is mainly interesting:
assert py_comp(scalar, -1) == expected
assert np_comp(scalar, -1) == expected


class TestAdd:
def test_reduce_alignment(self):
# gh-9876
Expand Down
2 changes: 1 addition & 1 deletion numpy/lib/_function_base_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -4462,7 +4462,7 @@ def quantile(a,

# Use dtype of array if possible (e.g., if q is a python int or float).
if isinstance(q, (int, float)) and a.dtype.kind == "f":
q = np.asanyarray(q, dtype=np.result_type(a, q))
q = np.asanyarray(q, dtype=a.dtype)
else:
q = np.asanyarray(q)

Expand Down
2 changes: 1 addition & 1 deletion numpy/lib/_nanfunctions_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1539,7 +1539,7 @@ def nanquantile(

# Use dtype of array if possible (e.g., if q is a python int or float).
if isinstance(q, (int, float)) and a.dtype.kind == "f":
q = np.asanyarray(q, dtype=np.result_type(a, q))
q = np.asanyarray(q, dtype=a.dtype)
else:
q = np.asanyarray(q)

Expand Down
12 changes: 6 additions & 6 deletions numpy/typing/tests/data/pass/bitwise_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
i8 ^ i8
i8 & i8

i << AR
i >> AR
i | AR
i ^ AR
i & AR

i8 << AR
i8 >> AR
i8 | AR
Expand Down Expand Up @@ -63,12 +69,6 @@
u8 ^ u8
u8 & u8

i << AR
i >> AR
i | AR
i ^ AR
i & AR

u4 << u4
u4 >> u4
u4 | u4
Expand Down
0