diff options
author | Jay Bourque <jay.bourque@continuum.io> | 2013-12-20 12:08:53 -0600 |
---|---|---|
committer | Jay Bourque <jay.bourque@continuum.io> | 2014-02-25 14:53:28 -0600 |
commit | 1f9d4d2613d7c8bccf7e16720e8d0fa87e74e34a (patch) | |
tree | 76f7d671d3a593849127f74d53b6beed6ae3911c /doc/source/reference/c-api.array.rst | |
parent | 56eb28ed29573d644696743804decf3a8d3260fc (diff) | |
download | numpy-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/source/reference/c-api.array.rst')
-rw-r--r-- | doc/source/reference/c-api.array.rst | 8 |
1 files changed, 6 insertions, 2 deletions
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) |