From 820765d762513510a8e46f108e8bc8b366127f8f Mon Sep 17 00:00:00 2001 From: luzpaz Date: Tue, 1 May 2018 04:28:18 +0000 Subject: MAINT: Misc. typos (#11005) User- and non-user-facing typos. Some source typos fixes as well. Found via `codespell`. --- numpy/lib/tests/test_histograms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'numpy/lib/tests/test_histograms.py') diff --git a/numpy/lib/tests/test_histograms.py b/numpy/lib/tests/test_histograms.py index 06daacbdc..597b5b376 100644 --- a/numpy/lib/tests/test_histograms.py +++ b/numpy/lib/tests/test_histograms.py @@ -253,7 +253,7 @@ class TestHistogram(object): one_nan = np.array([0, 1, np.nan]) all_nan = np.array([np.nan, np.nan]) - # the internal commparisons with NaN give warnings + # the internal comparisons with NaN give warnings sup = suppress_warnings() sup.filter(RuntimeWarning) with sup: -- cgit v1.2.1 From 4a5d02fe2879846404a2a3a5f347c4c4509ee6d9 Mon Sep 17 00:00:00 2001 From: Eric Wieser Date: Sun, 8 Apr 2018 14:57:21 -0700 Subject: ENH: Disable fuzzing on histogram boundaries Previously a fuzzy rounded comparison was used for the rightmost bin of histogramdd. It's not clear why this was done, and it resulted in surprising behavior. This also removes the restriction that bin edges must be floats, and allows integer arrays to be passed (and returned) Fixes gh-10864 --- numpy/lib/tests/test_histograms.py | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'numpy/lib/tests/test_histograms.py') diff --git a/numpy/lib/tests/test_histograms.py b/numpy/lib/tests/test_histograms.py index 06daacbdc..8c420bd77 100644 --- a/numpy/lib/tests/test_histograms.py +++ b/numpy/lib/tests/test_histograms.py @@ -612,8 +612,6 @@ class TestHistogramdd(object): x = np.arange(8).reshape(2, 4) assert_raises(ValueError, np.histogramdd, x, bins=[-1, 2, 4, 5]) assert_raises(ValueError, np.histogramdd, x, bins=[1, 0.99, 1, 1]) - assert_raises( - ValueError, np.histogramdd, x, bins=[1, 1, 1, [1, 2, 2, 3]]) assert_raises( ValueError, np.histogramdd, x, bins=[1, 1, 1, [1, 2, 3, -3]]) assert_(np.histogramdd(x, bins=[1, 1, 1, [1, 2, 3, 4]])) @@ -646,7 +644,7 @@ class TestHistogramdd(object): bins = [[0., 0.5, 1.0]] hist, _ = histogramdd(x, bins=bins) assert_(hist[0] == 0.0) - assert_(hist[1] == 1.) + assert_(hist[1] == 0.0) x = [1.0001] bins = [[0., 0.5, 1.0]] hist, _ = histogramdd(x, bins=bins) @@ -660,3 +658,28 @@ class TestHistogramdd(object): range=[[0.0, 1.0], [0.25, 0.75], [0.25, np.inf]]) assert_raises(ValueError, histogramdd, vals, range=[[0.0, 1.0], [np.nan, 0.75], [0.25, 0.5]]) + + def test_equal_edges(self): + """ Test that adjacent entries in an edge array can be equal """ + x = np.array([0, 1, 2]) + y = np.array([0, 1, 2]) + x_edges = np.array([0, 2, 2]) + y_edges = 1 + hist, edges = histogramdd((x, y), bins=(x_edges, y_edges)) + + hist_expected = np.array([ + [2.], + [1.], # x == 2 falls in the final bin + ]) + assert_equal(hist, hist_expected) + + def test_edge_dtype(self): + """ Test that if an edge array is input, its type is preserved """ + x = np.array([0, 10, 20]) + y = x / 10 + x_edges = np.array([0, 5, 15, 20]) + y_edges = x_edges / 10 + hist, edges = histogramdd((x, y), bins=(x_edges, y_edges)) + + assert_equal(edges[0].dtype, x_edges.dtype) + assert_equal(edges[1].dtype, y_edges.dtype) -- cgit v1.2.1 From 8ed017a30c8ec60f17538c585f87415a1ca989fc Mon Sep 17 00:00:00 2001 From: Eric Wieser Date: Mon, 30 Apr 2018 23:31:21 -0700 Subject: BUG: histogramdd fails on large integers This is due to gh-11022. --- numpy/lib/tests/test_histograms.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'numpy/lib/tests/test_histograms.py') diff --git a/numpy/lib/tests/test_histograms.py b/numpy/lib/tests/test_histograms.py index 8c420bd77..8583efab8 100644 --- a/numpy/lib/tests/test_histograms.py +++ b/numpy/lib/tests/test_histograms.py @@ -683,3 +683,15 @@ class TestHistogramdd(object): assert_equal(edges[0].dtype, x_edges.dtype) assert_equal(edges[1].dtype, y_edges.dtype) + + def test_large_integers(self): + big = 2**60 # Too large to represent with a full precision float + + x = np.array([0], np.int64) + x_edges = np.array([-1, +1], np.int64) + y = big + x + y_edges = big + x_edges + + hist, edges = histogramdd((x, y), bins=(x_edges, y_edges)) + + assert_equal(hist[0, 0], 1) -- cgit v1.2.1