summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/_internal.py6
-rw-r--r--numpy/core/tests/test_multiarray.py5
-rw-r--r--numpy/lib/utils.py18
3 files changed, 24 insertions, 5 deletions
diff --git a/numpy/core/_internal.py b/numpy/core/_internal.py
index 92ab0c8b0..fbe580dee 100644
--- a/numpy/core/_internal.py
+++ b/numpy/core/_internal.py
@@ -295,7 +295,11 @@ def _index_fields(ary, fields):
view_dtype = {'names':names, 'formats':formats, 'offsets':offsets, 'itemsize':dt.itemsize}
view = ary.view(dtype=view_dtype)
- return view.copy()
+ # Return a copy for now until behavior is fully deprecated
+ # in favor of returning view
+ copy_dtype = {'names':view_dtype['names'], 'formats':view_dtype['formats']}
+ from numpy import array
+ return array(view, dtype=copy_dtype, copy=True)
# Given a string containing a PEP 3118 format specifier,
# construct a Numpy dtype
diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py
index b9fd3ad86..118f221ae 100644
--- a/numpy/core/tests/test_multiarray.py
+++ b/numpy/core/tests/test_multiarray.py
@@ -1956,6 +1956,11 @@ class TestRecord(TestCase):
assert_equal(b[['f1','f2']][0].tolist(), (2, 3))
assert_equal(b[['f2','f1']][0].tolist(), (3, 2))
assert_equal(b[['f1','f3']][0].tolist(), (2, (1,)))
+ # view of subfield view/copy
+ assert_equal(b[['f1','f2']][0].view(('i4',2)).tolist(), (2, 3))
+ assert_equal(b[['f2','f1']][0].view(('i4',2)).tolist(), (3, 2))
+ view_dtype=[('f1', 'i4'),('f3', [('', 'i4')])]
+ assert_equal(b[['f1','f3']][0].view(view_dtype).tolist(), (2, (1,)))
# non-ascii unicode field indexing is well behaved
if not is_py3:
raise SkipTest('non ascii unicode field indexing skipped; '
diff --git a/numpy/lib/utils.py b/numpy/lib/utils.py
index 924289a6a..dc6c16767 100644
--- a/numpy/lib/utils.py
+++ b/numpy/lib/utils.py
@@ -1136,11 +1136,21 @@ def safe_eval(source):
SyntaxError: Unsupported source construct: compiler.ast.CallFunc
"""
- # Local import to speed up numpy's import time.
+ # Local imports to speed up numpy's import time.
+ import warnings
+ from numpy.testing.utils import WarningManager
+ warn_ctx = WarningManager()
+ warn_ctx.__enter__()
try:
- import compiler
- except ImportError:
- import ast as compiler
+ # compiler package is deprecated for 3.x, which is already solved here
+ warnings.simplefilter('ignore', DeprecationWarning)
+ try:
+ import compiler
+ except ImportError:
+ import ast as compiler
+ finally:
+ warn_ctx.__exit__()
+
walker = SafeEval()
try:
ast = compiler.parse(source, mode="eval")