Repository: numpy/numpy
File: numpy/lib/tests/test_function_base.py (Python)

Code before:
        lambda x: _make_complex(0, x),
        lambda x: _make_complex(x, np.multiply(x, -2))
    ], ids=[
        'real',
        'complex-real',
        'complex-imag',
        'complex-both'
    ])
    def sc(self, request):
        """ scale function used by the below tests """
        return request.param

    def test_non_finite_any_nan(self, sc):
        """ test that nans are propagated """
        assert_equal(np.interp(0.5, [np.nan,      1], sc([     0,     10])), sc(np.nan))
        assert_equal(np.interp(0.5, [     0, np.nan], sc([     0,     10])), sc(np.nan))
        assert_equal(np.interp(0.5, [     0,      1], sc([np.nan,     10])), sc(np.nan))
        assert_equal(np.interp(0.5, [     0,      1], sc([     0, np.nan])), sc(np.nan))

    def test_non_finite_inf(self, sc):
        """ Test that interp between opposite infs gives nan """
        inf = np.inf
        nan = np.nan
        assert_equal(np.interp(0.5, [-inf, +inf], sc([      0,      10])), sc(nan))
        assert_equal(np.interp(0.5, [      0,       1], sc([-inf, +inf])), sc(nan))
        assert_equal(np.interp(0.5, [      0,       1], sc([+inf, -inf])), sc(nan))

        # unless the y values are equal
        assert_equal(np.interp(0.5, [-np.inf, +np.inf], sc([     10,      10])), sc(10))

    def test_non_finite_half_inf_xf(self, sc):
        """ Test that interp where both axes have a bound at inf gives nan """
        inf = np.inf
        nan = np.nan
        assert_equal(np.interp(0.5, [-inf,       1], sc([-inf,      10])), sc(nan))
        assert_equal(np.interp(0.5, [-inf,       1], sc([+inf,      10])), sc(nan))
        assert_equal(np.interp(0.5, [-inf,       1], sc([      0, -inf])), sc(nan))
        assert_equal(np.interp(0.5, [-inf,       1], sc([      0, +inf])), sc(nan))
        assert_equal(np.interp(0.5, [      0, +inf], sc([-inf,      10])), sc(nan))
        assert_equal(np.interp(0.5, [      0, +inf], sc([+inf,      10])), sc(nan))
        assert_equal(np.interp(0.5, [      0, +inf], sc([      0, -inf])), sc(nan))
        assert_equal(np.interp(0.5, [      0, +inf], sc([      0, +inf])), sc(nan))

    def test_non_finite_half_inf_x(self, sc):
        """ Test interp where the x axis has a bound at inf """
        assert_equal(np.interp(0.5, [-np.inf, -np.inf], sc([0, 10])), sc(10))
        assert_equal(np.interp(0.5, [-np.inf, 1      ], sc([0, 10])), sc(10))  # noqa: E202
        assert_equal(np.interp(0.5, [      0, +np.inf], sc([0, 10])), sc(0))
        assert_equal(np.interp(0.5, [+np.inf, +np.inf], sc([0, 10])), sc(0))

    def test_non_finite_half_inf_f(self, sc):

Review comment (suggestion):
```suggestion
        assert_equal(np.interp(0.5, [-inf, +inf], sc([   0,   10])), sc(nan))
        assert_equal(np.interp(0.5, [   0,    1], sc([-inf, +inf])), sc(nan))
        assert_equal(np.interp(0.5, [   0,    1], sc([+inf, -inf])), sc(nan))
```

Code after:
        lambda x: _make_complex(0, x),
        lambda x: _make_complex(x, np.multiply(x, -2))
    ], ids=[
        'real',
        'complex-real',
        'complex-imag',
        'complex-both'
    ])
    def sc(self, request):
        """ scale function used by the below tests """
        return request.param

    def test_non_finite_any_nan(self, sc):
        """ test that nans are propagated """
        assert_equal(np.interp(0.5, [np.nan,      1], sc([     0,     10])), sc(np.nan))
        assert_equal(np.interp(0.5, [     0, np.nan], sc([     0,     10])), sc(np.nan))
        assert_equal(np.interp(0.5, [     0,      1], sc([np.nan,     10])), sc(np.nan))
        assert_equal(np.interp(0.5, [     0,      1], sc([     0, np.nan])), sc(np.nan))

    def test_non_finite_inf(self, sc):
        """ Test that interp between opposite infs gives nan """
        inf = np.inf
        nan = np.nan
        assert_equal(np.interp(0.5, [-inf, +inf], sc([   0,   10])), sc(nan))
        assert_equal(np.interp(0.5, [   0,    1], sc([-inf, +inf])), sc(nan))
        assert_equal(np.interp(0.5, [   0,    1], sc([+inf, -inf])), sc(nan))

        # unless the y values are equal
        assert_equal(np.interp(0.5, [-np.inf, +np.inf], sc([     10,      10])), sc(10))

    def test_non_finite_half_inf_xf(self, sc):
        """ Test that interp where both axes have a bound at inf gives nan """
        inf = np.inf
        nan = np.nan
        assert_equal(np.interp(0.5, [-inf,    1], sc([-inf,   10])), sc(nan))
        assert_equal(np.interp(0.5, [-inf,    1], sc([+inf,   10])), sc(nan))
        assert_equal(np.interp(0.5, [-inf,    1], sc([   0, -inf])), sc(nan))
        assert_equal(np.interp(0.5, [-inf,    1], sc([   0, +inf])), sc(nan))
        assert_equal(np.interp(0.5, [   0, +inf], sc([-inf,   10])), sc(nan))
        assert_equal(np.interp(0.5, [   0, +inf], sc([+inf,   10])), sc(nan))
        assert_equal(np.interp(0.5, [   0, +inf], sc([   0, -inf])), sc(nan))
        assert_equal(np.interp(0.5, [   0, +inf], sc([   0, +inf])), sc(nan))

    def test_non_finite_half_inf_x(self, sc):
        """ Test interp where the x axis has a bound at inf """
        assert_equal(np.interp(0.5, [-np.inf, -np.inf], sc([0, 10])), sc(10))
        assert_equal(np.interp(0.5, [-np.inf, 1      ], sc([0, 10])), sc(10))  # noqa: E202
        assert_equal(np.interp(0.5, [      0, +np.inf], sc([0, 10])), sc(0))
        assert_equal(np.interp(0.5, [+np.inf, +np.inf], sc([0, 10])), sc(0))

    def test_non_finite_half_inf_f(self, sc):