diff options
author | Matti Picus <matti.picus@gmail.com> | 2020-01-22 05:34:40 +1100 |
---|---|---|
committer | Sebastian Berg <sebastian@sipsolutions.net> | 2020-01-21 10:34:40 -0800 |
commit | 287a9d0646c9cc40385615264348a637a7c57205 (patch) | |
tree | 15ee6f057044e13284ae4378b0422e23f099a97a /numpy/lib/tests/test_arraypad.py | |
parent | c3441dfb3fdde09008b19a2998331d3fc2dd0cd1 (diff) | |
download | numpy-287a9d0646c9cc40385615264348a637a7c57205.tar.gz |
NEP: issue deprecation warning when creating ragged array (NEP 34)
This implements NEP 34.
Diffstat (limited to 'numpy/lib/tests/test_arraypad.py')
-rw-r--r-- | numpy/lib/tests/test_arraypad.py | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/numpy/lib/tests/test_arraypad.py b/numpy/lib/tests/test_arraypad.py index cd75b4ac4..75db5928b 100644 --- a/numpy/lib/tests/test_arraypad.py +++ b/numpy/lib/tests/test_arraypad.py @@ -1260,24 +1260,29 @@ class TestPadWidth: with pytest.raises(ValueError, match=match): np.pad(arr, pad_width, mode) - @pytest.mark.parametrize("pad_width", [ - "3", - "word", - None, - object(), - 3.4, - ((2, 3, 4), (3, 2)), # dtype=object (tuple) - complex(1, -1), - ((-2.1, 3), (3, 2)), + @pytest.mark.parametrize("pad_width, dtype", [ + ("3", None), + ("word", None), + (None, None), + (object(), None), + (3.4, None), + (((2, 3, 4), (3, 2)), object), + (complex(1, -1), None), + (((-2.1, 3), (3, 2)), None), ]) @pytest.mark.parametrize("mode", _all_modes.keys()) - def test_bad_type(self, pad_width, mode): + def test_bad_type(self, pad_width, dtype, mode): arr = np.arange(30).reshape((6, 5)) match = "`pad_width` must be of integral type." - with pytest.raises(TypeError, match=match): - np.pad(arr, pad_width, mode) - with pytest.raises(TypeError, match=match): - np.pad(arr, np.array(pad_width), mode) + if dtype is not None: + # avoid DeprecationWarning when not specifying dtype + with pytest.raises(TypeError, match=match): + np.pad(arr, np.array(pad_width, dtype=dtype), mode) + else: + with pytest.raises(TypeError, match=match): + np.pad(arr, pad_width, mode) + with pytest.raises(TypeError, match=match): + np.pad(arr, np.array(pad_width), mode) def test_pad_width_as_ndarray(self): a = np.arange(12) |