8000 Merge pull request #7274 from gfyoung/delete_copy_dtype · numpy/numpy@6d3b34f · GitHub
[go: up one dir, main page]

Skip to content

Commit 6d3b34f

Browse files
committed
Merge pull request #7274 from gfyoung/delete_copy_dtype
BUG: Preserve array order in np.delete
2 parents bd905a8 + ed527cd commit 6d3b34f

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

numpy/lib/function_base.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4097,7 +4097,7 @@ def delete(arr, obj, axis=None):
40974097
if wrap:
40984098
return wrap(arr)
40994099
else:
4100-
return arr.copy()
4100+
return arr.copy(order=arrorder)
41014101

41024102
slobj = [slice(None)]*ndim
41034103
N = arr.shape[axis]
@@ -4110,9 +4110,9 @@ def delete(arr, obj, axis=None):
41104110

41114111
if numtodel <= 0:
41124112
if wrap:
4113-
return wrap(arr.copy())
4113+
return wrap(arr.copy(order=arrorder))
41144114
else:
4115-
return arr.copy()
4115+
return arr.copy(order=arrorder)
41164116

41174117
# Invert if step is negative:
41184118
if step < 0:
@@ -4333,7 +4333,7 @@ def insert(arr, obj, values, axis=None):
43334333
warnings.warn(
43344334
"in the future the special handling of scalars will be removed "
43354335
"from insert and raise an error", DeprecationWarning)
4336-
arr = arr.copy()
4336+
arr = arr.copy(order=arrorder)
43374337
arr[...] = values
43384338
if wrap:
43394339
return wrap(arr)

numpy/lib/tests/test_function_base.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,16 @@ class SubClass(np.ndarray):
533533
assert_(isinstance(delete(a, slice(1, 2)), SubClass))
534534
assert_(isinstance(delete(a, slice(1, -2)), SubClass))
535535

536+
def test_array_order_preserve(self):
537+
# See gh-7113
538+
k = np.arange(10).reshape(2, 5, order='F')
539+
m = delete(k, slice(60, None), axis=1)
540+
541+
# 'k' is Fortran ordered, and 'm' should have the
542+
# same ordering as 'k' and NOT become C ordered
543+
assert_equal(m.flags.c_contiguous, k.flags.c_contiguous)
544+
assert_equal(m.flags.f_contiguous, k.flags.f_contiguous)
545+
536546

537547
class TestGradient(TestCase):
538548

0 commit comments

Comments
 (0)
0