summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--numpy/core/src/multiarray/getset.c20
-rw-r--r--numpy/core/tests/test_deprecations.py16
2 files changed, 32 insertions, 4 deletions
diff --git a/numpy/core/src/multiarray/getset.c b/numpy/core/src/multiarray/getset.c
index 549ea333a..c2a88e3b9 100644
--- a/numpy/core/src/multiarray/getset.c
+++ b/numpy/core/src/multiarray/getset.c
@@ -488,11 +488,25 @@ array_descr_set(PyArrayObject *self, PyObject *arg)
if ((newtype->elsize != PyArray_DESCR(self)->elsize) &&
- (PyArray_NDIM(self) == 0 || !PyArray_ISONESEGMENT(self) ||
- PyDataType_HASSUBARRAY(newtype))) {
+ (PyArray_NDIM(self) == 0 ||
+ !PyArray_ISONESEGMENT(self) ||
+ PyDataType_HASSUBARRAY(newtype))) {
goto fail;
}
- if (PyArray_ISCONTIGUOUS(self)) {
+
+ /* Deprecate not C contiguous and a dimension changes */
+ if (newtype->elsize != PyArray_DESCR(self)->elsize &&
+ !PyArray_IS_C_CONTIGUOUS(self)) {
+ /* 11/27/2015 1.11.0 */
+ if (DEPRECATE("Changing the shape of non-C contiguous array by\n"
+ "descriptor assignment is deprecated. To maintain\n"
+ "the Fortran contiguity of a multidimensional Fortran\n"
+ "array, use 'a.T.view(...).T' instead") < 0) {
+ return -1;
+ }
+ }
+
+ if (PyArray_IS_C_CONTIGUOUS(self)) {
i = PyArray_NDIM(self) - 1;
}
else {
diff --git a/numpy/core/tests/test_deprecations.py b/numpy/core/tests/test_deprecations.py
index e2542195f..8f7e55d91 100644
--- a/numpy/core/tests/test_deprecations.py
+++ b/numpy/core/tests/test_deprecations.py
@@ -375,7 +375,7 @@ class TestBooleanIndexShapeMismatchDeprecation():
arr.__getitem__, (slice(None), index))
-class TestFullDefaultDtype:
+class TestFullDefaultDtype(object):
"""np.full defaults to float when dtype is not set. In the future, it will
use the fill value's dtype.
"""
@@ -386,5 +386,19 @@ class TestFullDefaultDtype:
assert_no_warnings(np.full, 1, 1, float)
+class TestNonCContiguousViewDeprecation(_DeprecationTestCase):
+ """View of non-C-contiguous arrays deprecated in 1.11.0.
+
+ The deprecation will not be raised for arrays that are both C and F
+ contiguous, as C contiguous is dominant. There are more such arrays
+ with relaxed stride checking than without so the deprecation is not
+ as visible with relaxed stride checking in force.
+ """
+
+ def test_fortran_contiguous(self):
+ self.assert_deprecated(np.ones((2,2)).T.view, args=(np.complex,))
+ self.assert_deprecated(np.ones((2,2)).T.view, args=(np.int8,))
+
+
if __name__ == "__main__":
run_module_suite()