8000 BUG, TST: Fix tests of ma.count return type. by charris · Pull Request #4699 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

BUG, TST: Fix tests of ma.count return type. #4699

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 14, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
BUG, TST: Fix tests of ma.count return type.
The masked array count method was fixed to use np.intp when doing sums.
The return type is always np.intp except for count(arr, axis=None) when
arr has no mask, in which case the return type is that of ndarray.size.

The test errors were noted in #4698.
  • Loading branch information
charris committed May 11, 2014
commit 9592bfa7d29c238bc891be255a4a666b407a9e2f
38 changes: 20 additions & 18 deletions numpy/ma/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,27 +808,29 @@ def test_basic_ufuncs(self):

def test_count_func(self):
# Tests count
ott = array([0., 1., 2., 3.], mask=[1, 0, 0, 0])
ott1= array([0., 1., 2., 3.])
if sys.version_info[0] >= 3:
self.assertTrue(isinstance(count(ott), np.integer))
else:
self.assertTrue(isinstance(count(ott), int))
assert_equal(3, count(ott))
assert_equal(1, count(1))
assert_equal(0, array(1, mask=[1]))

ott = array([0., 1., 2., 3.], mask=[1, 0, 0, 0])
res = count(ott)
self.assertTrue(res.dtype.type is np.intp)
assert_equal(3, res)

ott = ott.reshape((2, 2))
assert_(isinstance(count(ott, 0), ndarray))
if sys.version_info[0] >= 3:
assert_(isinstance(count(ott), np.integer))
else:
assert_(isinstance(count(ott), int))
assert_equal(3, count(ott))
assert_(getmask(count(ott, 0)) is nomask)
< 8000 /td> assert_equal([1, 2], count(ott, 0))
assert_equal(type(count(ott, 0)), type(count(ott1, 0)))
assert_equal(count(ott, 0).dtype, count(ott1, 0).dtype)
assert_raises(IndexError, ott1.count, 1)
res = count(ott)
assert_(res.dtype.type is np.intp)
assert_equal(3, res)
res = count(ott, 0)
assert_(isinstance(res, ndarray))
assert_equal([1, 2], res)
assert_(getmask(res) is nomask)

ott= array([0., 1., 2., 3.])
res = count(ott, 0)
assert_(isinstance(res, ndarray))
assert_(res.dtype.type is np.intp)

assert_raises(IndexError, ott.count, 1)

def test_minmax_func(self):
# Tests minimum and maximum.
Expand Down
11 changes: 3 additions & 8 deletions numpy/ma/tests/test_old_ma.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,19 +153,14 @@ def test_testUfuncs1(self):
def test_xtestCount(self):
# Test count
ott = array([0., 1., 2., 3.], mask=[1, 0, 0, 0])
if sys.version_info[0] >= 3:
self.assertTrue(isinstance(count(ott), np.integer))
else:
self.assertTrue(isinstance(count(ott), int))
self.assertTrue(count(ott).dtype.type is np.intp)
self.assertEqual(3, count(ott))
self.assertEqual(1, count(1))
self.assertTrue(eq(0, array(1, mask=[1])))
ott = ott.reshape((2, 2))
self.assertTrue(count(ott).dtype.type is np.intp)
assert_(isinstance(count(ott, 0), np.ndarray))
if sys.version_info[0] >= 3:
assert_(isinstance(count(ott), np.integer))
else:
assert_(isinstance(count(ott), int))
self.assertTrue(count(ott).dtype.type is np.intp)
self.assertTrue(eq(3, count(ott)))
assert_(getmask(count(ott, 0)) is nomask)
self.assertTrue(eq([1, 2], count(ott, 0)))
Expand Down
0