Repository: numpy/numpy
File: numpy/_core/tests/test_numeric.py (Python)

Code before:
        a = np.array([[1, 2, 3, "NaT"]], dtype="m8[ns]")
        assert np.isclose(a, a, atol=0, equal_nan=True).all()
        assert np.isclose(a, a, atol=np.timedelta64(1, "ns"), equal_nan=True).all()
        assert np.allclose(a, a, atol=0, equal_nan=True)
        assert np.allclose(a, a, atol=np.timedelta64(1, "ns"), equal_nan=True)

    def test_tol_warnings(self):
        a = np.array([1, 2, 3])
        b = np.array([np.inf, np.nan, 1])

        for i in b:
            for j in b:
                # Making sure that i and j are not both numbers,
                #because that won't create a warning
                if (i == 1) and (j == 1):
                    continue

                with warnings.catch_warnings(record=True) as w:

                    warnings.simplefilter("always")
                    c = np.isclose(a, a, atol=i, rtol=j)
                    assert len(w) == 1
                    assert issubclass(w[-1].category, RuntimeWarning)
                    assert (
                        f"One of rtol or atol is not valid, atol: {i}, rtol: {j}"
                    ) in str(w[-1].message)


class TestStdVar:
    def _create_data(self):
        A = np.array([1, -1, 1, -1])
        real_var = 1
        return A, real_var

    def test_basic(self):
        A, real_var = self._create_data()
        assert_almost_equal(np.var(A), real_var)
        assert_almost_equal(np.std(A)**2, real_var)

    def test_scalars(self):
        assert_equal(np.var(1), 0)
        assert_equal(np.std(1), 0)

    def test_ddof1(self):
        A, real_var = self._create_data()
        assert_almost_equal(np.var(A, ddof=1),
                            real_var * len(A) / (len(A) - 1))
        assert_almost_equal(np.std(A, ddof=1)**2,
                            real_var * len(A) / (len(A) - 1))

    def test_ddof2(self):

Review comment (suggestion):
```suggestion
                    expected = f"One of rtol or atol is not valid, atol: {i}, rtol: {j}"
                    assert expected, in str(w[-1].message)
```
Let's see if this is <88

Code after:
        # Allclose currently works for timedelta64 as long as `atol` is
        # an integer or also a timedelta64
        a = np.array([[1, 2, 3, "NaT"]], dtype="m8[ns]")
        assert np.isclose(a, a, atol=0, equal_nan=True).all()
        assert np.isclose(a, a, atol=np.timedelta64(1, "ns"), equal_nan=True).all()
        assert np.allclose(a, a, atol=0, equal_nan=True)
        assert np.allclose(a, a, atol=np.timedelta64(1, "ns"), equal_nan=True)

    def test_tol_warnings(self):
        a = np.array([1, 2, 3])
        b = np.array([np.inf, np.nan, 1])

        for i in b:
            for j in b:
                # Making sure that i and j are not both numbers,
                # because that won't create a warning
                if (i == 1) and (j == 1):
                    continue

                with warnings.catch_warnings(record=True) as w:

                    warnings.simplefilter("always")
                    c = np.isclose(a, a, atol=i, rtol=j)
                    assert len(w) == 1
                    assert issubclass(w[-1].category, RuntimeWarning)
                    expected = f"One of rtol or atol is not valid, atol: {i}, rtol: {j}"
                    assert expected in str(w[-1].message)


class TestStdVar:
    def _create_data(self):
        A = np.array([1, -1, 1, -1])
        real_var = 1
        return A, real_var

    def test_basic(self):
        A, real_var = self._create_data()
        assert_almost_equal(np.var(A), real_var)
        assert_almost_equal(np.std(A)**2, real_var)

    def test_scalars(self):
        assert_equal(np.var(1), 0)
        assert_equal(np.std(1), 0)

    def test_ddof1(self):
        A, real_var = self._create_data()
        assert_almost_equal(np.var(A, ddof=1),
                            real_var * len(A) / (len(A) - 1))
        assert_almost_equal(np.std(A, ddof=1)**2,
                            real_var * len(A) / (len(A) - 1))