Skip to content

Commit 6c7b6f2

Browse files
committed
Apply review comments
1 parent ea983c6 commit 6c7b6f2

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

numpy/_core/src/multiarray/ctors.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1622,9 +1622,8 @@ PyArray_FromAny_int(PyObject *op, PyArray_Descr *in_descr,
16221622
assert(cache->converted_obj == op);
16231623
arr = (PyArrayObject *)(cache->arr_or_sequence);
16241624
/* we may need to cast or assert flags (e.g. copy) */
1625-
if (was_copied_by__array__ == 1 && flags & NPY_ARRAY_ENSURECOPY) {
1625+
if (was_copied_by__array__ == 1) {
16261626
flags = flags & ~NPY_ARRAY_ENSURECOPY;
1627-
flags = flags | NPY_ARRAY_ENSURENOCOPY;
16281627
}
16291628
PyObject *res = PyArray_FromArray(arr, dtype, flags);
16301629
npy_unlink_coercion_cache(cache);
@@ -2591,6 +2590,7 @@ PyArray_FromArrayAttr_int(PyObject *op, PyArray_Descr *descr, int copy,
25912590
Py_DECREF(new);
25922591
return NULL;
25932592
}
2593+
/* TODO: Remove was_copied_by__array__ argument */
25942594
if (was_copied_by__array__ != NULL && copy == 1 &&
25952595
must_copy_but_copy_kwarg_unimplemented == 0) {
25962596
/* We can assume that a copy was made */

numpy/_core/tests/test_multiarray.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8532,6 +8532,11 @@ def __array__(self, dtype=None, copy=None):
85328532
_ = np.array([arr_random], copy=True)
85338533
assert not arr_random.true_passed
85348534

8535+
arr_random = ArrayRandom()
8536+
second_copy = np.array(arr_random, copy=True, order="F")
8537+
assert arr_random.true_passed
8538+
assert not second_copy is copy_arr
8539+
85358540
@pytest.mark.skipif(not HAS_REFCOUNT, reason="Python lacks refcounts")
85368541
def test__array__reference_leak(self):
85378542
class NotAnArray:

0 commit comments

Comments
 (0)