diff options
author | Julian Taylor <juliantaylor108@gmail.com> | 2014-07-29 22:48:35 +0200 |
---|---|---|
committer | Julian Taylor <juliantaylor108@gmail.com> | 2014-07-29 22:48:35 +0200 |
commit | 2ad538899928c249af456d93f250ebbd7535dcff (patch) | |
tree | bdac30c97cecbb3b8b65ec91b352eeade7a41c0c /numpy/lib/tests | |
parent | c50a2da70b4a5b5d23636c454b04d8afa7642d36 (diff) | |
parent | a7c788c2dfcc9e44bab1ca69c1473785f31e3f70 (diff) | |
download | numpy-2ad538899928c249af456d93f250ebbd7535dcff.tar.gz |
Merge pull request #4916 from yotam/triu-dtype-fix
BUG: Avoid type promotion in tril and triu.
Diffstat (limited to 'numpy/lib/tests')
-rw-r--r-- | numpy/lib/tests/test_twodim_base.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/numpy/lib/tests/test_twodim_base.py b/numpy/lib/tests/test_twodim_base.py index c9a220920..d07e4d578 100644 --- a/numpy/lib/tests/test_twodim_base.py +++ b/numpy/lib/tests/test_twodim_base.py @@ -324,6 +324,28 @@ def test_tril_triu_with_inf(): assert_array_equal(np.tril(arr), out_tril) +def test_tril_triu_dtype(): + # Issue 4916 + # tril and triu should return the same dtype as input + for c in np.typecodes['All']: + if c == 'V': + continue + arr = np.zeros((3, 3), dtype=c) + assert_equal(np.triu(arr).dtype, arr.dtype) + assert_equal(np.tril(arr).dtype, arr.dtype) + + # check special cases + arr = np.array([['2001-01-01T12:00', '2002-02-03T13:56'], + ['2004-01-01T12:00', '2003-01-03T13:45']], + dtype='datetime64') + assert_equal(np.triu(arr).dtype, arr.dtype) + assert_equal(np.tril(arr).dtype, arr.dtype) + + arr = np.zeros((3,3), dtype='f4,f4') + assert_equal(np.triu(arr).dtype, arr.dtype) + assert_equal(np.tril(arr).dtype, arr.dtype) + + def test_mask_indices(): # simple test without offset iu = mask_indices(3, np.triu) |