Repository: pandas-dev/pandas

Issue:
test_invalid_colormap: ValueError not raised
```
======================================================================
FAIL: test_invalid_colormap (pandas.tests.test_graphics.TestDataFrameGroupByPlots)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/yoh/deb/gits/pkg-exppsy/build-area/pandas-0.11.0+git43-g7b2eaa4/debian/tmp/usr/lib/python2.7/dist-packages/pandas/tests/test_graphics.py", line 995, in test_invalid_colormap
    self.assertRaises(ValueError, df.plot, colormap='invalid_colormap')
AssertionError: ValueError not raised
```

that is under Agg backend and matplotlib 1.1.1~rc2-1



Discussion:
cc @qwhelan, @jtratner

anyone know why this is happening?

@yarikoptic did you say you were using a customized back end?

Also, can you show us what happens if you try to get a non-standard colormap from your version of matplotlib?

This test, IIRC, just checks that plotting bubbles up the error from the mpl call to get the colormap. So if the other tests are passing, to me this suggests that either it's a matplotlib bug OR the Agg backend handles unknown colormaps differently.

If there is variance in how colormaps are handled by backend, we should add a skip test at the  start if directly asking for a bad colormap doesn't raise an error. 

Should have been @yarikoptic above (sorry about that!) 

For me even with the default interactive backend  I get no exception while asking for the colormap

```
$> python -c "import matplotlib as mpl; print mpl.__version__;import matplotlib.cm as cm; print cm.get_cmap('invalid_colormap');" 
1.1.1rc2
```

```
$> nosetests -s -v pandas/tests/test_graphics.py:TestDataFrameGroupByPlots.test_invalid_colormap
/usr/bin/nosetests:5: UserWarning: Module dap was already imported from None, but /usr/lib/python2.7/dist-packages is being added to sys.path
  from pkg_resources import load_entry_point
test_invalid_colormap (pandas.tests.test_graphics.TestDataFrameGroupByPlots) ... FAIL

======================================================================
FAIL: test_invalid_colormap (pandas.tests.test_graphics.TestDataFrameGroupByPlots)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/yoh/deb/gits/pkg-exppsy/pandas/pandas/tests/test_graphics.py", line 995, in test_invalid_colormap
    self.assertRaises(ValueError, df.plot, colormap='invalid_colormap')
AssertionError: ValueError not raised

----------------------------------------------------------------------
Ran 1 test in 0.319s

FAILED (failures=1)
```

@yarikoptic I think t's because of the version of `matplotlib` that you're using

what you should see

```
In [7]: cm.get_cmap('invalid')
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-7-ddb89b348247> in <module>()
----> 1 cm.get_cmap('invalid')

/home/phillip/.virtualenvs/pandas/lib/python2.7/site-packages/matplotlib/cm.pyc in get_cmap(name, lut)
    153             return _generate_cmap(name, lut)
    154
--> 155     raise ValueError("Colormap %s is not recognized" % name)
    156
    157 class ScalarMappable:

ValueError: Colormap invalid is not recognized
```

my versions

```
INSTALLED VERSIONS
------------------
Python: 2.7.5.final.0
OS: Linux 3.9.9-1-ARCH #1 SMP PREEMPT Wed Jul 3 22:45:16 CEST 2013 x86_64
LC_ALL: None
LANG: en_US.UTF-8

Cython: 0.19.1
Numpy: 1.7.1
Scipy: 0.12.0
statsmodels: 0.5.0.dev-95737a1
    patsy: 0.1.0
scikits.timeseries: 0.91.3
dateutil: 2.1
pytz: 2013b
bottleneck: 0.6.0
PyTables: 3.0.0
    numexpr: 2.1
matplotlib: 1.2.1
openpyxl: 1.6.2
xlrd: 0.9.2
xlwt: 0.7.5
sqlalchemy: 0.8.1
lxml: 3.2.1
bs4: 4.2.1
html5lib: 1.0b1
```

:phone: pandas version help hotline, how can i help you? :smile: 

yep it's the version, just installed 1.1.1 and it returns `None`

i'll add a version check in there in the test

actually u know what i'll raise if the color map is `None`

wow mpl gained a hefty 29MB from 1.1.1 to 1.2.1...


Resolving patch:
diff --git a/pandas/tools/plotting.py b/pandas/tools/plotting.py
--- a/pandas/tools/plotting.py
+++ b/pandas/tools/plotting.py
@@ -91,14 +91,17 @@
 def _get_standard_kind(kind):
     return {'density': 'kde'}.get(kind, kind)
 
-def _get_standard_colors(num_colors=None, colormap=None,
-                        color_type='default', color=None):
+def _get_standard_colors(num_colors=None, colormap=None, color_type='default',
+                         color=None):
     import matplotlib.pyplot as plt
 
     if color is None and colormap is not None:
         if isinstance(colormap, basestring):
             import matplotlib.cm as cm
+            cmap = colormap
             colormap = cm.get_cmap(colormap)
+            if colormap is None:
+                raise ValueError("Colormap {0} is not recognized".format(cmap))
         colors = map(colormap, np.linspace(0, 1, num=num_colors))
     elif color is not None:
         if colormap is not None:


Test patch:
diff --git a/pandas/tests/test_graphics.py b/pandas/tests/test_graphics.py
--- a/pandas/tests/test_graphics.py
+++ b/pandas/tests/test_graphics.py
@@ -990,8 +990,7 @@ def test_option_mpl_style(self):
             pass
 
     def test_invalid_colormap(self):
-        df = DataFrame(np.random.randn(500, 2), columns=['A', 'B'])
-
+        df = DataFrame(np.random.randn(3, 2), columns=['A', 'B'])
         self.assertRaises(ValueError, df.plot, colormap='invalid_colormap')