summaryrefslogtreecommitdiff
path: root/numpy/core/multiarray.py
diff options
context:
space:
mode:
authorMarten van Kerkwijk <mhvk@astro.utoronto.ca>2019-05-27 21:40:07 -0400
committerMarten van Kerkwijk <mhvk@astro.utoronto.ca>2019-06-12 14:48:30 -0400
commite12c6bda05c8b8c024f04f2d41416e5e63971b3e (patch)
treea34cb770b014957b80b61e9d8b105382422bdf86 /numpy/core/multiarray.py
parent90ee55557537f5fc2f02cca57f43f8494a5c497d (diff)
downloadnumpy-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/core/multiarray.py')
-rw-r--r--numpy/core/multiarray.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/numpy/core/multiarray.py b/numpy/core/multiarray.py
index 8006dd9b5..118562c89 100644
--- a/numpy/core/multiarray.py
+++ b/numpy/core/multiarray.py
@@ -496,11 +496,15 @@ def can_cast(from_, to, casting=None):
Notes
-----
- Starting in NumPy 1.9, can_cast function now returns False in 'safe'
- casting mode for integer/float dtype and string dtype if the string dtype
- length is not long enough to store the max integer/float value converted
- to a string. Previously can_cast in 'safe' mode returned True for
- integer/float dtype and a string dtype of any length.
+ .. versionchanged:: 1.17.0
+ Casting between a simple data type and a structured one is possible only
+ for "unsafe" casting. Casting to multiple fields is allowed, but
+ casting from multiple fields is not.
+
+ .. versionchanged:: 1.9.0
+ Casting from numeric to string types in 'safe' casting mode requires
+ that the string dtype length is long enough to store the maximum
+ integer/float value converted.
See also
--------