diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2017-09-06 13:34:44 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-06 13:34:44 -0500 |
commit | 6810e1e9015538bf030d7e307f11f0828e3dacbe (patch) | |
tree | 2a61b0e29edb8f4e3ce8e9b8de43b8013af7f20b | |
parent | cf7ba54953b360905982d346c6376836736090ef (diff) | |
parent | 51eb2bb7be8ef40ead60448bca6a5384efc95697 (diff) | |
download | numpy-6810e1e9015538bf030d7e307f11f0828e3dacbe.tar.gz |
Merge pull request #9658 from MSeifert04/fix_keyword_as_parameter_name
BUG: Fix usage of keyword "from" as argument name for "can_cast".
-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): |