diff options
author | Sebastian Berg <sebastian@sipsolutions.net> | 2019-09-26 09:36:45 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-26 09:36:45 -0700 |
commit | cb89f88af361f045c560886b1268038ba5ea9cc2 (patch) | |
tree | 65301c9c0e3d0750093ad7890341f809460d8f9d | |
parent | 504ba4bd9d414fecbfe61c511adf0027208e29e2 (diff) | |
parent | 65e91e4d711b86fe2705202251791a2e30a3c075 (diff) | |
download | numpy-cb89f88af361f045c560886b1268038ba5ea9cc2.tar.gz |
Merge pull request #14583 from mattip/select-deprecation
DEP: remove deprecated select behaviour
-rw-r--r-- | doc/release/upcoming_changes/14583.expired.rst | 2 | ||||
-rw-r--r-- | numpy/lib/function_base.py | 24 | ||||
-rw-r--r-- | numpy/lib/tests/test_function_base.py | 24 |
3 files changed, 12 insertions, 38 deletions
diff --git a/doc/release/upcoming_changes/14583.expired.rst b/doc/release/upcoming_changes/14583.expired.rst new file mode 100644 index 000000000..1fad06309 --- /dev/null +++ b/doc/release/upcoming_changes/14583.expired.rst @@ -0,0 +1,2 @@ +* Remove deprecated support for boolean and empty condition lists in + `numpy.select` diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index e39bbf63a..ebf918012 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -682,11 +682,7 @@ def select(condlist, choicelist, default=0): # Now that the dtype is known, handle the deprecated select([], []) case if len(condlist) == 0: - # 2014-02-24, 1.9 - warnings.warn("select with an empty condition list is not possible" - "and will be deprecated", - DeprecationWarning, stacklevel=3) - return np.asarray(default)[()] + raise ValueError("select with an empty condition list is not possible") choicelist = [np.asarray(choice) for choice in choicelist] choicelist.append(np.asarray(default)) @@ -702,25 +698,11 @@ def select(condlist, choicelist, default=0): choicelist = np.broadcast_arrays(*choicelist) # If cond array is not an ndarray in boolean format or scalar bool, abort. - deprecated_ints = False for i in range(len(condlist)): cond = condlist[i] if cond.dtype.type is not np.bool_: - if np.issubdtype(cond.dtype, np.integer): - # A previous implementation accepted int ndarrays accidentally. - # Supported here deliberately, but deprecated. - condlist[i] = condlist[i].astype(bool) - deprecated_ints = True - else: - raise ValueError( - 'invalid entry {} in condlist: should be boolean ndarray'.format(i)) - - if deprecated_ints: - # 2014-02-24, 1.9 - msg = "select condlists containing integer ndarrays is deprecated " \ - "and will be removed in the future. Use `.astype(bool)` to " \ - "convert to bools." - warnings.warn(msg, DeprecationWarning, stacklevel=3) + raise TypeError( + 'invalid entry {} in condlist: should be boolean ndarray'.format(i)) if choicelist[0].ndim == 0: # This may be common, so avoid the call. diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py index eae52c002..1eae8ccfb 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -423,27 +423,17 @@ class TestSelect(object): assert_equal(select([m], [d]), [0, 0, 0, np.nan, 0, 0]) def test_deprecated_empty(self): - with warnings.catch_warnings(record=True): - warnings.simplefilter("always") - assert_equal(select([], [], 3j), 3j) - - with warnings.catch_warnings(): - warnings.simplefilter("always") - assert_warns(DeprecationWarning, select, [], []) - warnings.simplefilter("error") - assert_raises(DeprecationWarning, select, [], []) + assert_raises(ValueError, select, [], [], 3j) + assert_raises(ValueError, select, [], []) def test_non_bool_deprecation(self): choices = self.choices conditions = self.conditions[:] - with warnings.catch_warnings(): - warnings.filterwarnings("always") - conditions[0] = conditions[0].astype(np.int_) - assert_warns(DeprecationWarning, select, conditions, choices) - conditions[0] = conditions[0].astype(np.uint8) - assert_warns(DeprecationWarning, select, conditions, choices) - warnings.filterwarnings("error") - assert_raises(DeprecationWarning, select, conditions, choices) + conditions[0] = conditions[0].astype(np.int_) + assert_raises(TypeError, select, conditions, choices) + conditions[0] = conditions[0].astype(np.uint8) + assert_raises(TypeError, select, conditions, choices) + assert_raises(TypeError, select, conditions, choices) def test_many_arguments(self): # This used to be limited by NPY_MAXARGS == 32 |