Skip to content

Commit ea983c6

Browse files
committed
Adjust was_copied variable names
1 parent c8cdda2 commit ea983c6

File tree

5 files changed

+30
-28
lines changed

5 files changed

+30
-28
lines changed

numpy/_core/src/multiarray/array_coercion.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ enum _dtype_discovery_flags {
9999
DISCOVER_TUPLES_AS_ELEMENTS = 1 << 4,
100100
MAX_DIMS_WAS_REACHED = 1 << 5,
101101
DESCRIPTOR_WAS_SET = 1 << 6,
102-
COPY_WAS_CREATED = 1 << 7,
102+
COPY_WAS_CREATED_BY__ARRAY__ = 1 << 7,
103103
};
104104

105105

@@ -1028,18 +1028,18 @@ PyArray_DiscoverDTypeAndShape_Recursive(
10281028
/* __array__ may be passed the requested descriptor if provided */
10291029
requested_descr = *out_descr;
10301030
}
1031-
int was_copied = 0;
1031+
int was_copied_by__array__ = 0;
10321032
arr = (PyArrayObject *)_array_from_array_like(obj,
1033-
requested_descr, 0, NULL, copy, &was_copied);
1033+
requested_descr, 0, NULL, copy, &was_copied_by__array__);
10341034
if (arr == NULL) {
10351035
return -1;
10361036
}
10371037
else if (arr == (PyArrayObject *)Py_NotImplemented) {
10381038
Py_DECREF(arr);
10391039
arr = NULL;
10401040
}
1041-
if (was_copied == 1) {
1042-
*flags |= COPY_WAS_CREATED;
1041+
if (was_copied_by__array__ == 1) {
1042+
*flags |= COPY_WAS_CREATED_BY__ARRAY__;
10431043
}
10441044
}
10451045
if (arr != NULL) {
@@ -1231,8 +1231,8 @@ PyArray_DiscoverDTypeAndShape_Recursive(
12311231
* to choose a default.
12321232
* @param copy Specifies the copy behavior. -1 is corresponds to copy=None,
12331233
* 0 to copy=False, and 1 to copy=True in the Python API.
1234-
* @param was_copied Set to 1 if it can be assumed that a copy was made
1235-
* by implementor.
1234+
* @param was_copied_by__array__ Set to 1 if it can be assumed that a copy was
1235+
* made by implementor.
12361236
* @return dimensions of the discovered object or -1 on error.
12371237
* WARNING: If (and only if) the output is a single array, the ndim
12381238
* returned _can_ exceed the maximum allowed number of dimensions.
@@ -1245,7 +1245,7 @@ PyArray_DiscoverDTypeAndShape(
12451245
npy_intp out_shape[NPY_MAXDIMS],
12461246
coercion_cache_obj **coercion_cache,
12471247
PyArray_DTypeMeta *fixed_DType, PyArray_Descr *requested_descr,
1248-
PyArray_Descr **out_descr, int copy, int *was_copied)
1248+
PyArray_Descr **out_descr, int copy, int *was_copied_by__array__)
12491249
{
12501250
coercion_cache_obj **coercion_cache_head = coercion_cache;
12511251
*coercion_cache = NULL;
@@ -1298,8 +1298,8 @@ PyArray_DiscoverDTypeAndShape(
12981298
goto fail;
12991299
}
13001300

1301-
if (was_copied != NULL && flags & COPY_WAS_CREATED) {
1302-
*was_copied = 1;
1301+
if (was_copied_by__array__ != NULL && flags & COPY_WAS_CREATED_BY__ARRAY__) {
1302+
*was_copied_by__array__ = 1;
13031303
}
13041304

13051305
if (NPY_UNLIKELY(flags & FOUND_RAGGED_ARRAY)) {

numpy/_core/src/multiarray/array_coercion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ PyArray_DiscoverDTypeAndShape(
4040
npy_intp out_shape[NPY_MAXDIMS],
4141
coercion_cache_obj **coercion_cache,
4242
PyArray_DTypeMeta *fixed_DType, PyArray_Descr *requested_descr,
43-
PyArray_Descr **out_descr, int copy, int *was_copied);
43+
PyArray_Descr **out_descr, int copy, int *was_copied_by__array__);
4444

4545
NPY_NO_EXPORT PyObject *
4646
_discover_array_parameters(PyObject *NPY_UNUSED(self),

numpy/_core/src/multiarray/ctors.c

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,8 +1429,8 @@ _array_from_buffer_3118(PyObject *memoryview)
14291429
* @param writeable whether the result must be writeable.
14301430
* @param context Unused parameter, must be NULL (should be removed later).
14311431
* @param copy Specifies the copy behavior.
1432-
* @param was_copied Set to 1 if it can be assumed that a copy was made
1433-
* by implementor.
1432+
* @param was_copied_by__array__ Set to 1 if it can be assumed that a copy
1433+
* was made by implementor.
14341434
*
14351435
* @returns The array object, Py_NotImplemented if op is not array-like,
14361436
* or NULL with an error set. (A new reference to Py_NotImplemented
@@ -1439,7 +1439,7 @@ _array_from_buffer_3118(PyObject *memoryview)
14391439
NPY_NO_EXPORT PyObject *
14401440
_array_from_array_like(PyObject *op,
14411441
PyArray_Descr *requested_dtype, npy_bool writeable, PyObject *context,
1442-
int copy, int *was_copied) {
1442+
int copy, int *was_copied_by__array__) {
14431443
PyObject* tmp;
14441444

14451445
/*
@@ -1487,7 +1487,8 @@ _array_from_array_like(PyObject *op,
14871487
}
14881488

14891489
if (tmp == Py_NotImplemented) {
1490-
tmp = PyArray_FromArrayAttr_int(op, requested_dtype, copy, was_copied);
1490+
tmp = PyArray_FromArrayAttr_int(
1491+
op, requested_dtype, copy, was_copied_by__array__);
14911492
if (tmp == NULL) {
14921493
return NULL;
14931494
}
@@ -1574,7 +1575,7 @@ PyArray_FromAny_int(PyObject *op, PyArray_Descr *in_descr,
15741575

15751576
// Default is copy = None
15761577
int copy = -1;
1577-
int was_copied = 0;
1578+
int was_copied_by__array__ = 0;
15781579

15791580
if (flags & NPY_ARRAY_ENSURENOCOPY) {
15801581
copy = 0;
@@ -1583,7 +1584,8 @@ PyArray_FromAny_int(PyObject *op, PyArray_Descr *in_descr,
15831584
}
15841585

15851586
ndim = PyArray_DiscoverDTypeAndShape(
1586-
op, NPY_MAXDIMS, dims, &cache, in_DType, in_descr, &dtype, copy, &was_copied);
1587+
op, NPY_MAXDIMS, dims, &cache, in_DType, in_descr, &dtype,
1588+
copy, &was_copied_by__array__);
15871589

15881590
if (ndim < 0) {
15891591
return NULL;
@@ -1620,7 +1622,7 @@ PyArray_FromAny_int(PyObject *op, PyArray_Descr *in_descr,
16201622
assert(cache->converted_obj == op);
16211623
arr = (PyArrayObject *)(cache->arr_or_sequence);
16221624
/* we may need to cast or assert flags (e.g. copy) */
1623-
if (was_copied == 1 && flags & NPY_ARRAY_ENSURECOPY) {
1625+
if (was_copied_by__array__ == 1 && flags & NPY_ARRAY_ENSURECOPY) {
16241626
flags = flags & ~NPY_ARRAY_ENSURECOPY;
16251627
flags = flags | NPY_ARRAY_ENSURENOCOPY;
16261628
}
@@ -2495,14 +2497,14 @@ check_or_clear_and_warn_error_if_due_to_copy_kwarg(PyObject *kwnames)
24952497
* NOTE: For copy == -1 it passes `op.__array__(copy=None)`,
24962498
* for copy == 0, `op.__array__(copy=False)`, and
24972499
* for copy == 1, `op.__array__(copy=True).
2498-
* @param was_copied Set to 1 if it can be assumed that a copy was made
2499-
* by implementor.
2500+
* @param was_copied_by__array__ Set to 1 if it can be assumed that a copy
2501+
* was made by implementor.
25002502
* @returns NotImplemented if `__array__` is not defined or a NumPy array
25012503
* (or subclass). On error, return NULL.
25022504
*/
25032505
NPY_NO_EXPORT PyObject *
2504-
PyArray_FromArrayAttr_int(
2505-
PyObject *op, PyArray_Descr *descr, int copy, int *was_copied)
2506+
PyArray_FromArrayAttr_int(PyObject *op, PyArray_Descr *descr, int copy,
2507+
int *was_copied_by__array__)
25062508
{
25072509
PyObject *new;
25082510
PyObject *array_meth;
@@ -2589,9 +2591,10 @@ PyArray_FromArrayAttr_int(
25892591
Py_DECREF(new);
25902592
return NULL;
25912593
}
2592-
if (was_copied != NULL && copy == 1 && must_copy_but_copy_kwarg_unimplemented == 0) {
2594+
if (was_copied_by__array__ != NULL && copy == 1 &&
2595+
must_copy_but_copy_kwarg_unimplemented == 0) {
25932596
/* We can assume that a copy was made */
2594-
*was_copied = 1;
2597+
*was_copied_by__array__ = 1;
25952598
}
25962599

25972600
return new;

numpy/_core/src/multiarray/ctors.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ PyArray_New(
5454
NPY_NO_EXPORT PyObject *
5555
_array_from_array_like(PyObject *op,
5656
PyArray_Descr *requested_dtype, npy_bool writeable, PyObject *context,
57-
int copy, int *was_copied);
57+
int copy, int *was_copied_by__array__);
5858

5959
NPY_NO_EXPORT PyObject *
6060
PyArray_FromAny_int(PyObject *op, PyArray_Descr *in_descr,
@@ -84,8 +84,8 @@ NPY_NO_EXPORT PyObject *
8484
PyArray_FromInterface(PyObject *input);
8585

8686
NPY_NO_EXPORT PyObject *
87-
PyArray_FromArrayAttr_int(
88-
PyObject *op, PyArray_Descr *descr, int copy, int *was_copied);
87+
PyArray_FromArrayAttr_int(PyObject *op, PyArray_Descr *descr, int copy,
88+
int *was_copied_by__array__);
8989

9090
NPY_NO_EXPORT PyObject *
9191
PyArray_FromArrayAttr(PyObject *op, PyArray_Descr *typecode,

numpy/_core/tests/test_multiarray.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8502,7 +8502,6 @@ def __array__(self, dtype=None):
85028502
match=r"Unable to avoid copy(.|\n)*numpy_2_0_migration_guide.html"):
85038503
np.array(a, copy=False)
85048504

8505-
@pytest.mark.skipif(IS_PYPY, reason="PyPy copies differently")
85068505
def test___array__copy_once(self):
85078506
size = 100
85088507
base_arr = np.zeros((size, size))

0 commit comments

Comments
 (0)