增加环绕侦察场景适配
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,15 +1,11 @@
|
||||
"""Test deprecation and future warnings.
|
||||
|
||||
"""
|
||||
import io
|
||||
import textwrap
|
||||
|
||||
import pytest
|
||||
|
||||
import numpy as np
|
||||
from numpy.ma.core import MaskedArrayFutureWarning
|
||||
from numpy.ma.testutils import assert_equal
|
||||
from numpy.testing import assert_warns
|
||||
|
||||
|
||||
class TestArgsort:
|
||||
@@ -23,7 +19,7 @@ class TestArgsort:
|
||||
|
||||
# argsort has a bad default for >1d arrays
|
||||
arr_2d = np.array([[1, 2], [3, 4]]).view(cls)
|
||||
result = assert_warns(
|
||||
result = pytest.warns(
|
||||
np.ma.core.MaskedArrayFutureWarning, argsort, arr_2d)
|
||||
assert_equal(result, argsort(arr_2d, axis=None))
|
||||
|
||||
@@ -53,10 +49,10 @@ class TestMinimumMaximum:
|
||||
ma_max = np.ma.maximum.reduce
|
||||
|
||||
# check that the default axis is still None, but warns on 2d arrays
|
||||
result = assert_warns(MaskedArrayFutureWarning, ma_max, data2d)
|
||||
result = pytest.warns(MaskedArrayFutureWarning, ma_max, data2d)
|
||||
assert_equal(result, ma_max(data2d, axis=None))
|
||||
|
||||
result = assert_warns(MaskedArrayFutureWarning, ma_min, data2d)
|
||||
result = pytest.warns(MaskedArrayFutureWarning, ma_min, data2d)
|
||||
assert_equal(result, ma_min(data2d, axis=None))
|
||||
|
||||
# no warnings on 1d, as both new and old defaults are equivalent
|
||||
@@ -67,21 +63,3 @@ class TestMinimumMaximum:
|
||||
result = ma_max(data1d)
|
||||
assert_equal(result, ma_max(data1d, axis=None))
|
||||
assert_equal(result, ma_max(data1d, axis=0))
|
||||
|
||||
|
||||
class TestFromtextfile:
|
||||
def test_fromtextfile_delimitor(self):
|
||||
# NumPy 1.22.0, 2021-09-23
|
||||
|
||||
textfile = io.StringIO(textwrap.dedent(
|
||||
"""
|
||||
A,B,C,D
|
||||
'string 1';1;1.0;'mixed column'
|
||||
'string 2';2;2.0;
|
||||
'string 3';3;3.0;123
|
||||
'string 4';4;4.0;3.14
|
||||
"""
|
||||
))
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
result = np.ma.mrecords.fromtextfile(textfile, delimitor=';')
|
||||
|
||||
@@ -5,8 +5,8 @@ Adapted from the original test_ma by Pierre Gerard-Marchant
|
||||
:contact: pierregm_at_uga_dot_edu
|
||||
|
||||
"""
|
||||
import inspect
|
||||
import itertools
|
||||
import warnings
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -68,7 +68,6 @@ from numpy.ma.testutils import (
|
||||
assert_array_equal,
|
||||
assert_equal,
|
||||
)
|
||||
from numpy.testing import assert_warns, suppress_warnings
|
||||
|
||||
|
||||
class TestGeneric:
|
||||
@@ -746,7 +745,7 @@ class TestCompressFunctions:
|
||||
x = array(np.arange(9).reshape(3, 3),
|
||||
mask=[[1, 0, 0], [0, 0, 0], [0, 0, 0]])
|
||||
|
||||
with assert_warns(DeprecationWarning):
|
||||
with pytest.warns(DeprecationWarning):
|
||||
res = func(x, axis=axis)
|
||||
assert_equal(res, mask_rowcols(x, rowcols_axis))
|
||||
|
||||
@@ -1078,7 +1077,7 @@ class TestMedian:
|
||||
x = np.ma.arange(24).reshape(3, 4, 2)
|
||||
x[x % 3 == 0] = masked
|
||||
assert_equal(median(x, 0), [[12, 9], [6, 15], [12, 9], [18, 15]])
|
||||
x.shape = (4, 3, 2)
|
||||
x = x.reshape((4, 3, 2))
|
||||
assert_equal(median(x, 0), [[99, 10], [11, 99], [13, 14]])
|
||||
x = np.ma.arange(24).reshape(4, 3, 2)
|
||||
x[x % 5 == 0] = masked
|
||||
@@ -1287,19 +1286,14 @@ class TestMedian:
|
||||
def test_empty(self):
|
||||
# empty arrays
|
||||
a = np.ma.masked_array(np.array([], dtype=float))
|
||||
with suppress_warnings() as w:
|
||||
w.record(RuntimeWarning)
|
||||
with pytest.warns(RuntimeWarning):
|
||||
assert_array_equal(np.ma.median(a), np.nan)
|
||||
assert_(w.log[0].category is RuntimeWarning)
|
||||
|
||||
# multiple dimensions
|
||||
a = np.ma.masked_array(np.array([], dtype=float, ndmin=3))
|
||||
# no axis
|
||||
with suppress_warnings() as w:
|
||||
w.record(RuntimeWarning)
|
||||
warnings.filterwarnings('always', '', RuntimeWarning)
|
||||
with pytest.warns(RuntimeWarning):
|
||||
assert_array_equal(np.ma.median(a), np.nan)
|
||||
assert_(w.log[0].category is RuntimeWarning)
|
||||
|
||||
# axis 0 and 1
|
||||
b = np.ma.masked_array(np.array([], dtype=float, ndmin=2))
|
||||
@@ -1308,10 +1302,8 @@ class TestMedian:
|
||||
|
||||
# axis 2
|
||||
b = np.ma.masked_array(np.array(np.nan, dtype=float, ndmin=2))
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
warnings.filterwarnings('always', '', RuntimeWarning)
|
||||
with pytest.warns(RuntimeWarning):
|
||||
assert_equal(np.ma.median(a, axis=2), b)
|
||||
assert_(w[0].category is RuntimeWarning)
|
||||
|
||||
def test_object(self):
|
||||
o = np.ma.masked_array(np.arange(7.))
|
||||
@@ -1322,11 +1314,11 @@ class TestMedian:
|
||||
|
||||
class TestCov:
|
||||
|
||||
def setup_method(self):
|
||||
self.data = array(np.random.rand(12))
|
||||
def _create_data(self):
|
||||
return array(np.random.rand(12))
|
||||
|
||||
def test_covhelper(self):
|
||||
x = self.data
|
||||
x = self._create_data()
|
||||
# Test not mask output type is a float.
|
||||
assert_(_covhelper(x, rowvar=True)[1].dtype, np.float32)
|
||||
assert_(_covhelper(x, y=x, rowvar=False)[1].dtype, np.float32)
|
||||
@@ -1347,7 +1339,7 @@ class TestCov:
|
||||
|
||||
def test_1d_without_missing(self):
|
||||
# Test cov on 1D variable w/o missing values
|
||||
x = self.data
|
||||
x = self._create_data()
|
||||
assert_almost_equal(np.cov(x), cov(x))
|
||||
assert_almost_equal(np.cov(x, rowvar=False), cov(x, rowvar=False))
|
||||
assert_almost_equal(np.cov(x, rowvar=False, bias=True),
|
||||
@@ -1355,7 +1347,7 @@ class TestCov:
|
||||
|
||||
def test_2d_without_missing(self):
|
||||
# Test cov on 1 2D variable w/o missing values
|
||||
x = self.data.reshape(3, 4)
|
||||
x = self._create_data().reshape(3, 4)
|
||||
assert_almost_equal(np.cov(x), cov(x))
|
||||
assert_almost_equal(np.cov(x, rowvar=False), cov(x, rowvar=False))
|
||||
assert_almost_equal(np.cov(x, rowvar=False, bias=True),
|
||||
@@ -1363,7 +1355,7 @@ class TestCov:
|
||||
|
||||
def test_1d_with_missing(self):
|
||||
# Test cov 1 1D variable w/missing values
|
||||
x = self.data
|
||||
x = self._create_data()
|
||||
x[-1] = masked
|
||||
x -= x.mean()
|
||||
nx = x.compressed()
|
||||
@@ -1387,7 +1379,7 @@ class TestCov:
|
||||
|
||||
def test_2d_with_missing(self):
|
||||
# Test cov on 2D variable w/ missing value
|
||||
x = self.data
|
||||
x = self._create_data()
|
||||
x[-1] = masked
|
||||
x = x.reshape(3, 4)
|
||||
valid = np.logical_not(getmaskarray(x)).astype(int)
|
||||
@@ -1409,74 +1401,33 @@ class TestCov:
|
||||
|
||||
class TestCorrcoef:
|
||||
|
||||
def setup_method(self):
|
||||
self.data = array(np.random.rand(12))
|
||||
self.data2 = array(np.random.rand(12))
|
||||
|
||||
def test_ddof(self):
|
||||
# ddof raises DeprecationWarning
|
||||
x, y = self.data, self.data2
|
||||
expected = np.corrcoef(x)
|
||||
expected2 = np.corrcoef(x, y)
|
||||
with suppress_warnings() as sup:
|
||||
warnings.simplefilter("always")
|
||||
assert_warns(DeprecationWarning, corrcoef, x, ddof=-1)
|
||||
sup.filter(DeprecationWarning, "bias and ddof have no effect")
|
||||
# ddof has no or negligible effect on the function
|
||||
assert_almost_equal(np.corrcoef(x, ddof=0), corrcoef(x, ddof=0))
|
||||
assert_almost_equal(corrcoef(x, ddof=-1), expected)
|
||||
assert_almost_equal(corrcoef(x, y, ddof=-1), expected2)
|
||||
assert_almost_equal(corrcoef(x, ddof=3), expected)
|
||||
assert_almost_equal(corrcoef(x, y, ddof=3), expected2)
|
||||
|
||||
def test_bias(self):
|
||||
x, y = self.data, self.data2
|
||||
expected = np.corrcoef(x)
|
||||
# bias raises DeprecationWarning
|
||||
with suppress_warnings() as sup:
|
||||
warnings.simplefilter("always")
|
||||
assert_warns(DeprecationWarning, corrcoef, x, y, True, False)
|
||||
assert_warns(DeprecationWarning, corrcoef, x, y, True, True)
|
||||
assert_warns(DeprecationWarning, corrcoef, x, bias=False)
|
||||
sup.filter(DeprecationWarning, "bias and ddof have no effect")
|
||||
# bias has no or negligible effect on the function
|
||||
assert_almost_equal(corrcoef(x, bias=1), expected)
|
||||
def _create_data(self):
|
||||
data = array(np.random.rand(12))
|
||||
data2 = array(np.random.rand(12))
|
||||
return data, data2
|
||||
|
||||
def test_1d_without_missing(self):
|
||||
# Test cov on 1D variable w/o missing values
|
||||
x = self.data
|
||||
x = self._create_data()[0]
|
||||
assert_almost_equal(np.corrcoef(x), corrcoef(x))
|
||||
assert_almost_equal(np.corrcoef(x, rowvar=False),
|
||||
corrcoef(x, rowvar=False))
|
||||
with suppress_warnings() as sup:
|
||||
sup.filter(DeprecationWarning, "bias and ddof have no effect")
|
||||
assert_almost_equal(np.corrcoef(x, rowvar=False, bias=True),
|
||||
corrcoef(x, rowvar=False, bias=True))
|
||||
|
||||
def test_2d_without_missing(self):
|
||||
# Test corrcoef on 1 2D variable w/o missing values
|
||||
x = self.data.reshape(3, 4)
|
||||
x = self._create_data()[0].reshape(3, 4)
|
||||
assert_almost_equal(np.corrcoef(x), corrcoef(x))
|
||||
assert_almost_equal(np.corrcoef(x, rowvar=False),
|
||||
corrcoef(x, rowvar=False))
|
||||
with suppress_warnings() as sup:
|
||||
sup.filter(DeprecationWarning, "bias and ddof have no effect")
|
||||
assert_almost_equal(np.corrcoef(x, rowvar=False, bias=True),
|
||||
corrcoef(x, rowvar=False, bias=True))
|
||||
|
||||
def test_1d_with_missing(self):
|
||||
# Test corrcoef 1 1D variable w/missing values
|
||||
x = self.data
|
||||
x = self._create_data()[0]
|
||||
x[-1] = masked
|
||||
x -= x.mean()
|
||||
nx = x.compressed()
|
||||
assert_almost_equal(np.corrcoef(nx), corrcoef(x))
|
||||
assert_almost_equal(np.corrcoef(nx, rowvar=False),
|
||||
corrcoef(x, rowvar=False))
|
||||
with suppress_warnings() as sup:
|
||||
sup.filter(DeprecationWarning, "bias and ddof have no effect")
|
||||
assert_almost_equal(np.corrcoef(nx, rowvar=False, bias=True),
|
||||
corrcoef(x, rowvar=False, bias=True))
|
||||
try:
|
||||
corrcoef(x, allow_masked=False)
|
||||
except ValueError:
|
||||
@@ -1486,36 +1437,20 @@ class TestCorrcoef:
|
||||
assert_almost_equal(np.corrcoef(nx, nx[::-1]), corrcoef(x, x[::-1]))
|
||||
assert_almost_equal(np.corrcoef(nx, nx[::-1], rowvar=False),
|
||||
corrcoef(x, x[::-1], rowvar=False))
|
||||
with suppress_warnings() as sup:
|
||||
sup.filter(DeprecationWarning, "bias and ddof have no effect")
|
||||
# ddof and bias have no or negligible effect on the function
|
||||
assert_almost_equal(np.corrcoef(nx, nx[::-1]),
|
||||
corrcoef(x, x[::-1], bias=1))
|
||||
assert_almost_equal(np.corrcoef(nx, nx[::-1]),
|
||||
corrcoef(x, x[::-1], ddof=2))
|
||||
|
||||
def test_2d_with_missing(self):
|
||||
# Test corrcoef on 2D variable w/ missing value
|
||||
x = self.data
|
||||
x = self._create_data()[0]
|
||||
x[-1] = masked
|
||||
x = x.reshape(3, 4)
|
||||
|
||||
test = corrcoef(x)
|
||||
control = np.corrcoef(x)
|
||||
assert_almost_equal(test[:-1, :-1], control[:-1, :-1])
|
||||
with suppress_warnings() as sup:
|
||||
sup.filter(DeprecationWarning, "bias and ddof have no effect")
|
||||
# ddof and bias have no or negligible effect on the function
|
||||
assert_almost_equal(corrcoef(x, ddof=-2)[:-1, :-1],
|
||||
control[:-1, :-1])
|
||||
assert_almost_equal(corrcoef(x, ddof=3)[:-1, :-1],
|
||||
control[:-1, :-1])
|
||||
assert_almost_equal(corrcoef(x, bias=1)[:-1, :-1],
|
||||
control[:-1, :-1])
|
||||
|
||||
|
||||
class TestPolynomial:
|
||||
#
|
||||
|
||||
def test_polyfit(self):
|
||||
# Tests polyfit
|
||||
# On ndarrays
|
||||
@@ -1877,6 +1812,18 @@ class TestShapeBase:
|
||||
assert_equal(b.shape, (1, 1))
|
||||
assert_equal(b.mask.shape, b.data.shape)
|
||||
|
||||
@pytest.mark.parametrize("fn", [atleast_1d, vstack, diagflat])
|
||||
def test_inspect_signature(self, fn):
|
||||
name = fn.__name__
|
||||
assert getattr(np.ma, name) is fn
|
||||
|
||||
assert fn.__module__ == "numpy.ma.extras"
|
||||
|
||||
wrapped = getattr(np, fn.__name__)
|
||||
sig_wrapped = inspect.signature(wrapped)
|
||||
sig = inspect.signature(fn)
|
||||
assert sig == sig_wrapped
|
||||
|
||||
|
||||
class TestNDEnumerate:
|
||||
|
||||
|
||||
@@ -8,9 +8,11 @@ import pickle
|
||||
|
||||
import numpy as np
|
||||
import numpy.ma as ma
|
||||
from numpy._core.records import fromarrays as recfromarrays
|
||||
from numpy._core.records import fromrecords as recfromrecords
|
||||
from numpy._core.records import recarray
|
||||
from numpy._core.records import (
|
||||
fromarrays as recfromarrays,
|
||||
fromrecords as recfromrecords,
|
||||
recarray,
|
||||
)
|
||||
from numpy.ma import masked, nomask
|
||||
from numpy.ma.mrecords import (
|
||||
MaskedRecords,
|
||||
@@ -20,11 +22,7 @@ from numpy.ma.mrecords import (
|
||||
fromtextfile,
|
||||
mrecarray,
|
||||
)
|
||||
from numpy.ma.testutils import (
|
||||
assert_,
|
||||
assert_equal,
|
||||
assert_equal_records,
|
||||
)
|
||||
from numpy.ma.testutils import assert_, assert_equal, assert_equal_records
|
||||
from numpy.testing import temppath
|
||||
|
||||
|
||||
@@ -352,24 +350,24 @@ class TestMRecords:
|
||||
|
||||
class TestView:
|
||||
|
||||
def setup_method(self):
|
||||
(a, b) = (np.arange(10), np.random.rand(10))
|
||||
def _create_data(self):
|
||||
a, b = (np.arange(10), np.random.rand(10))
|
||||
ndtype = [('a', float), ('b', float)]
|
||||
arr = np.array(list(zip(a, b)), dtype=ndtype)
|
||||
|
||||
mrec = fromarrays([a, b], dtype=ndtype, fill_value=(-9., -99.))
|
||||
mrec.mask[3] = (False, True)
|
||||
self.data = (mrec, a, b, arr)
|
||||
return mrec, a, b, arr
|
||||
|
||||
def test_view_by_itself(self):
|
||||
(mrec, a, b, arr) = self.data
|
||||
mrec = self._create_data()[0]
|
||||
test = mrec.view()
|
||||
assert_(isinstance(test, MaskedRecords))
|
||||
assert_equal_records(test, mrec)
|
||||
assert_equal_records(test._mask, mrec._mask)
|
||||
|
||||
def test_view_simple_dtype(self):
|
||||
(mrec, a, b, arr) = self.data
|
||||
mrec, a, b, _ = self._create_data()
|
||||
ntype = (float, 2)
|
||||
test = mrec.view(ntype)
|
||||
assert_(isinstance(test, ma.MaskedArray))
|
||||
@@ -377,7 +375,7 @@ class TestView:
|
||||
assert_(test[3, 1] is ma.masked)
|
||||
|
||||
def test_view_flexible_type(self):
|
||||
(mrec, a, b, arr) = self.data
|
||||
mrec, _, _, arr = self._create_data()
|
||||
alttype = [('A', float), ('B', float)]
|
||||
test = mrec.view(alttype)
|
||||
assert_(isinstance(test, MaskedRecords))
|
||||
|
||||
@@ -83,11 +83,7 @@ from numpy.ma import (
|
||||
where,
|
||||
zeros,
|
||||
)
|
||||
from numpy.testing import (
|
||||
assert_,
|
||||
assert_equal,
|
||||
assert_raises,
|
||||
)
|
||||
from numpy.testing import assert_, assert_equal, assert_raises
|
||||
|
||||
pi = np.pi
|
||||
|
||||
@@ -101,7 +97,7 @@ def eq(v, w, msg=''):
|
||||
|
||||
class TestMa:
|
||||
|
||||
def setup_method(self):
|
||||
def _create_data(self):
|
||||
x = np.array([1., 1., 1., -2., pi / 2.0, 4., 5., -10., 10., 1., 2., 3.])
|
||||
y = np.array([5., 0., 3., 2., -1., -4., 0., -10., 10., 1., 0., 3.])
|
||||
a10 = 10.
|
||||
@@ -114,11 +110,11 @@ class TestMa:
|
||||
xf = np.where(m1, 1e+20, x)
|
||||
s = x.shape
|
||||
xm.set_fill_value(1e+20)
|
||||
self.d = (x, y, a10, m1, m2, xm, ym, z, zm, xf, s)
|
||||
return x, y, a10, m1, m2, xm, ym, z, zm, xf, s
|
||||
|
||||
def test_testBasic1d(self):
|
||||
# Test of basic array creation and properties in 1 dimension.
|
||||
(x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d
|
||||
x, _, _, m1, _, xm, _, _, _, xf, s = self._create_data()
|
||||
assert_(not isMaskedArray(x))
|
||||
assert_(isMaskedArray(xm))
|
||||
assert_equal(shape(xm), s)
|
||||
@@ -133,7 +129,7 @@ class TestMa:
|
||||
@pytest.mark.parametrize("s", [(4, 3), (6, 2)])
|
||||
def test_testBasic2d(self, s):
|
||||
# Test of basic array creation and properties in 2 dimensions.
|
||||
(x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d
|
||||
x, y, _, m1, _, xm, ym, _, _, xf, s = self._create_data()
|
||||
x.shape = s
|
||||
y.shape = s
|
||||
xm.shape = s
|
||||
@@ -152,7 +148,7 @@ class TestMa:
|
||||
|
||||
def test_testArithmetic(self):
|
||||
# Test of basic arithmetic.
|
||||
(x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d
|
||||
x, y, a10, _, _, xm, ym, _, _, xf, s = self._create_data()
|
||||
a2d = array([[1, 2], [0, 4]])
|
||||
a2dm = masked_array(a2d, [[0, 0], [1, 0]])
|
||||
assert_(eq(a2d * a2d, a2d * a2dm))
|
||||
@@ -196,7 +192,7 @@ class TestMa:
|
||||
|
||||
def test_testUfuncs1(self):
|
||||
# Test various functions such as sin, cos.
|
||||
(x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d
|
||||
x, y, _, _, _, xm, ym, z, zm, _, _ = self._create_data()
|
||||
assert_(eq(np.cos(x), cos(xm)))
|
||||
assert_(eq(np.cosh(x), cosh(xm)))
|
||||
assert_(eq(np.sin(x), sin(xm)))
|
||||
@@ -242,7 +238,7 @@ class TestMa:
|
||||
|
||||
def test_testMinMax(self):
|
||||
# Test minimum and maximum.
|
||||
(x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d
|
||||
x, _, _, _, _, xm, _, _, _, _, _ = self._create_data()
|
||||
xr = np.ravel(x) # max doesn't work if shaped
|
||||
xmr = ravel(xm)
|
||||
|
||||
@@ -252,7 +248,7 @@ class TestMa:
|
||||
|
||||
def test_testAddSumProd(self):
|
||||
# Test add, sum, product.
|
||||
(x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d
|
||||
x, y, _, _, _, xm, ym, _, _, _, s = self._create_data()
|
||||
assert_(eq(np.add.reduce(x), add.reduce(x)))
|
||||
assert_(eq(np.add.accumulate(x), add.accumulate(x)))
|
||||
assert_(eq(4, sum(array(4), axis=0)))
|
||||
@@ -421,7 +417,7 @@ class TestMa:
|
||||
assert_(eq(x, [0, 1, 10, 40, 4]))
|
||||
|
||||
def test_testMaPut(self):
|
||||
(x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d
|
||||
_, _, _, _, _, _, ym, _, zm, _, _ = self._create_data()
|
||||
m = [1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1]
|
||||
i = np.nonzero(m)[0]
|
||||
put(ym, i, zm)
|
||||
@@ -781,8 +777,9 @@ class TestMa:
|
||||
|
||||
|
||||
class TestUfuncs:
|
||||
def setup_method(self):
|
||||
self.d = (array([1.0, 0, -1, pi / 2] * 2, mask=[0, 1] + [0] * 6),
|
||||
|
||||
def _create_data(self):
|
||||
return (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),)
|
||||
|
||||
def test_testUfuncRegression(self):
|
||||
@@ -811,7 +808,7 @@ class TestUfuncs:
|
||||
except AttributeError:
|
||||
uf = getattr(fromnumeric, f)
|
||||
mf = getattr(np.ma, f)
|
||||
args = self.d[:uf.nin]
|
||||
args = self._create_data()[:uf.nin]
|
||||
with np.errstate():
|
||||
if f in f_invalid_ignore:
|
||||
np.seterr(invalid='ignore')
|
||||
@@ -823,7 +820,7 @@ class TestUfuncs:
|
||||
assert_(eqmask(ur.mask, mr.mask))
|
||||
|
||||
def test_reduce(self):
|
||||
a = self.d[0]
|
||||
a = self._create_data()[0]
|
||||
assert_(not alltrue(a, axis=0))
|
||||
assert_(sometrue(a, axis=0))
|
||||
assert_equal(sum(a[:3], axis=0), 0)
|
||||
@@ -847,7 +844,7 @@ class TestUfuncs:
|
||||
|
||||
class TestArrayMethods:
|
||||
|
||||
def setup_method(self):
|
||||
def _create_data(self):
|
||||
x = np.array([8.375, 7.545, 8.828, 8.5, 1.757, 5.928,
|
||||
8.43, 7.78, 9.865, 5.878, 8.979, 4.732,
|
||||
3.012, 6.022, 5.095, 3.116, 5.238, 3.957,
|
||||
@@ -867,10 +864,10 @@ class TestArrayMethods:
|
||||
mX = array(data=X, mask=m.reshape(X.shape))
|
||||
mXX = array(data=XX, mask=m.reshape(XX.shape))
|
||||
|
||||
self.d = (x, X, XX, m, mx, mX, mXX)
|
||||
return x, X, XX, m, mx, mX, mXX
|
||||
|
||||
def test_trace(self):
|
||||
(x, X, XX, m, mx, mX, mXX,) = self.d
|
||||
_, X, _, _, _, mX, _ = self._create_data()
|
||||
mXdiag = mX.diagonal()
|
||||
assert_equal(mX.trace(), mX.diagonal().compressed().sum())
|
||||
assert_(eq(mX.trace(),
|
||||
@@ -878,15 +875,15 @@ class TestArrayMethods:
|
||||
axis=0)))
|
||||
|
||||
def test_clip(self):
|
||||
(x, X, XX, m, mx, mX, mXX,) = self.d
|
||||
x, _, _, _, mx, _, _ = self._create_data()
|
||||
clipped = mx.clip(2, 8)
|
||||
assert_(eq(clipped.mask, mx.mask))
|
||||
assert_(eq(clipped._data, x.clip(2, 8)))
|
||||
assert_(eq(clipped._data, mx._data.clip(2, 8)))
|
||||
|
||||
def test_ptp(self):
|
||||
(x, X, XX, m, mx, mX, mXX,) = self.d
|
||||
(n, m) = X.shape
|
||||
_, X, _, m, mx, mX, _ = self._create_data()
|
||||
n, m = X.shape
|
||||
# print(type(mx), mx.compressed())
|
||||
# raise Exception()
|
||||
assert_equal(mx.ptp(), np.ptp(mx.compressed()))
|
||||
@@ -900,28 +897,28 @@ class TestArrayMethods:
|
||||
assert_(eq(mX.ptp(1), rows))
|
||||
|
||||
def test_swapaxes(self):
|
||||
(x, X, XX, m, mx, mX, mXX,) = self.d
|
||||
_, _, _, _, _, mX, mXX = self._create_data()
|
||||
mXswapped = mX.swapaxes(0, 1)
|
||||
assert_(eq(mXswapped[-1], mX[:, -1]))
|
||||
mXXswapped = mXX.swapaxes(0, 2)
|
||||
assert_equal(mXXswapped.shape, (2, 2, 3, 3))
|
||||
|
||||
def test_cumprod(self):
|
||||
(x, X, XX, m, mx, mX, mXX,) = self.d
|
||||
mX = self._create_data()[5]
|
||||
mXcp = mX.cumprod(0)
|
||||
assert_(eq(mXcp._data, mX.filled(1).cumprod(0)))
|
||||
mXcp = mX.cumprod(1)
|
||||
assert_(eq(mXcp._data, mX.filled(1).cumprod(1)))
|
||||
|
||||
def test_cumsum(self):
|
||||
(x, X, XX, m, mx, mX, mXX,) = self.d
|
||||
mX = self._create_data()[5]
|
||||
mXcp = mX.cumsum(0)
|
||||
assert_(eq(mXcp._data, mX.filled(0).cumsum(0)))
|
||||
mXcp = mX.cumsum(1)
|
||||
assert_(eq(mXcp._data, mX.filled(0).cumsum(1)))
|
||||
|
||||
def test_varstd(self):
|
||||
(x, X, XX, m, mx, mX, mXX,) = self.d
|
||||
_, X, XX, _, _, mX, mXX = self._create_data()
|
||||
assert_(eq(mX.var(axis=None), mX.compressed().var()))
|
||||
assert_(eq(mX.std(axis=None), mX.compressed().std()))
|
||||
assert_(eq(mXX.var(axis=3).shape, XX.var(axis=3).shape))
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
import numpy as np
|
||||
from numpy.testing import (
|
||||
assert_,
|
||||
assert_allclose,
|
||||
assert_array_equal,
|
||||
suppress_warnings,
|
||||
)
|
||||
from numpy.testing import assert_, assert_array_equal
|
||||
|
||||
|
||||
class TestRegression:
|
||||
@@ -62,18 +57,6 @@ class TestRegression:
|
||||
a.var(out=mout)
|
||||
assert_(mout._data == 0)
|
||||
|
||||
def test_ddof_corrcoef(self):
|
||||
# See gh-3336
|
||||
x = np.ma.masked_equal([1, 2, 3, 4, 5], 4)
|
||||
y = np.array([2, 2.5, 3.1, 3, 5])
|
||||
# this test can be removed after deprecation.
|
||||
with suppress_warnings() as sup:
|
||||
sup.filter(DeprecationWarning, "bias and ddof have no effect")
|
||||
r0 = np.ma.corrcoef(x, y, ddof=0)
|
||||
r1 = np.ma.corrcoef(x, y, ddof=1)
|
||||
# ddof should not have an effect (it gets cancelled out)
|
||||
assert_allclose(r0.data, r1.data)
|
||||
|
||||
def test_mask_not_backmangled(self):
|
||||
# See gh-10314. Test case taken from gh-3140.
|
||||
a = np.ma.MaskedArray([1., 2.], mask=[False, False])
|
||||
|
||||
@@ -188,10 +188,10 @@ class WrappedArray(NDArrayOperatorsMixin):
|
||||
class TestSubclassing:
|
||||
# Test suite for masked subclasses of ndarray.
|
||||
|
||||
def setup_method(self):
|
||||
def _create_data(self):
|
||||
x = np.arange(5, dtype='float')
|
||||
mx = msubarray(x, mask=[0, 1, 0, 0, 0])
|
||||
self.data = (x, mx)
|
||||
return x, mx
|
||||
|
||||
def test_data_subclassing(self):
|
||||
# Tests whether the subclass is kept.
|
||||
@@ -205,19 +205,19 @@ class TestSubclassing:
|
||||
|
||||
def test_maskedarray_subclassing(self):
|
||||
# Tests subclassing MaskedArray
|
||||
(x, mx) = self.data
|
||||
mx = self._create_data()[1]
|
||||
assert_(isinstance(mx._data, subarray))
|
||||
|
||||
def test_masked_unary_operations(self):
|
||||
# Tests masked_unary_operation
|
||||
(x, mx) = self.data
|
||||
x, mx = self._create_data()
|
||||
with np.errstate(divide='ignore'):
|
||||
assert_(isinstance(log(mx), msubarray))
|
||||
assert_equal(log(x), np.log(x))
|
||||
|
||||
def test_masked_binary_operations(self):
|
||||
# Tests masked_binary_operation
|
||||
(x, mx) = self.data
|
||||
x, mx = self._create_data()
|
||||
# Result should be a msubarray
|
||||
assert_(isinstance(add(mx, mx), msubarray))
|
||||
assert_(isinstance(add(mx, x), msubarray))
|
||||
@@ -230,7 +230,7 @@ class TestSubclassing:
|
||||
|
||||
def test_masked_binary_operations2(self):
|
||||
# Tests domained_masked_binary_operation
|
||||
(x, mx) = self.data
|
||||
x, mx = self._create_data()
|
||||
xmx = masked_array(mx.data.__array__(), mask=mx.mask)
|
||||
assert_(isinstance(divide(mx, mx), msubarray))
|
||||
assert_(isinstance(divide(mx, x), msubarray))
|
||||
@@ -427,20 +427,20 @@ def test_array_no_inheritance():
|
||||
class TestClassWrapping:
|
||||
# Test suite for classes that wrap MaskedArrays
|
||||
|
||||
def setup_method(self):
|
||||
def _create_data(self):
|
||||
m = np.ma.masked_array([1, 3, 5], mask=[False, True, False])
|
||||
wm = WrappedArray(m)
|
||||
self.data = (m, wm)
|
||||
return m, wm
|
||||
|
||||
def test_masked_unary_operations(self):
|
||||
# Tests masked_unary_operation
|
||||
(m, wm) = self.data
|
||||
wm = self._create_data()[1]
|
||||
with np.errstate(divide='ignore'):
|
||||
assert_(isinstance(np.log(wm), WrappedArray))
|
||||
|
||||
def test_masked_binary_operations(self):
|
||||
# Tests masked_binary_operation
|
||||
(m, wm) = self.data
|
||||
m, wm = self._create_data()
|
||||
# Result should be a WrappedArray
|
||||
assert_(isinstance(np.add(wm, wm), WrappedArray))
|
||||
assert_(isinstance(np.add(m, wm), WrappedArray))
|
||||
|
||||
Reference in New Issue
Block a user