Skip to content

Commit

Permalink
TST: Changed TC to check for TypeError in floor divide
Browse files Browse the repository at this point in the history
  • Loading branch information
ganesh-k13 committed May 29, 2021
1 parent 2ad9dd7 commit 9257feb
Showing 1 changed file with 27 additions and 15 deletions.
42 changes: 27 additions & 15 deletions numpy/ma/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1317,7 +1317,7 @@ def test_minmax_dtypes(self):
dtype=float_dtype)
assert_equal(zm.min(), float_dtype(-np.inf-1j))
assert_equal(zm.max(), float_dtype(np.inf+2j))

cmax = np.inf - 1j * np.finfo(np.float64).max
assert masked_array([-cmax, 0], mask=[0, 1]).max() == -cmax
assert masked_array([cmax, 0], mask=[0, 1]).min() == cmax
Expand Down Expand Up @@ -2853,39 +2853,51 @@ def test_inplace_multiplication_array_type(self):

def test_inplace_floor_division_scalar_type(self):
# Test of inplace division
# Check for TypeError in case of unsupported types
unsupported = {np.complex64, np.complex128, np.complex256}
for t in self.othertypes:
with warnings.catch_warnings(record=True) as w:
warnings.filterwarnings("always")
(x, y, xm) = (_.astype(t) for _ in self.uint8data)
x = arange(10, dtype=t) * t(2)
xm = arange(10, dtype=t) * t(2)
xm[2] = masked
x //= t(2)
xm //= t(2)
assert_equal(x, y)
assert_equal(xm, y)
try:
x //= t(2)
xm //= t(2)
assert_equal(x, y)
assert_equal(xm, y)

assert_equal(len(w), 0, "Failed on type=%s." % t)
assert_equal(len(w), 0, "Failed on type=%s." % t)
except TypeError:
msg = f"Supported type {t} throwing TypeError"
assert t in unsupported, msg

def test_inplace_floor_division_array_type(self):
# Test of inplace division
# Check for TypeError in case of unsupported types
unsupported = {np.complex64, np.complex128, np.complex256}
for t in self.othertypes:
with warnings.catch_warnings(record=True) as w:
warnings.filterwarnings("always")
(x, y, xm) = (_.astype(t) for _ in self.uint8data)
m = xm.mask
a = arange(10, dtype=t)
a[-1] = masked
x //= a
xm //= a
assert_equal(x, y // a)
assert_equal(xm, y // a)
assert_equal(
xm.mask,
mask_or(mask_or(m, a.mask), (a == t(0)))
)
try:
x //= a
xm //= a
assert_equal(x, y // a)
assert_equal(xm, y // a)
assert_equal(
xm.mask,
mask_or(mask_or(m, a.mask), (a == t(0)))
)

assert_equal(len(w), 0, f'Failed on type={t}.')
assert_equal(len(w), 0, f'Failed on type={t}.')
except TypeError:
msg = f"Supported type {t} throwing TypeError"
assert t in unsupported, msg

def test_inplace_division_scalar_type(self):
# Test of inplace division
Expand Down

0 comments on commit 9257feb

Please sign in to comment.