# Buggy code
def _contour_level_args(self, z, args):
    """
    Determine the contour levels and store in self.levels.
    """
    if self.filled:
        fn = "contourf"
    else:
        fn = "contour"
    self._auto = False
    if self.levels is None:
        if len(args) == 0:
            lev = self._autolev(z, 7)
        else:
            level_arg = args[0]
            try:
                if type(level_arg) == int:
                    lev = self._autolev(z, level_arg)
                else:
                    lev = np.asarray(level_arg).astype(np.float64)
            except:
                raise TypeError("Last %s arg must give levels; see help(%s)" % (fn, fn))
        self.levels = lev
    if self.filled and len(self.levels) < 2:
        raise ValueError("Filled contours require at least 2 levels.")

    if len(self.levels) > 1 and np.amin(np.diff(self.levels)) <= 0.0:
        if hasattr(self, "_corner_mask") and self._corner_mask == "legacy":
            warnings.warn("Contour levels are not increasing")
        else:
            raise ValueError("Contour levels must be increasing")


# Traceback (TypeError)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-13-37a1d06c84a1> in <module>()
30 # the label
31 plt.figure()
---> 32 CS = plt.contour(X, Y, Z,locator=matplotlib.ticker.LinearLocator(10))
33 plt.clabel(CS, inline=1, fontsize=10)
34 plt.title('Simplest default with labels')

/home/w2naf/code/matplotlib/lib/matplotlib/pyplot.pyc in contour(*args, **kwargs)
2764         ax.hold(hold)
2765     try:
-> 2766         ret = ax.contour(*args, **kwargs)
2767     finally:
2768         ax.hold(washold)

/home/w2naf/code/matplotlib/lib/matplotlib/__init__.pyc in inner(ax, *args, **kwargs)
1810                     warnings.warn(msg % (label_namer, func.__name__),
1811                                   RuntimeWarning, stacklevel=2)
-> 1812             return func(ax, *args, **kwargs)
1813         pre_doc = inner.__doc__
1814         if pre_doc is None:

/home/w2naf/code/matplotlib/lib/matplotlib/axes/_axes.pyc in contour(self, *args, **kwargs)
5642             self.cla()
5643         kwargs['filled'] = False
-> 5644         return mcontour.QuadContourSet(self, *args, **kwargs)
5645     contour.__doc__ = mcontour.QuadContourSet.contour_doc
5646

/home/w2naf/code/matplotlib/lib/matplotlib/contour.pyc in __init__(self, ax, *args, **kwargs)
1422         are described in QuadContourSet.contour_doc.
1423         """
-> 1424         ContourSet.__init__(self, ax, *args, **kwargs)
1425
1426     def _process_args(self, *args, **kwargs):

/home/w2naf/code/matplotlib/lib/matplotlib/contour.pyc in __init__(self, ax, *args, **kwargs)
861         self._transform = kwargs.get('transform', None)
862
--> 863         self._process_args(*args, **kwargs)
864         self._process_levels()
865

/home/w2naf/code/matplotlib/lib/matplotlib/contour.pyc in _process_args(self, *args, **kwargs)
1443                 self._corner_mask = mpl.rcParams['contour.corner_mask']
1444
-> 1445             x, y, z = self._contour_args(args, kwargs)
1446
1447             _mask = ma.getmask(z)

/home/w2naf/code/matplotlib/lib/matplotlib/contour.pyc in _contour_args(self, args, kwargs)
1538             warnings.warn('Log scale: values of z <= 0 have been masked')
1539             self.zmin = z.min()
-> 1540         self._contour_level_args(z, args)
1541         return (x, y, z)
1542

/home/w2naf/code/matplotlib/lib/matplotlib/contour.pyc in _contour_level_args(self, z, args)
1167         if self.levels is None:
1168             if len(args) == 0:
-> 1169                 lev = self._autolev(z, 7)
1170             else:
1171                 level_arg = args[0]

/home/w2naf/code/matplotlib/lib/matplotlib/contour.pyc in _autolev(self, z, N)
1149         zmax = self.zmax
1150         zmin = self.zmin
-> 1151         lev = self.locator.tick_values(zmin, zmax)
1152         self._auto = True
1153         if self.filled:

/home/w2naf/code/matplotlib/lib/matplotlib/ticker.pyc in tick_values(self, vmin, vmax)
1173             vmin, vmax = vmax, vmin
1174
-> 1175         if (vmin, vmax) in self.presets:
1176             return self.presets[(vmin, vmax)]
1177

TypeError: unhashable type: 'MaskedArray'

# Fixed code
def _contour_level_args(self, z, args):
    """
    Determine the contour levels and store in self.levels.
    """
    if self.filled:
        fn = "contourf"
    else:
        fn = "contour"
    self._auto = False
    if self.levels is None:
        if len(args) == 0:
            lev = self._autolev(7)
        else:
            level_arg = args[0]
            try:
                if type(level_arg) == int:
                    lev = self._autolev(level_arg)
                else:
                    lev = np.asarray(level_arg).astype(np.float64)
            except:
                raise TypeError("Last %s arg must give levels; see help(%s)" % (fn, fn))
        self.levels = lev
    if self.filled and len(self.levels) < 2:
        raise ValueError("Filled contours require at least 2 levels.")

    if len(self.levels) > 1 and np.amin(np.diff(self.levels)) <= 0.0:
        if hasattr(self, "_corner_mask") and self._corner_mask == "legacy":
            warnings.warn("Contour levels are not increasing")
        else:
            raise ValueError("Contour levels must be increasing")