Repository: bokeh/bokeh

Issue:
Pandas required to use the server!
In the happiness demo I am using `plotting.Figure` to make my plots.

When I setup a clean environment with only `bokeh` and `django` as the requirements, I got the following error. I don't use the charts interface at all, so I'm guessing this is a bug.

``` sh
Failed to push document: RuntimeError('The bokeh.charts interface requires Pandas (http://pandas.pydata.org) to be installed.',)
/envs/happiness/lib/python3.5/site-packages/bokeh/client/connection.py in push_doc, line 231
```



Discussion:
Guessing this is the problem: https://github.com/bokeh/bokeh/blob/master/bokeh/model.py#L51-L66

A few options I can think of:
- restore pandas as a dependency
- try the imports incrementally (only import `bokeh.charts` if  lookup in `bokeh.models` fails)
- defer the pandas dependency warning until classes that actually use it are initialized

I guess the last would be the best, but a little bit of work.  On the plus side it would let people use charts that _don't_ need pandas without having to install it. The second is easier, it would merely "work" (scare quotes). 

On top of my head, I doubt charts should be preloaded. I need to verify this.

FYI this is a must-fix (one way or another) for `0.11.1` I'd like to have a fix in the next dev build (looks like tomorrow morning)

> defer the pandas dependency warning until classes that actually use it are initialized

Yes, that definitely seems best, but it sounds hard.

Looks like just this:

```
bryan@0199-bryanv (git:master) ~/work/bokeh/bokeh $ grip "import pandas"
./charts/attributes.py:
    5 : import pandas as pd
./charts/builders/donut_builder.py:
   81 :         import pandas as pd
./charts/builders/horizon_builder.py:
   56 :         import pandas as pd
./charts/builders/timeseries_builder.py:
   61 :         import pandas as pd
./charts/conftest.py:
    4 : import pandas as pd
./charts/data_source.py:
   17 : import pandas as pd
./charts/glyphs.py:
    6 : import pandas as pd
./charts/models.py:
    4 : import pandas as pd
./charts/properties.py:
   12 : import pandas as pd
./charts/stats.py:
   18 : import pandas as pd
./charts/tests/test_comp_glyphs.py:
    2 : import pandas as pd
./charts/tests/test_stats.py:
    6 : import pandas as pd
./charts/utils.py:
   24 : import pandas as pd
```

I'll make a stab...

tangent: `grip` looks like a useful wrapper on grep.

it's just:

```
alias grip='grin -I "*.py"'
```

(`grin` comes with anaconda)

Actually, this either has to be solved by removing the preload, or by adding back in pandas as a hard dependency. The preload brings in lots of the places that the more specific import would be anyway. 

Nothing under `bokeh.charts` inherits from `Model` afaict I think the import can just be removed. 


Resolving patch:
diff --git a/bokeh/model.py b/bokeh/model.py
--- a/bokeh/model.py
+++ b/bokeh/model.py
@@ -51,7 +51,13 @@ def __new__(meta_cls, class_name, bases, class_dict):
     @classmethod
     def _preload_models(cls):
         from . import models; models
-        from .charts import Chart; Chart
+        from .plotting import Figure; Figure
+        try:
+            from .charts import Chart; Chart
+        except RuntimeError:
+            # this would occur if pandas is not installed but then we can't
+            # use the bokeh.charts interface anyway
+            pass
 
     @classmethod
     def get_class(cls, view_model_name):


Test patch: