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

Method test_safe_casting

numpy/core/tests/test_ufunc.py:1835–1852  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1833 uf.accumulate(np.zeros((0, 0)), axis=0)
1834
1835 def test_safe_casting(self):
1836 # In old versions of numpy, in-place operations used the 'unsafe'
1837 # casting rules. In versions >= 1.10, 'same_kind' is the
1838 # default and an exception is raised instead of a warning.
1839 # when 'same_kind' is not satisfied.
1840 a = np.array([1, 2, 3], dtype=int)
1841 # Non-in-place addition is fine
1842 assert_array_equal(assert_no_warnings(np.add, a, 1.1),
1843 [2.1, 3.1, 4.1])
1844 assert_raises(TypeError, np.add, a, 1.1, out=a)
1845
1846 def add_inplace(a, b):
1847 a += b
1848
1849 assert_raises(TypeError, add_inplace, a, 1.1)
1850 # Make sure that explicitly overriding the exception is allowed:
1851 assert_no_warnings(np.add, a, 1.1, out=a, casting="unsafe")
1852 assert_array_equal(a, [2, 3, 4])
1853
1854 def test_ufunc_custom_out(self):
1855 # Test ufunc with built in input types and custom output type

Callers

nothing calls this directly

Calls 3

assert_array_equalFunction · 0.90
assert_no_warningsFunction · 0.90
assert_raisesFunction · 0.90

Tested by

no test coverage detected