summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorMatti Picus <matti.picus@gmail.com>2019-04-25 16:09:00 -0700
committerGitHub <noreply@github.com>2019-04-25 16:09:00 -0700
commit171a3e5811e43643788c20075be9ba52efb83b81 (patch)
tree2370d772ffb615bd4494a1c2da5d26a0bb520fd9 /numpy
parent0c3d18f57c842047ae23383c2eae46a042faef5d (diff)
parent58c28d4fd1c54b455d19372f0c838fed5fc71fe4 (diff)
downloadnumpy-171a3e5811e43643788c20075be9ba52efb83b81.tar.gz
Merge pull request #13334 from eric-wieser/fix-1-field-unstructured
BUG: Fix structured_to_unstructured on single-field types
Diffstat (limited to 'numpy')
-rw-r--r--numpy/lib/recfunctions.py2
-rw-r--r--numpy/lib/tests/test_recfunctions.py2
2 files changed, 3 insertions, 1 deletions
diff --git a/numpy/lib/recfunctions.py b/numpy/lib/recfunctions.py
index 5ff35f0bb..ccbcfad91 100644
--- a/numpy/lib/recfunctions.py
+++ b/numpy/lib/recfunctions.py
@@ -980,7 +980,7 @@ def structured_to_unstructured(arr, dtype=None, copy=False, casting='unsafe'):
arr = arr.astype(packed_fields, copy=copy, casting=casting)
# finally is it safe to view the packed fields as the unstructured type
- return arr.view((out_dtype, sum(counts)))
+ return arr.view((out_dtype, (sum(counts),)))
def _unstructured_to_structured_dispatcher(arr, dtype=None, names=None,
align=None, copy=None, casting=None):
diff --git a/numpy/lib/tests/test_recfunctions.py b/numpy/lib/tests/test_recfunctions.py
index 069693613..112678294 100644
--- a/numpy/lib/tests/test_recfunctions.py
+++ b/numpy/lib/tests/test_recfunctions.py
@@ -214,6 +214,8 @@ class TestRecFunctions(object):
dtype=[('x', 'i4'), ('y', 'f4'), ('z', 'f8')])
out = np.mean(structured_to_unstructured(b[['x', 'z']]), axis=-1)
assert_equal(out, np.array([ 3. , 5.5, 9. , 11. ]))
+ out = np.mean(structured_to_unstructured(b[['x']]), axis=-1)
+ assert_equal(out, np.array([ 1. , 4. , 7. , 10. ]))
c = np.arange(20).reshape((4,5))
out = unstructured_to_structured(c, a.dtype)