diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2018-09-18 14:40:13 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-18 14:40:13 -0500 |
commit | a19d9de805f4cef2dfb02f7e2c1ecd3c55ab2b6a (patch) | |
tree | bd2954dd08ee878239074c32ee1ba1bda7abfe03 /numpy/lib/tests/test_arraypad.py | |
parent | cef7394a646ad1ef866f37f47253b78d3ba57458 (diff) | |
parent | d26ad30deea8e11d3614f8b72b58e1350a055a30 (diff) | |
download | numpy-a19d9de805f4cef2dfb02f7e2c1ecd3c55ab2b6a.tar.gz |
Merge pull request #11961 from eric-wieser/pad-tests
TST: Add more tests for np.pad
Diffstat (limited to 'numpy/lib/tests/test_arraypad.py')
-rw-r--r-- | numpy/lib/tests/test_arraypad.py | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/numpy/lib/tests/test_arraypad.py b/numpy/lib/tests/test_arraypad.py index 243110391..e62fccaa0 100644 --- a/numpy/lib/tests/test_arraypad.py +++ b/numpy/lib/tests/test_arraypad.py @@ -3,8 +3,11 @@ """ from __future__ import division, absolute_import, print_function +import pytest + import numpy as np -from numpy.testing import (assert_array_equal, assert_raises, assert_allclose,) +from numpy.testing import (assert_array_equal, assert_raises, assert_allclose, + assert_equal) from numpy.lib import pad @@ -344,6 +347,20 @@ class TestStatistic(object): ) assert_array_equal(a, b) + @pytest.mark.parametrize("mode", [ + pytest.param("mean", marks=pytest.mark.xfail(reason="gh-11216")), + "median", + "minimum", + "maximum" + ]) + def test_same_prepend_append(self, mode): + """ Test that appended and prepended values are equal """ + # This test is constructed to trigger floating point rounding errors in + # a way that caused gh-11216 for mode=='mean' + a = np.array([-1, 2, -1]) + np.array([0, 1e-12, 0], dtype=np.float64) + a = np.pad(a, (1, 1), mode) + assert_equal(a[0], a[-1]) + class TestConstant(object): def test_check_constant(self): @@ -557,6 +574,25 @@ class TestLinearRamp(object): [0., 0., 0., 0., 0., 0., 0., 0., 0.]]) assert_allclose(test, expected) + @pytest.mark.xfail(exceptions=(AssertionError,)) + def test_object_array(self): + from fractions import Fraction + arr = np.array([Fraction(1, 2), Fraction(-1, 2)]) + actual = np.pad(arr, (2, 3), mode='linear_ramp', end_values=0) + + # deliberately chosen to have a non-power-of-2 denominator such that + # rounding to floats causes a failure. + expected = np.array([ + Fraction( 0, 12), + Fraction( 3, 12), + Fraction( 6, 12), + Fraction(-6, 12), + Fraction(-4, 12), + Fraction(-2, 12), + Fraction(-0, 12), + ]) + assert_equal(actual, expected) + class TestReflect(object): def test_check_simple(self): @@ -902,6 +938,11 @@ class TestWrap(object): b = np.array([3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1]) assert_array_equal(a, b) + def test_pad_with_zero(self): + a = np.ones((3, 5)) + b = np.pad(a, (0, 5), mode="wrap") + assert_array_equal(a, b[:-5, :-5]) + class TestStatLen(object): def test_check_simple(self): |