summaryrefslogtreecommitdiff
path: root/numpy/lib/tests/test_histograms.py
diff options
context:
space:
mode:
authorVarun Nayyar <nayyarv@users.noreply.github.com>2018-04-10 12:55:59 +0800
committerEric Wieser <wieser.eric@gmail.com>2018-04-09 21:55:59 -0700
commit918a167c30a7e19f0c0061f5e09e7637b1e04591 (patch)
tree0b1c76b31578cb10b9777e750cdbb0767823544f /numpy/lib/tests/test_histograms.py
parentab4e4c93beb671b634bac34d21f30452ef194bf6 (diff)
downloadnumpy-918a167c30a7e19f0c0061f5e09e7637b1e04591.tar.gz
ENH: Improve histogram bins="auto" for data with little variance (#10739)
Now falls back on sturges estimator when the IQR is zero
Diffstat (limited to 'numpy/lib/tests/test_histograms.py')
-rw-r--r--numpy/lib/tests/test_histograms.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/numpy/lib/tests/test_histograms.py b/numpy/lib/tests/test_histograms.py
index 6777089ab..06daacbdc 100644
--- a/numpy/lib/tests/test_histograms.py
+++ b/numpy/lib/tests/test_histograms.py
@@ -443,6 +443,24 @@ class TestHistogramOptimBinNums(object):
assert_equal(len(a), numbins, err_msg="{0} estimator, "
"No Variance test".format(estimator))
+ def test_limited_variance(self):
+ """
+ Check when IQR is 0, but variance exists, we return the sturges value
+ and not the fd value.
+ """
+ lim_var_data = np.ones(1000)
+ lim_var_data[:3] = 0
+ lim_var_data[-4:] = 100
+
+ edges_auto = histogram_bin_edges(lim_var_data, 'auto')
+ assert_equal(edges_auto, np.linspace(0, 100, 12))
+
+ edges_fd = histogram_bin_edges(lim_var_data, 'fd')
+ assert_equal(edges_fd, np.array([0, 100]))
+
+ edges_sturges = histogram_bin_edges(lim_var_data, 'sturges')
+ assert_equal(edges_sturges, np.linspace(0, 100, 12))
+
def test_outlier(self):
"""
Check the FD, Scott and Doane with outliers.