diff options
author | Matthew Bowden <bowdenm@spu.edu> | 2018-10-10 10:07:03 -0700 |
---|---|---|
committer | Matthew Bowden <bowdenm@spu.edu> | 2018-10-10 10:07:03 -0700 |
commit | e4e897fa1740ee4efaa276457debda9b8707b457 (patch) | |
tree | d567d4599f91615aeb05233554aeece5d13df623 /numpy/lib/tests/test_histograms.py | |
parent | cb9add3de86a5b886e08b5b649be7e6ccdf5f927 (diff) | |
download | numpy-e4e897fa1740ee4efaa276457debda9b8707b457.tar.gz |
BUG: Allow boolean subtract in histogram
Convert bool to uint at start, rather than attempt a XOR
Only check type against np.bool_
Refactor warnings check
Diffstat (limited to 'numpy/lib/tests/test_histograms.py')
-rw-r--r-- | numpy/lib/tests/test_histograms.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/numpy/lib/tests/test_histograms.py b/numpy/lib/tests/test_histograms.py index 561f5f938..a71060a46 100644 --- a/numpy/lib/tests/test_histograms.py +++ b/numpy/lib/tests/test_histograms.py @@ -141,6 +141,23 @@ class TestHistogram(object): counts_hist, xedges, yedges = np.histogram2d(x, y, bins=100) assert_equal(counts_hist.sum(), 3.) + def test_bool_conversion(self): + # gh-12107 + # Reference integer histogram + a = np.array([1, 1, 0], dtype=np.uint8) + int_hist, int_edges = np.histogram(a) + + # Should raise an warning on booleans + # Ensure that the histograms are equivalent, need to suppress + # the warnings to get the actual outputs + with suppress_warnings() as sup: + rec = sup.record(RuntimeWarning, 'Converting input from .*') + hist, edges = np.histogram([True, True, False]) + # A warning should be issued + assert_equal(len(rec), 1) + assert_array_equal(hist, int_hist) + assert_array_equal(edges, int_edges) + def test_weights(self): v = np.random.rand(100) w = np.ones(100) * 5 |