summaryrefslogtreecommitdiff
path: root/numpy/lib/tests
diff options
context:
space:
mode:
authorMatti Picus <matti.picus@gmail.com>2019-07-15 07:57:03 -0500
committerGitHub <noreply@github.com>2019-07-15 07:57:03 -0500
commit562405c74fe7cebf22d45cb0de77bb23e082fd63 (patch)
tree6da58f687a4ee96df49eec0157f63347d6e06155 /numpy/lib/tests
parent48a0ed69999dfa77f4d78a37c890417e2725c040 (diff)
parentc24e43c0eb4dd6f9e4bf12519000cb9f662a5425 (diff)
downloadnumpy-562405c74fe7cebf22d45cb0de77bb23e082fd63.tar.gz
Merge pull request #13993 from seberg/issue-13929-2
DEP: Speed up WarnOnWrite deprecation in buffer interface
Diffstat (limited to 'numpy/lib/tests')
-rw-r--r--numpy/lib/tests/test_stride_tricks.py29
1 files changed, 26 insertions, 3 deletions
diff --git a/numpy/lib/tests/test_stride_tricks.py b/numpy/lib/tests/test_stride_tricks.py
index 955fb914c..85fcceedc 100644
--- a/numpy/lib/tests/test_stride_tricks.py
+++ b/numpy/lib/tests/test_stride_tricks.py
@@ -417,17 +417,21 @@ def test_writeable():
# but the result of broadcast_arrays needs to be writeable, to
# preserve backwards compatibility
- for results in [broadcast_arrays(original),
- broadcast_arrays(0, original)]:
+ for is_broadcast, results in [(False, broadcast_arrays(original,)),
+ (True, broadcast_arrays(0, original))]:
for result in results:
# This will change to False in a future version
- if any([s == 0 for s in result.strides]):
+ if is_broadcast:
with assert_warns(FutureWarning):
assert_equal(result.flags.writeable, True)
with assert_warns(DeprecationWarning):
result[:] = 0
# Warning not emitted, writing to the array resets it
assert_equal(result.flags.writeable, True)
+ else:
+ # No warning:
+ assert_equal(result.flags.writeable, True)
+
for results in [broadcast_arrays(original),
broadcast_arrays(0, original)]:
for result in results:
@@ -451,6 +455,25 @@ def test_writeable():
assert_(first.shape == second.shape)
+def test_writeable_memoryview():
+ # The result of broadcast_arrays exports as a non-writeable memoryview
+ # because otherwise there is no good way to opt in to the new behaviour
+ # (i.e. you would need to set writeable to False explicitly).
+ # See gh-13929.
+ original = np.array([1, 2, 3])
+
+ for is_broadcast, results in [(False, broadcast_arrays(original,)),
+ (True, broadcast_arrays(0, original))]:
+ for result in results:
+ # This will change to False in a future version
+ if is_broadcast:
+ # memoryview(result, writable=True) will give warning but cannot
+ # be tested using the python API.
+ assert memoryview(result).readonly
+ else:
+ assert not memoryview(result).readonly
+
+
def test_reference_types():
input_array = np.array('a', dtype=object)
expected = np.array(['a'] * 3, dtype=object)