diff options
-rw-r--r-- | doc/release/1.14.0-notes.rst | 6 | ||||
-rw-r--r-- | numpy/add_newdocs.py | 6 | ||||
-rw-r--r-- | numpy/core/src/multiarray/multiarraymodule.c | 2 | ||||
-rw-r--r-- | numpy/core/tests/test_numeric.py | 3 |
4 files changed, 13 insertions, 4 deletions
diff --git a/doc/release/1.14.0-notes.rst b/doc/release/1.14.0-notes.rst index fdb1341af..a7e208c99 100644 --- a/doc/release/1.14.0-notes.rst +++ b/doc/release/1.14.0-notes.rst @@ -124,6 +124,12 @@ the result is always a view on the original masked array. This breaks any code that used ``masked_arr.squeeze() is np.ma.masked``, but fixes code that writes to the result of `.squeeze()`. +Renamed first parameter of ``can_cast`` from ``from`` to ``from_`` +------------------------------------------------------------------ +The previous parameter name ``from`` is a reserved keyword in Python, which made +it difficult to pass the argument by name. This has been fixed by renaming +the parameter to ``from_``. + C API changes ============= diff --git a/numpy/add_newdocs.py b/numpy/add_newdocs.py index 687204fc1..477a3db34 100644 --- a/numpy/add_newdocs.py +++ b/numpy/add_newdocs.py @@ -1589,7 +1589,7 @@ add_newdoc('numpy.core.multiarray', 'lexsort', add_newdoc('numpy.core.multiarray', 'can_cast', """ - can_cast(from, totype, casting = 'safe') + can_cast(from_, to, casting='safe') Returns True if cast between data types can occur according to the casting rule. If from is a scalar or array scalar, also returns @@ -1598,9 +1598,9 @@ add_newdoc('numpy.core.multiarray', 'can_cast', Parameters ---------- - from : dtype, dtype specifier, scalar, or array + from_ : dtype, dtype specifier, scalar, or array Data type, scalar, or array to cast from. - totype : dtype or dtype specifier + to : dtype or dtype specifier Data type to cast to. casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional Controls what kind of data casting may occur. diff --git a/numpy/core/src/multiarray/multiarraymodule.c b/numpy/core/src/multiarray/multiarraymodule.c index ca481a11f..72515a3aa 100644 --- a/numpy/core/src/multiarray/multiarraymodule.c +++ b/numpy/core/src/multiarray/multiarraymodule.c @@ -3224,7 +3224,7 @@ array_can_cast_safely(PyObject *NPY_UNUSED(self), PyObject *args, npy_bool ret; PyObject *retobj = NULL; NPY_CASTING casting = NPY_SAFE_CASTING; - static char *kwlist[] = {"from", "to", "casting", NULL}; + static char *kwlist[] = {"from_", "to", "casting", NULL}; if(!PyArg_ParseTupleAndKeywords(args, kwds, "OO&|O&:can_cast", kwlist, &from_obj, diff --git a/numpy/core/tests/test_numeric.py b/numpy/core/tests/test_numeric.py index bdb3dfe69..d62e18b93 100644 --- a/numpy/core/tests/test_numeric.py +++ b/numpy/core/tests/test_numeric.py @@ -872,6 +872,9 @@ class TestTypes(object): assert_raises(TypeError, np.can_cast, 'i4', None) assert_raises(TypeError, np.can_cast, None, 'i4') + # Also test keyword arguments + assert_(np.can_cast(from_=np.int32, to=np.int64)) + # Custom exception class to test exception propagation in fromiter class NIterError(Exception): |