summaryrefslogtreecommitdiff
path: root/numpy/lib/stride_tricks.py
diff options
context:
space:
mode:
authorAntoine Pitrou <antoine@python.org>2017-05-23 16:46:06 +0200
committerAntoine Pitrou <antoine@python.org>2017-05-24 15:44:28 +0200
commit3c0b4db0b51ec4f4b67f63d647d8f8a668b7e754 (patch)
tree830ec571d6c0fbe8b1d9c3cdba72133e5d498514 /numpy/lib/stride_tricks.py
parentd0c15fab8e3c0324914baede7496810485eb4e56 (diff)
downloadnumpy-3c0b4db0b51ec4f4b67f63d647d8f8a668b7e754.tar.gz
BUG: have as_strided() keep custom dtypes
Fixes issue #9161
Diffstat (limited to 'numpy/lib/stride_tricks.py')
-rw-r--r--numpy/lib/stride_tricks.py7
1 files changed, 3 insertions, 4 deletions
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)