summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorJay Bourque <jay.bourque@continuum.io>2013-12-20 12:08:53 -0600
committerJay Bourque <jay.bourque@continuum.io>2014-02-25 14:53:28 -0600
commit1f9d4d2613d7c8bccf7e16720e8d0fa87e74e34a (patch)
tree76f7d671d3a593849127f74d53b6beed6ae3911c /doc
parent56eb28ed29573d644696743804decf3a8d3260fc (diff)
downloadnumpy-1f9d4d2613d7c8bccf7e16720e8d0fa87e74e34a.tar.gz
BUG: Fix promote_types, can_cast, as astype issues
- promote_types does not return correct string size for integer and string arguments. Fix so that integer and string types are promoted to string type that is long enough to hold integer type safely cast to string. - can_cast incorrectly returns True for certain integer and string types. Fix so that can_cast only returns True if string type is long enough to hold integer type safely cast to string. - calling astype to convert integer to string should fail if string type is not long enough to hold integer converted to string and casting argument is set to "safe".
Diffstat (limited to 'doc')
-rw-r--r--doc/release/1.9.0-notes.rst24
-rw-r--r--doc/source/reference/c-api.array.rst8
2 files changed, 30 insertions, 2 deletions
diff --git a/doc/release/1.9.0-notes.rst b/doc/release/1.9.0-notes.rst
index 9a58cbf3a..4b51f6064 100644
--- a/doc/release/1.9.0-notes.rst
+++ b/doc/release/1.9.0-notes.rst
@@ -179,6 +179,30 @@ indexing operations:
* Indexing with more then one ellipsis (`...`) is deprecated.
+promote_types and string dtype
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+promote_types function now returns a valid string length when given an
+integer or float dtype as one argument and a string dtype as another argument.
+Previously it always returned the input string dtype, even if it wasn't
+long enough to store the max integer/float value converted to a string.
+
+
+can_cast and string dtype
+~~~~~~~~~~~~~~~~~~~~~~~~~
+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.
+
+
+astype and string dtype
+~~~~~~~~~~~~~~~~~~~~~~~
+astype method now returns an error if the string dtype to cast to is not long
+enough in "safe" casting mode to hold the max value of integer/float array that
+is being casted. Previously the casting was allowed even if the result was
+truncated.
+
+
C-API
~~~~~
diff --git a/doc/source/reference/c-api.array.rst b/doc/source/reference/c-api.array.rst
index 351b4238e..3ce49cb85 100644
--- a/doc/source/reference/c-api.array.rst
+++ b/doc/source/reference/c-api.array.rst
@@ -1036,7 +1036,10 @@ Converting data types
the casting rule *casting*. For simple types with :cdata:`NPY_SAFE_CASTING`,
this is basically a wrapper around :cfunc:`PyArray_CanCastSafely`, but
for flexible types such as strings or unicode, it produces results
- taking into account their sizes.
+ taking into account their sizes. Integer and float types can only be cast
+ to a string or unicode type using :cdata:`NPY_SAFE_CASTING` if the string
+ or unicode type is big enough to hold the max value of the integer/float
+ type being cast from.
.. cfunction:: int PyArray_CanCastArrayTo(PyArrayObject* arr, PyArray_Descr* totype, NPY_CASTING casting)
@@ -1073,7 +1076,8 @@ Converting data types
Finds the data type of smallest size and kind to which *type1* and
*type2* may be safely converted. This function is symmetric and
- associative.
+ associative. A string or unicode result will be the proper size for
+ storing the max value of the input types converted to a string or unicode.
.. cfunction:: PyArray_Descr* PyArray_ResultType(npy_intp narrs, PyArrayObject**arrs, npy_intp ndtypes, PyArray_Descr**dtypes)