(self, dtype)
| 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) |
no test coverage detected