diff options
author | Jay Bourque <jay.bourque@continuum.io> | 2014-02-26 18:30:44 -0600 |
---|---|---|
committer | Jay Bourque <jay.bourque@continuum.io> | 2014-02-26 18:30:44 -0600 |
commit | a98b6b4ef12d09c51e5c9f015992c5b2ae164607 (patch) | |
tree | 347adeebe4757a009af3c13a41818cdc94e19d56 /numpy/lib/tests/test_stride_tricks.py | |
parent | 2943c43d855fc5a047a5fd39330306b873eab670 (diff) | |
download | numpy-a98b6b4ef12d09c51e5c9f015992c5b2ae164607.tar.gz |
Fix stride_stricks.as_strided function for object arrays
Currently, calling as_strided for object array results in 'TypeError: Cannot change data-type for object array.'. Fix so that dtype of new array is only set for void dtype, as originally intended.
Diffstat (limited to 'numpy/lib/tests/test_stride_tricks.py')
-rw-r--r-- | numpy/lib/tests/test_stride_tricks.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/numpy/lib/tests/test_stride_tricks.py b/numpy/lib/tests/test_stride_tricks.py index 4d57d2ca7..3adcf0b41 100644 --- a/numpy/lib/tests/test_stride_tricks.py +++ b/numpy/lib/tests/test_stride_tricks.py @@ -3,6 +3,7 @@ from __future__ import division, absolute_import, print_function import numpy as np from numpy.testing import * from numpy.lib.stride_tricks import broadcast_arrays +from numpy.lib.stride_tricks import as_strided def assert_shapes_correct(input_shapes, expected_shape): @@ -214,6 +215,22 @@ def test_same_as_ufunc(): assert_same_as_ufunc(input_shapes[0], input_shapes[1], False, True) assert_same_as_ufunc(input_shapes[0], input_shapes[1], True, True) +def test_as_strided(): + a = np.array([None]) + a_view = as_strided(a) + expected = np.array([None]) + assert_array_equal(a_view, np.array([None])) + + a = np.array([1, 2, 3, 4]) + a_view = as_strided(a, shape=(2,), strides=(2 * a.itemsize,)) + expected = np.array([1, 3]) + assert_array_equal(a_view, expected) + + a = np.array([1, 2, 3, 4]) + a_view = as_strided(a, shape=(3, 4), strides=(0, 1 * a.itemsize)) + expected = np.array([[1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4]]) + assert_array_equal(a_view, expected) + if __name__ == "__main__": run_module_suite() |