diff options
Diffstat (limited to 'numpy/ma/tests')
-rw-r--r-- | numpy/ma/tests/test_core.py | 84 | ||||
-rw-r--r-- | numpy/ma/tests/test_deprecations.py | 6 | ||||
-rw-r--r-- | numpy/ma/tests/test_extras.py | 43 | ||||
-rw-r--r-- | numpy/ma/tests/test_mrecords.py | 8 | ||||
-rw-r--r-- | numpy/ma/tests/test_old_ma.py | 8 | ||||
-rw-r--r-- | numpy/ma/tests/test_regression.py | 8 | ||||
-rw-r--r-- | numpy/ma/tests/test_subclassing.py | 8 |
7 files changed, 94 insertions, 71 deletions
diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py index b72ce56aa..98fc7dd97 100644 --- a/numpy/ma/tests/test_core.py +++ b/numpy/ma/tests/test_core.py @@ -4,8 +4,6 @@ :author: Pierre Gerard-Marchant :contact: pierregm_at_uga_dot_edu """ -from __future__ import division, absolute_import, print_function - __author__ = "Pierre GF Gerard-Marchant" import sys @@ -65,7 +63,7 @@ num_dts = [np.dtype(dt_) for dt_ in '?bhilqBHILQefdgFD'] num_ids = [dt_.char for dt_ in num_dts] -class TestMaskedArray(object): +class TestMaskedArray: # Base test class for MaskedArrays. def setup(self): @@ -449,6 +447,21 @@ class TestMaskedArray(object): assert_equal(copied.mask, [0, 0, 0]) assert_equal(a.mask, [0, 1, 0]) + def test_format(self): + a = array([0, 1, 2], mask=[False, True, False]) + assert_equal(format(a), "[0 -- 2]") + assert_equal(format(masked), "--") + assert_equal(format(masked, ""), "--") + + # Postponed from PR #15410, perhaps address in the future. + # assert_equal(format(masked, " >5"), " --") + # assert_equal(format(masked, " <5"), "-- ") + + # Expect a FutureWarning for using format_spec with MaskedElement + with assert_warns(FutureWarning): + with_format_string = format(masked, " >5") + assert_equal(with_format_string, "--") + def test_str_repr(self): a = array([0, 1, 2], mask=[False, True, False]) assert_equal(str(a), '[0 -- 2]') @@ -936,7 +949,7 @@ class TestMaskedArray(object): def test_object_with_array(self): mx1 = masked_array([1.], mask=[True]) mx2 = masked_array([1., 2.]) - mx = masked_array([mx1, mx2], mask=[False, True]) + mx = masked_array([mx1, mx2], mask=[False, True], dtype=object) assert_(mx[0] is mx1) assert_(mx[1] is not mx2) assert_(np.all(mx[1].data == mx2.data)) @@ -946,7 +959,7 @@ class TestMaskedArray(object): assert_(mx2[0] == 0.) -class TestMaskedArrayArithmetic(object): +class TestMaskedArrayArithmetic: # Base test class for MaskedArrays. def setup(self): @@ -1558,7 +1571,11 @@ class TestMaskedArrayArithmetic(object): assert_equal(test.mask, [True, True]) assert_(test.fill_value == True) - # test = (a[0] == b) # doesn't work in Python2 + test = (a[0] == b) + assert_equal(test.data, [False, False]) + assert_equal(test.mask, [True, False]) + assert_(test.fill_value == True) + test = (b == a[0]) assert_equal(test.data, [False, False]) assert_equal(test.mask, [True, False]) @@ -1586,7 +1603,11 @@ class TestMaskedArrayArithmetic(object): assert_equal(test.mask, [True, True]) assert_(test.fill_value == True) - # test = (a[0] != b) # doesn't work in Python2 + test = (a[0] != b) + assert_equal(test.data, [True, True]) + assert_equal(test.mask, [True, False]) + assert_(test.fill_value == True) + test = (b != a[0]) assert_equal(test.data, [True, True]) assert_equal(test.mask, [True, False]) @@ -1615,7 +1636,11 @@ class TestMaskedArrayArithmetic(object): assert_equal(test.mask, [True, True]) assert_(test.fill_value == True) - # test = (a[0] == b) # doesn't work in Python2 + test = (a[0] == b) + assert_equal(test.data, [False, False]) + assert_equal(test.mask, [True, False]) + assert_(test.fill_value == True) + test = (b == a[0]) assert_equal(test.data, [False, False]) assert_equal(test.mask, [True, False]) @@ -1644,7 +1669,11 @@ class TestMaskedArrayArithmetic(object): assert_equal(test.mask, [True, True]) assert_(test.fill_value == True) - # test = (a[0] != b) # doesn't work in Python2 + test = (a[0] != b) + assert_equal(test.data, [True, True]) + assert_equal(test.mask, [True, False]) + assert_(test.fill_value == True) + test = (b != a[0]) assert_equal(test.data, [True, True]) assert_equal(test.mask, [True, False]) @@ -1715,7 +1744,7 @@ class TestMaskedArrayArithmetic(object): assert_equal(a.mask, [0, 0, 0, 0, 1]) -class TestMaskedArrayAttributes(object): +class TestMaskedArrayAttributes: def test_keepmask(self): # Tests the keep mask flag @@ -1891,7 +1920,7 @@ class TestMaskedArrayAttributes(object): assert_equal(m._mask, np.ma.nomask) -class TestFillingValues(object): +class TestFillingValues: def test_check_on_scalar(self): # Test _check_fill_value set to valid and invalid values @@ -2229,7 +2258,7 @@ class TestFillingValues(object): assert_equal(a["f1"].fill_value, default_fill_value("eggs")) -class TestUfuncs(object): +class TestUfuncs: # Test class for the application of ufuncs on MaskedArrays. def setup(self): @@ -2309,7 +2338,7 @@ class TestUfuncs(object): assert_raises(TypeError, operator.mul, a, "abc") assert_raises(TypeError, operator.truediv, a, "abc") - class MyClass(object): + class MyClass: __array_priority__ = a.__array_priority__ + 1 def __mul__(self, other): @@ -2323,7 +2352,7 @@ class TestUfuncs(object): assert_(a * me == "My rmul") # and that __array_priority__ is respected - class MyClass2(object): + class MyClass2: __array_priority__ = 100 def __mul__(self, other): @@ -2373,7 +2402,7 @@ class TestUfuncs(object): # also check that allclose uses ma ufuncs, to avoid warning allclose(m, 0.5) -class TestMaskedArrayInPlaceArithmetics(object): +class TestMaskedArrayInPlaceArithmetics: # Test MaskedArray Arithmetics def setup(self): @@ -2875,7 +2904,7 @@ class TestMaskedArrayInPlaceArithmetics(object): assert_equal(len(w), 0, "Failed on type=%s." % t) -class TestMaskedArrayMethods(object): +class TestMaskedArrayMethods: # Test class for miscellaneous MaskedArrays methods. def setup(self): # Base data definition. @@ -3582,7 +3611,7 @@ class TestMaskedArrayMethods(object): assert_equal(xd.data, x.diagonal().data) -class TestMaskedArrayMathMethods(object): +class TestMaskedArrayMathMethods: def setup(self): # Base data definition. @@ -3860,7 +3889,7 @@ class TestMaskedArrayMathMethods(object): assert_equal(a.max(1), [3, 6]) -class TestMaskedArrayMathMethodsComplex(object): +class TestMaskedArrayMathMethodsComplex: # Test class for miscellaneous MaskedArrays methods. def setup(self): # Base data definition. @@ -3913,7 +3942,7 @@ class TestMaskedArrayMathMethodsComplex(object): mX[:, k].compressed().std()) -class TestMaskedArrayFunctions(object): +class TestMaskedArrayFunctions: # Test class for miscellaneous functions. def setup(self): @@ -4552,7 +4581,7 @@ class TestMaskedArrayFunctions(object): assert_equal(test, masked_equal([-1, -1, -1, -1, -1], -1)) -class TestMaskedFields(object): +class TestMaskedFields: def setup(self): ilist = [1, 2, 3, 4, 5] @@ -4714,7 +4743,7 @@ class TestMaskedFields(object): assert_equal(len(rec), len(self.data['ddtype'])) -class TestMaskedObjectArray(object): +class TestMaskedObjectArray: def test_getitem(self): arr = np.ma.array([None, None]) @@ -4762,7 +4791,7 @@ class TestMaskedObjectArray(object): assert_(arr[0] is np.ma.masked) -class TestMaskedView(object): +class TestMaskedView: def setup(self): iterator = list(zip(np.arange(10), np.random.rand(10))) @@ -4840,7 +4869,7 @@ class TestMaskedView(object): assert_(not isinstance(test, MaskedArray)) -class TestOptionalArgs(object): +class TestOptionalArgs: def test_ndarrayfuncs(self): # test axis arg behaves the same as ndarray (including multiple axes) @@ -4927,7 +4956,7 @@ class TestOptionalArgs(object): assert_raises(np.AxisError, count, np.ma.array(1), axis=1) -class TestMaskedConstant(object): +class TestMaskedConstant: def _do_add_test(self, add): # sanity check assert_(add(np.ma.masked, 1) is np.ma.masked) @@ -5008,11 +5037,6 @@ class TestMaskedConstant(object): assert_raises(MaskError, operator.setitem, a_i, (), np.ma.masked) assert_raises(MaskError, int, np.ma.masked) - @pytest.mark.skipif(sys.version_info.major == 3, - reason="long doesn't exist in Python 3") - def test_coercion_long(self): - assert_raises(MaskError, long, np.ma.masked) - def test_coercion_float(self): a_f = np.zeros((), float) assert_warns(UserWarning, operator.setitem, a_f, (), np.ma.masked) @@ -5044,7 +5068,7 @@ class TestMaskedConstant(object): assert_raises(AttributeError, setattr, np.ma.masked, 'dtype', np.int64) -class TestMaskedWhereAliases(object): +class TestMaskedWhereAliases: # TODO: Test masked_object, masked_equal, ... diff --git a/numpy/ma/tests/test_deprecations.py b/numpy/ma/tests/test_deprecations.py index 72cc29aa0..14f697375 100644 --- a/numpy/ma/tests/test_deprecations.py +++ b/numpy/ma/tests/test_deprecations.py @@ -1,14 +1,12 @@ """Test deprecation and future warnings. """ -from __future__ import division, absolute_import, print_function - import numpy as np from numpy.testing import assert_warns from numpy.ma.testutils import assert_equal from numpy.ma.core import MaskedArrayFutureWarning -class TestArgsort(object): +class TestArgsort: """ gh-8701 """ def _test_base(self, argsort, cls): arr_0d = np.array(1).view(cls) @@ -37,7 +35,7 @@ class TestArgsort(object): return self._test_base(np.ma.MaskedArray.argsort, np.ma.MaskedArray) -class TestMinimumMaximum(object): +class TestMinimumMaximum: def test_minimum(self): assert_warns(DeprecationWarning, np.ma.minimum, np.ma.array([1, 2])) diff --git a/numpy/ma/tests/test_extras.py b/numpy/ma/tests/test_extras.py index 836770378..1c8610625 100644 --- a/numpy/ma/tests/test_extras.py +++ b/numpy/ma/tests/test_extras.py @@ -7,10 +7,9 @@ Adapted from the original test_ma by Pierre Gerard-Marchant :version: $Id: test_extras.py 3473 2007-10-29 15:18:13Z jarrod.millman $ """ -from __future__ import division, absolute_import, print_function - import warnings import itertools +import pytest import numpy as np from numpy.testing import ( @@ -33,7 +32,7 @@ from numpy.ma.extras import ( ) -class TestGeneric(object): +class TestGeneric: # def test_masked_all(self): # Tests masked_all @@ -141,7 +140,7 @@ class TestGeneric(object): assert_equal(test, []) -class TestAverage(object): +class TestAverage: # Several tests of average. Why so many ? Good point... def test_testAverage1(self): # Test of average. @@ -272,7 +271,7 @@ class TestAverage(object): assert_almost_equal(wav1.imag, expected1.imag) -class TestConcatenator(object): +class TestConcatenator: # Tests for mr_, the equivalent of r_ for masked arrays. def test_1d(self): @@ -316,7 +315,7 @@ class TestConcatenator(object): assert_equal(actual.data[:2], [1, 2]) -class TestNotMasked(object): +class TestNotMasked: # Tests notmasked_edges and notmasked_contiguous. def test_edges(self): @@ -386,7 +385,7 @@ class TestNotMasked(object): ]) -class TestCompressFunctions(object): +class TestCompressFunctions: def test_compress_nd(self): # Tests compress_nd @@ -552,6 +551,18 @@ class TestCompressFunctions(object): assert_(mask_rowcols(x, 0).mask.all()) assert_(mask_rowcols(x, 1).mask.all()) + @pytest.mark.parametrize("axis", [None, 0, 1]) + @pytest.mark.parametrize(["func", "rowcols_axis"], + [(np.ma.mask_rows, 0), (np.ma.mask_cols, 1)]) + def test_mask_row_cols_axis_deprecation(self, axis, func, rowcols_axis): + # Test deprecation of the axis argument to `mask_rows` and `mask_cols` + x = array(np.arange(9).reshape(3, 3), + mask=[[1, 0, 0], [0, 0, 0], [0, 0, 0]]) + + with assert_warns(DeprecationWarning): + res = func(x, axis=axis) + assert_equal(res, mask_rowcols(x, rowcols_axis)) + def test_dot(self): # Tests dot product n = np.arange(1, 7) @@ -639,7 +650,7 @@ class TestCompressFunctions(object): assert_equal(a, res) -class TestApplyAlongAxis(object): +class TestApplyAlongAxis: # Tests 2D functions def test_3d(self): a = arange(12.).reshape(2, 2, 3) @@ -661,7 +672,7 @@ class TestApplyAlongAxis(object): assert_equal(xa, [[2, 5], [8, 11]]) -class TestApplyOverAxes(object): +class TestApplyOverAxes: # Tests apply_over_axes def test_basic(self): a = arange(24).reshape(2, 3, 4) @@ -674,7 +685,7 @@ class TestApplyOverAxes(object): assert_equal(test, ctrl) -class TestMedian(object): +class TestMedian: def test_pytype(self): r = np.ma.median([[np.inf, np.inf], [np.inf, np.inf]], axis=-1) assert_equal(r, np.inf) @@ -1053,7 +1064,7 @@ class TestMedian(object): assert_(type(np.ma.median(o.astype(object))), float) -class TestCov(object): +class TestCov: def setup(self): self.data = array(np.random.rand(12)) @@ -1120,7 +1131,7 @@ class TestCov(object): x.shape[0] / frac)) -class TestCorrcoef(object): +class TestCorrcoef: def setup(self): self.data = array(np.random.rand(12)) @@ -1227,7 +1238,7 @@ class TestCorrcoef(object): control[:-1, :-1]) -class TestPolynomial(object): +class TestPolynomial: # def test_polyfit(self): # Tests polyfit @@ -1285,7 +1296,7 @@ class TestPolynomial(object): assert_almost_equal(a, a_) -class TestArraySetOps(object): +class TestArraySetOps: def test_unique_onlist(self): # Test unique on list @@ -1517,7 +1528,7 @@ class TestArraySetOps(object): assert_array_equal(setdiff1d(a, b), np.array(['c'])) -class TestShapeBase(object): +class TestShapeBase: def test_atleast_2d(self): # Test atleast_2d @@ -1573,7 +1584,7 @@ class TestShapeBase(object): assert_equal(b.mask.shape, b.data.shape) -class TestStack(object): +class TestStack: def test_stack_1d(self): a = masked_array([0, 1, 2], mask=[0, 1, 0]) diff --git a/numpy/ma/tests/test_mrecords.py b/numpy/ma/tests/test_mrecords.py index 94e772d55..c2f859273 100644 --- a/numpy/ma/tests/test_mrecords.py +++ b/numpy/ma/tests/test_mrecords.py @@ -5,8 +5,6 @@ :contact: pierregm_at_uga_dot_edu """ -from __future__ import division, absolute_import, print_function - import numpy as np import numpy.ma as ma from numpy import recarray @@ -26,7 +24,7 @@ from numpy.ma.testutils import ( from numpy.compat import pickle -class TestMRecords(object): +class TestMRecords: ilist = [1, 2, 3, 4, 5] flist = [1.1, 2.2, 3.3, 4.4, 5.5] @@ -348,7 +346,7 @@ class TestMRecords(object): dtype=mult.dtype)) -class TestView(object): +class TestView: def setup(self): (a, b) = (np.arange(10), np.random.rand(10)) @@ -386,7 +384,7 @@ class TestView(object): ############################################################################## -class TestMRecordsImport(object): +class TestMRecordsImport: _a = ma.array([1, 2, 3], mask=[0, 0, 1], dtype=int) _b = ma.array([1.1, 2.2, 3.3], mask=[0, 0, 1], dtype=float) diff --git a/numpy/ma/tests/test_old_ma.py b/numpy/ma/tests/test_old_ma.py index 7100eccbb..96c7e3609 100644 --- a/numpy/ma/tests/test_old_ma.py +++ b/numpy/ma/tests/test_old_ma.py @@ -1,5 +1,3 @@ -from __future__ import division, absolute_import, print_function - from functools import reduce import numpy as np @@ -33,7 +31,7 @@ def eq(v, w, msg=''): return result -class TestMa(object): +class TestMa: def setup(self): x = np.array([1., 1., 1., -2., pi/2.0, 4., 5., -10., 10., 1., 2., 3.]) @@ -700,7 +698,7 @@ class TestMa(object): assert_equal(b[1].shape, ()) -class TestUfuncs(object): +class TestUfuncs: def setup(self): self.d = (array([1.0, 0, -1, pi / 2] * 2, mask=[0, 1] + [0] * 6), array([1.0, 0, -1, pi / 2] * 2, mask=[1, 0] + [0] * 6),) @@ -765,7 +763,7 @@ class TestUfuncs(object): assert_(eq(nonzero(x), [0])) -class TestArrayMethods(object): +class TestArrayMethods: def setup(self): x = np.array([8.375, 7.545, 8.828, 8.5, 1.757, 5.928, diff --git a/numpy/ma/tests/test_regression.py b/numpy/ma/tests/test_regression.py index b83873a5a..7e76eb054 100644 --- a/numpy/ma/tests/test_regression.py +++ b/numpy/ma/tests/test_regression.py @@ -1,12 +1,10 @@ -from __future__ import division, absolute_import, print_function - import numpy as np from numpy.testing import ( assert_, assert_array_equal, assert_allclose, suppress_warnings ) -class TestRegression(object): +class TestRegression: def test_masked_array_create(self): # Ticket #17 x = np.ma.masked_array([0, 1, 2, 3, 0, 4, 5, 6], @@ -88,6 +86,6 @@ class TestRegression(object): ma = np.ma.MaskedArray([(1, 1.), (2, 2.), (3, 3.)], dtype='i4,f4') assert_array_equal(ma[[]], ma[:0]) - def test_masked_array_tostring_fortran(self): + def test_masked_array_tobytes_fortran(self): ma = np.ma.arange(4).reshape((2,2)) - assert_array_equal(ma.tostring(order='F'), ma.T.tostring()) + assert_array_equal(ma.tobytes(order='F'), ma.T.tobytes()) diff --git a/numpy/ma/tests/test_subclassing.py b/numpy/ma/tests/test_subclassing.py index 440b36722..caa746740 100644 --- a/numpy/ma/tests/test_subclassing.py +++ b/numpy/ma/tests/test_subclassing.py @@ -6,8 +6,6 @@ :version: $Id: test_subclassing.py 3473 2007-10-29 15:18:13Z jarrod.millman $ """ -from __future__ import division, absolute_import, print_function - import numpy as np from numpy.testing import assert_, assert_raises from numpy.ma.testutils import assert_equal @@ -80,7 +78,7 @@ msubarray = MSubArray # and overrides __array_wrap__, updating the info dict, to check that this # doesn't get destroyed by MaskedArray._update_from. But this one also needs # its own iterator... -class CSAIterator(object): +class CSAIterator: """ Flat iterator object that uses its own setter/getter (works around ndarray.flat not propagating subclass setters/getters @@ -107,8 +105,6 @@ class CSAIterator(object): def __next__(self): return next(self._dataiter).__array__().view(type(self._original)) - next = __next__ - class ComplicatedSubArray(SubArray): @@ -154,7 +150,7 @@ class ComplicatedSubArray(SubArray): return obj -class TestSubclassing(object): +class TestSubclassing: # Test suite for masked subclasses of ndarray. def setup(self): |