diff options
author | Lars Grueter <lagru@mailbox.org> | 2019-07-24 12:40:30 +0200 |
---|---|---|
committer | Lars Grueter <lagru@mailbox.org> | 2019-08-09 19:18:40 +0200 |
commit | 6f009fce15e7bea11c31c871170a37071761eac4 (patch) | |
tree | 99a6496a4d1a15fee0b47389e342968651fab52d /numpy/lib/tests/test_arraypad.py | |
parent | 691e6dbe1fd70c7638daf3ab38e877419babeed2 (diff) | |
download | numpy-6f009fce15e7bea11c31c871170a37071761eac4.tar.gz |
MAINT: Clearer error while padding stat_length=0
Provides a clearer error message if stat_length=0 is the cause of an
exception (mean and median return nan with warnings) as well as tests
covering this behavior.
Note: This shouldn't change the behavior/API except for the content of
the raised ValueError.
Diffstat (limited to 'numpy/lib/tests/test_arraypad.py')
-rw-r--r-- | numpy/lib/tests/test_arraypad.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/numpy/lib/tests/test_arraypad.py b/numpy/lib/tests/test_arraypad.py index b7630cdcd..b6dd3b31c 100644 --- a/numpy/lib/tests/test_arraypad.py +++ b/numpy/lib/tests/test_arraypad.py @@ -469,6 +469,29 @@ class TestStatistic(object): ) assert_array_equal(a, b) + @pytest.mark.filterwarnings("ignore:Mean of empty slice:RuntimeWarning") + @pytest.mark.filterwarnings( + "ignore:invalid value encountered in (true_divide|double_scalars):" + "RuntimeWarning" + ) + @pytest.mark.parametrize("mode", ["mean", "median"]) + def test_zero_stat_length_valid(self, mode): + arr = np.pad([1., 2.], (1, 2), mode, stat_length=0) + expected = np.array([np.nan, 1., 2., np.nan, np.nan]) + assert_equal(arr, expected) + + @pytest.mark.parametrize("mode", ["minimum", "maximum"]) + def test_zero_stat_length_invalid(self, mode): + match = "stat_length of 0 yields no value for padding" + with pytest.raises(ValueError, match=match): + np.pad([1., 2.], 0, mode, stat_length=0) + with pytest.raises(ValueError, match=match): + np.pad([1., 2.], 0, mode, stat_length=(1, 0)) + with pytest.raises(ValueError, match=match): + np.pad([1., 2.], 1, mode, stat_length=0) + with pytest.raises(ValueError, match=match): + np.pad([1., 2.], 1, mode, stat_length=(1, 0)) + class TestConstant(object): def test_check_constant(self): |