Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
test_deprecations.py66 linesDownload Raw Back to tests
1"""Test deprecation and future warnings.
2
3"""
4import pytest
5
6import numpy as np
7from numpy.ma.core import MaskedArrayFutureWarning
8from numpy.ma.testutils import assert_equal
9
10
11class TestArgsort:
12    """ gh-8701 """
13    def _test_base(self, argsort, cls):
14        arr_0d = np.array(1).view(cls)
15        argsort(arr_0d)
16
17        arr_1d = np.array([1, 2, 3]).view(cls)
18        argsort(arr_1d)
19
20        # argsort has a bad default for >1d arrays
21        arr_2d = np.array([[1, 2], [3, 4]]).view(cls)
22        result = pytest.warns(
23            np.ma.core.MaskedArrayFutureWarning, argsort, arr_2d)
24        assert_equal(result, argsort(arr_2d, axis=None))
25
26        # should be no warnings for explicitly specifying it
27        argsort(arr_2d, axis=None)
28        argsort(arr_2d, axis=-1)
29
30    def test_function_ndarray(self):
31        return self._test_base(np.ma.argsort, np.ndarray)
32
33    def test_function_maskedarray(self):
34        return self._test_base(np.ma.argsort, np.ma.MaskedArray)
35
36    def test_method(self):
37        return self._test_base(np.ma.MaskedArray.argsort, np.ma.MaskedArray)
38
39
40class TestMinimumMaximum:
41
42    def test_axis_default(self):
43        # NumPy 1.13, 2017-05-06
44
45        data1d = np.ma.arange(6)
46        data2d = data1d.reshape(2, 3)
47
48        ma_min = np.ma.minimum.reduce
49        ma_max = np.ma.maximum.reduce
50
51        # check that the default axis is still None, but warns on 2d arrays
52        result = pytest.warns(MaskedArrayFutureWarning, ma_max, data2d)
53        assert_equal(result, ma_max(data2d, axis=None))
54
55        result = pytest.warns(MaskedArrayFutureWarning, ma_min, data2d)
56        assert_equal(result, ma_min(data2d, axis=None))
57
58        # no warnings on 1d, as both new and old defaults are equivalent
59        result = ma_min(data1d)
60        assert_equal(result, ma_min(data1d, axis=None))
61        assert_equal(result, ma_min(data1d, axis=0))
62
63        result = ma_max(data1d)
64        assert_equal(result, ma_max(data1d, axis=None))
65        assert_equal(result, ma_max(data1d, axis=0))
66 
codekingpro/portable-devtools · Team Ai