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/stride_tricks.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'numpy/lib/stride_tricks.py') diff --git a/numpy/lib/stride_tricks.py b/numpy/lib/stride_tricks.py index 545623c38..6c240db7f 100644 --- a/numpy/lib/stride_tricks.py +++ b/numpy/lib/stride_tricks.py @@ -100,10 +100,9 @@ def as_strided(x, shape=None, strides=None, subok=False, writeable=True): interface['strides'] = tuple(strides) array = np.asarray(DummyArray(interface, base=x)) - - if array.dtype.fields is None and x.dtype.fields is not None: - # This should only happen if x.dtype is [('', 'Vx')] - array.dtype = x.dtype + # The route via `__interface__` does not preserve structured + # dtypes. Since dtype should remain unchanged, we set it explicitly. + array.dtype = x.dtype view = _maybe_view_as_subclass(x, array) -- cgit v1.2.1