MCPcopy Create free account
hub / github.com/numpy/numpy / _test_cast_from_flexible

Method _test_cast_from_flexible

numpy/core/tests/test_multiarray.py:1703–1721  ·  view source on GitHub ↗
(self, dtype)

Source from the content-addressed store, hash-verified

1701 assert_equal(np.count_nonzero(a), builtins.sum(a.tolist()))
1702
1703 def _test_cast_from_flexible(self, dtype):
1704 # empty string -> false
1705 for n in range(3):
1706 v = np.array(b'', (dtype, n))
1707 assert_equal(bool(v), False)
1708 assert_equal(bool(v[()]), False)
1709 assert_equal(v.astype(bool), False)
1710 assert_(isinstance(v.astype(bool), np.ndarray))
1711 assert_(v[()].astype(bool) is np.False_)
1712
1713 # anything else -> true
1714 for n in range(1, 4):
1715 for val in [b'a', b'0', b' ']:
1716 v = np.array(val, (dtype, n))
1717 assert_equal(bool(v), True)
1718 assert_equal(bool(v[()]), True)
1719 assert_equal(v.astype(bool), True)
1720 assert_(isinstance(v.astype(bool), np.ndarray))
1721 assert_(v[()].astype(bool) is np.True_)
1722
1723 def test_cast_from_void(self):
1724 self._test_cast_from_flexible(np.void)

Callers 3

test_cast_from_voidMethod · 0.95
test_cast_from_bytesMethod · 0.95

Calls 3

assert_equalFunction · 0.90
assert_Function · 0.90
astypeMethod · 0.80

Tested by

no test coverage detected