diff options
author | Marten van Kerkwijk <mhvk@astro.utoronto.ca> | 2019-05-27 21:40:07 -0400 |
---|---|---|
committer | Marten van Kerkwijk <mhvk@astro.utoronto.ca> | 2019-06-12 14:48:30 -0400 |
commit | e12c6bda05c8b8c024f04f2d41416e5e63971b3e (patch) | |
tree | a34cb770b014957b80b61e9d8b105382422bdf86 /numpy/doc/structured_arrays.py | |
parent | 90ee55557537f5fc2f02cca57f43f8494a5c497d (diff) | |
download | numpy-e12c6bda05c8b8c024f04f2d41416e5e63971b3e.tar.gz |
BUG: ensure that casting to/from structured is properly checked.
Allow unsafe casting from a simple data type to a structured one with
multiple fields, but only from structured data type with a single
field (checked recursively) to a simple data type.
For now, continue to allow any structured to structured with
casting="unsafe", as the current can_cast implementation does not
match that of "astype".
Diffstat (limited to 'numpy/doc/structured_arrays.py')
-rw-r--r-- | numpy/doc/structured_arrays.py | 7 |
1 files changed, 2 insertions, 5 deletions
diff --git a/numpy/doc/structured_arrays.py b/numpy/doc/structured_arrays.py index c0437dc07..1343d2adc 100644 --- a/numpy/doc/structured_arrays.py +++ b/numpy/doc/structured_arrays.py @@ -340,11 +340,8 @@ structured datatype has just a single field:: >>> nostruct = np.zeros(2, dtype='i4') >>> nostruct[:] = twofield Traceback (most recent call last): - File "<stdin>", line 1, in <module> - ValueError: Can't cast from structure to non-structure, except if the structure only has a single field. - >>> nostruct[:] = onefield - >>> nostruct - array([0, 0], dtype=int32) + ... + TypeError: Cannot cast scalar from dtype([('A', '<i4'), ('B', '<i4')]) to dtype('int32') according to the rule 'unsafe' Assignment from other Structured Arrays ``````````````````````````````````````` |