Repository: bokeh/bokeh

Issue:
Error with histogram
I am trying to create a Histogram with Bokeh and I'm getting the following error. The histogram is completely wrong.

For example

I have this list:

[1205.0, 2527.0, 1745.0, 1556.0, 493.0, 2276.0, 556.0, 1928.0, 2641.0, 1897.0, 1891.0, 1545.0, 1307.0, 1692.0, 1543.0, 1282.0, 775.0, 2032.0, 1240.0, 473.0, 1612.0, 605.0, 327.0, 946.0, 541.0, 1539.0, 529.0, 628.0, 1453.0, 297.0, 703.0, 269.0, 751.0, 245.0, 1182.0, 515.0, 435.0, 383.0, 457.0, 730.0, 614.0, 414.0, 324.0, 776.0, 611.0, 544.0, 538.0, 579.0, 806.0, 459.0, 458.0, 626.0, 621.0, 544.0, 535.0, 385.0, 401.0, 614.0, 665.0, 488.0, 172.0, 142.0, 37.0, 453.0, 355.0, 22.0, 502.0, 273.0, 720.0, 582.0, 198.0, 198.0, 597.0, 516.0, 815.0, 402.0, 605.0, 711.0, 614.0, 468.0]

And when I try to create a histogram:

hist = Histogram(val)
show(hist)

I get: (the Y-axis is completely wrong) ... How can I solve this?
Thanks



Discussion:
Hi @andrefilipemb, our issue tracker is becoming too large to manage easily. We have to reserve it for feature requests and bug reports only, to have any hope of taming it. This kind of support question should go to the general public mailing list:

https://groups.google.com/a/continuum.io/forum/#!forum/bokeh

We hope you post there, and then if there turns out to be a bug we welcome you opening a new issue with the specific bug report.

Er... this exact question _did_ go to the mailing list, and the advice was to file an issue.
https://groups.google.com/a/continuum.io/forum/#!search/histogram/bokeh/JTsX9Hx-1sY/cGsUfqPvDAAJ

Small example that reproduces the bug:

```
from bokeh.charts import Histogram
from bokeh.plotting import output_file, show
hist = Histogram([300, 300, 300, 400, 400, 500])
output_file('/tmp/output.html')
show(hist)
```

![histogram](https://cloud.githubusercontent.com/assets/6985468/13460102/45b1d38e-e070-11e5-9e38-4ce2f375c484.png)

Note how the Y-axis counts 500 values for one bin, when clearly there are only 6 values in the entire data set.

Also note how we'd expect a histogram much more weighted to the left than the right, i.e. count(300) is 3, count(400) is 2, count(500) is 1.

```
>>> import numpy
>>> counts, edges = numpy.histogram([300, 300, 300, 400, 400, 500], bins=3)
>>> counts
array([3, 2, 1])
```

whereas the counts for the `bokeh.charts.Histogram` seem more like `array([1, 500])`.

thanks @twaugh for the follow up on this and the code to reproduce.. I think this is actually a (weird?) bug, will try later and reopen the issue if confirmed..

This is definitely a bug (lnteresting one :) ).. reopening...

Issue should be here: https://github.com/bokeh/bokeh/blob/master/bokeh/charts/glyphs.py#L603-L605

Which I'd be tempted to remove this part (since I miss the possible scenarios) but seems to fall into a very specific case... so need more more tests before just removing that.. 

pinging @rothnic for some historical knowledge :-)


Resolving patch:
diff --git a/bokeh/charts/glyphs.py b/bokeh/charts/glyphs.py
--- a/bokeh/charts/glyphs.py
+++ b/bokeh/charts/glyphs.py
@@ -600,10 +600,7 @@ def get_start(self):
 
     def get_end(self):
         """Get the value for the end of the glyph."""
-        if len(self.values.index) == 1 and not self.values.dtype.name == 'object':
-            self.end_agg = None
-            return self.values[0]
-        elif isinstance(self.end_agg, str):
+        if isinstance(self.end_agg, str):
             self.end_agg = stats[self.end_agg]()
 
         self.end_agg.set_data(self.values)


Test patch:
diff --git a/bokeh/charts/tests/test_comp_glyphs.py b/bokeh/charts/tests/test_comp_glyphs.py
--- a/bokeh/charts/tests/test_comp_glyphs.py
+++ b/bokeh/charts/tests/test_comp_glyphs.py
@@ -2,8 +2,9 @@
 import pandas as pd
 from bokeh.charts.models import CompositeGlyph
 from bokeh.charts.glyphs import (AreaGlyph, LineGlyph, PointGlyph, StepGlyph,
-                                 BarGlyph, BoxGlyph)
+                                 BarGlyph, BoxGlyph, BarGlyph)
 from bokeh.charts.operations import stack
+from bokeh.charts.stats import stats
 
 from bokeh.models import ColumnDataSource
 
@@ -104,6 +105,19 @@ def test_boxplot():
     assert box.q3 == 113.5
     assert box.iqr == 7.5
 
-    # test Interquartile range do not exceed data limits 
+    # test Interquartile range do not exceed data limits
     assert box.w0 == 102
     assert box.w1 == 118
+
+
+def test_bar_single_value():
+    data=[500]
+
+    for stat in stats.keys():
+        bar = BarGlyph(label={'cat': 'a'}, values=data, color='red', agg='sum')
+
+        assert bar.get_start() == 0
+        if stats != 'count':
+            assert bar.get_end() == 500
+        else:
+            assert bar.get_end() == 1