From 3c0b4db0b51ec4f4b67f63d647d8f8a668b7e754 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Tue, 23 May 2017 16:46:06 +0200 Subject: BUG: have as_strided() keep custom dtypes Fixes issue #9161 --- numpy/lib/tests/test_stride_tricks.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'numpy/lib/tests') diff --git a/numpy/lib/tests/test_stride_tricks.py b/numpy/lib/tests/test_stride_tricks.py index 7dc3c4d24..0599324d7 100644 --- a/numpy/lib/tests/test_stride_tricks.py +++ b/numpy/lib/tests/test_stride_tricks.py @@ -1,6 +1,7 @@ from __future__ import division, absolute_import, print_function import numpy as np +from numpy.core.test_rational import rational from numpy.testing import ( run_module_suite, assert_equal, assert_array_equal, assert_raises, assert_ @@ -317,6 +318,13 @@ def test_as_strided(): a_view = as_strided(a, shape=(3, 4), strides=(0, a.itemsize)) assert_equal(a.dtype, a_view.dtype) + # Custom dtypes should not be lost (gh-9161) + r = [rational(i) for i in range(4)] + a = np.array(r, dtype=rational) + a_view = as_strided(a, shape=(3, 4), strides=(0, a.itemsize)) + assert_equal(a.dtype, a_view.dtype) + assert_array_equal([r] * 3, a_view) + def as_strided_writeable(): arr = np.ones(10) view = as_strided(arr, writeable=False) -- cgit v1.2.1