diff options
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/lib/tests/test_twodim_base.py | 10 | ||||
-rw-r--r-- | numpy/lib/twodim_base.py | 3 |
2 files changed, 13 insertions, 0 deletions
diff --git a/numpy/lib/tests/test_twodim_base.py b/numpy/lib/tests/test_twodim_base.py index cce683bfe..c1c5a1615 100644 --- a/numpy/lib/tests/test_twodim_base.py +++ b/numpy/lib/tests/test_twodim_base.py @@ -18,6 +18,9 @@ import numpy as np from numpy.core.tests.test_overrides import requires_array_function +import pytest + + def get_mat(n): data = arange(n) data = add.outer(data, data) @@ -295,6 +298,13 @@ class TestHistogram2d: r = histogram2d(xy, xy, weights=s_d) assert_(r, ((ShouldDispatch,), (xy, xy), dict(weights=s_d))) + @pytest.mark.parametrize(("x_len", "y_len"), [(10, 11), (20, 19)]) + def test_bad_length(self, x_len, y_len): + x, y = np.ones(x_len), np.ones(y_len) + with pytest.raises(ValueError, + match='x and y must have the same length.'): + histogram2d(x, y) + class TestTri: def test_dtype(self): diff --git a/numpy/lib/twodim_base.py b/numpy/lib/twodim_base.py index 811faff79..3e5ad31ff 100644 --- a/numpy/lib/twodim_base.py +++ b/numpy/lib/twodim_base.py @@ -804,6 +804,9 @@ def histogram2d(x, y, bins=10, range=None, normed=None, weights=None, >>> plt.show() """ from numpy import histogramdd + + if len(x) != len(y): + raise ValueError('x and y must have the same length.') try: N = len(bins) |