summaryrefslogtreecommitdiff
path: root/numpy/lib/tests/test_histograms.py
diff options
context:
space:
mode:
authorMatthew Bowden <bowdenm@spu.edu>2018-10-10 10:07:03 -0700
committerMatthew Bowden <bowdenm@spu.edu>2018-10-10 10:07:03 -0700
commite4e897fa1740ee4efaa276457debda9b8707b457 (patch)
treed567d4599f91615aeb05233554aeece5d13df623 /numpy/lib/tests/test_histograms.py
parentcb9add3de86a5b886e08b5b649be7e6ccdf5f927 (diff)
downloadnumpy-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.py17
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