# Buggy code
def _mapclassify_choro(values, scheme, **classification_kwds):
    """
    Wrapper for choropleth schemes from mapclassify for use with plot_dataframe

    Parameters
    ----------
    values
        Series to be plotted
    scheme : str
        One of mapclassify classification schemes
        Options are BoxPlot, EqualInterval, FisherJenks,
        FisherJenksSampled, HeadTailBreaks, JenksCaspall,
        JenksCaspallForced, JenksCaspallSampled, MaxP,
        MaximumBreaks, NaturalBreaks, Quantiles, Percentiles, StdMean,
        UserDefined

    **classification_kwds : dict
        Keyword arguments for classification scheme
        For details see mapclassify documentation:
        https://mapclassify.readthedocs.io/en/latest/api.html

    Returns
    -------
    binning
        Binning objects that holds the Series with values replaced with
        class identifier and the bins.
    """
    try:
        import mapclassify.classifiers as classifiers

    except ImportError:
        raise ImportError(
            "The 'mapclassify' >= 2.2.0 package is required to use the 'scheme' keyword"
        )
    from mapclassify import __version__ as mc_version

    if mc_version < LooseVersion("2.2.0"):
        raise ImportError(
            "The 'mapclassify' >= 2.2.0 package is required to use the 'scheme' keyword"
        )
    schemes = {}
    for classifier in classifiers.CLASSIFIERS:
        schemes[classifier.lower()] = getattr(classifiers, classifier)

    scheme = scheme.lower()

    # mapclassify < 2.1 cleaned up the scheme names (removing underscores)
    # trying both to keep compatibility with older versions and provide
    # compatibility with newer versions of mapclassify
    oldnew = {
        "Box_Plot": "BoxPlot",
        "Equal_Interval": "EqualInterval",
        "Fisher_Jenks": "FisherJenks",
        "Fisher_Jenks_Sampled": "FisherJenksSampled",
        "HeadTail_Breaks": "HeadTailBreaks",
        "Jenks_Caspall": "JenksCaspall",
        "Jenks_Caspall_Forced": "JenksCaspallForced",
        "Jenks_Caspall_Sampled": "JenksCaspallSampled",
        "Max_P_Plassifier": "MaxP",
        "Maximum_Breaks": "MaximumBreaks",
        "Natural_Breaks": "NaturalBreaks",
        "Std_Mean": "StdMean",
        "User_Defined": "UserDefined",
    }
    scheme_names_mapping = {}
    scheme_names_mapping.update(
        {old.lower(): new.lower() for old, new in oldnew.items()}
    )
    scheme_names_mapping.update(
        {new.lower(): old.lower() for old, new in oldnew.items()}
    )

    try:
        scheme_class = schemes[scheme]
    except KeyError:
        scheme = scheme_names_mapping.get(scheme, scheme)
        try:
            scheme_class = schemes[scheme]
        except KeyError:
            raise ValueError(
                "Invalid scheme. Scheme must be in the set: %r" % schemes.keys()
            )

    if classification_kwds["k"] is not None:
        from inspect import getfullargspec as getspec

        spec = getspec(scheme_class.__init__)
        if "k" not in spec.args:
            del classification_kwds["k"]
    try:
        binning = scheme_class(values, **classification_kwds)
    except TypeError:
        raise TypeError("Invalid keyword argument for %r " % scheme)
    return binning


# Traceback (ValueError)
df = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
df.plot(column='pop_est', scheme='JenksCaspallSampled')

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-18-3fe371919d49> in <module>
----> 1 df.plot(column='pop_est', scheme='JenksCaspallSampled')

~/Dropbox/Python/geopandas/martinfleis/geopandas/geodataframe.py in plot(self, *args, **kwargs)
897         from there.
898         """
--> 899         return plot_dataframe(self, *args, **kwargs)
900
901     plot.__doc__ = plot_dataframe.__doc__

~/Dropbox/Python/geopandas/martinfleis/geopandas/plotting.py in plot_dataframe(df, column, cmap, color, ax, cax, categorical, legend, scheme, k, vmin, vmax, markersize, figsize, legend_kwds, categories, classification_kwds, missing_kwds, aspect, **style_kwds)
672             classification_kwds["k"] = k
673
--> 674         binning = _mapclassify_choro(values[~nan_idx], scheme, **classification_kwds)
675         # set categorical to True for creating the legend
676         categorical = True

~/Dropbox/Python/geopandas/martinfleis/geopandas/plotting.py in _mapclassify_choro(values, scheme, **classification_kwds)
917             del classification_kwds["k"]
918     try:
--> 919         binning = scheme_class(values, **classification_kwds)
920     except TypeError:
921         raise TypeError("Invalid keyword argument for %r " % scheme)

/opt/miniconda3/envs/geo_dev/lib/python3.7/site-packages/mapclassify/classifiers.py in __init__(self, y, k, pct)
2037         self.name = "JenksCaspallSampled"
2038         self.y = y
-> 2039         self._summary()  # have to recalculate summary stats
2040
2041     def _set_bins(self):

/opt/miniconda3/envs/geo_dev/lib/python3.7/site-packages/mapclassify/classifiers.py in _summary(self)
625     def _summary(self):
626         yb = self.yb
--> 627         self.classes = [np.nonzero(yb == c)[0].tolist() for c in range(self.k)]
628         self.tss = self.get_tss()
629         self.adcm = self.get_adcm()

/opt/miniconda3/envs/geo_dev/lib/python3.7/site-packages/mapclassify/classifiers.py in <listcomp>(.0)
625     def _summary(self):
626         yb = self.yb
--> 627         self.classes = [np.nonzero(yb == c)[0].tolist() for c in range(self.k)]
628         self.tss = self.get_tss()
629         self.adcm = self.get_adcm()

<__array_function__ internals> in nonzero(*args, **kwargs)

/opt/miniconda3/envs/geo_dev/lib/python3.7/site-packages/numpy/core/fromnumeric.py in nonzero(a)
1894
1895     """
-> 1896     return _wrapfunc(a, 'nonzero')
1897
1898

/opt/miniconda3/envs/geo_dev/lib/python3.7/site-packages/numpy/core/fromnumeric.py in _wrapfunc(obj, method, *args, **kwds)
56     bound = getattr(obj, method, None)
57     if bound is None:
---> 58         return _wrapit(obj, method, *args, **kwds)
59
60     try:

/opt/miniconda3/envs/geo_dev/lib/python3.7/site-packages/numpy/core/fromnumeric.py in _wrapit(obj, method, *args, **kwds)
49         if not isinstance(result, mu.ndarray):
50             result = asarray(result)
---> 51         result = wrap(result)
52     return result
53

/opt/miniconda3/envs/geo_dev/lib/python3.7/site-packages/pandas/core/generic.py in __array_wrap__(self, result, context)
1916             return result
1917         d = self._construct_axes_dict(self._AXIS_ORDERS, copy=False)
-> 1918         return self._constructor(result, **d).__finalize__(self)
1919
1920     # ideally we would define this to avoid the getattr checks, but

/opt/miniconda3/envs/geo_dev/lib/python3.7/site-packages/pandas/core/series.py in __init__(self, data, index, dtype, name, copy, fastpath)
290                     if len(index) != len(data):
291                         raise ValueError(
--> 292                             f"Length of passed values is {len(data)}, "
293                             f"index implies {len(index)}."
294                         )

ValueError: Length of passed values is 1, index implies 177.

# Fixed code
def _mapclassify_choro(values, scheme, **classification_kwds):
    """
    Wrapper for choropleth schemes from mapclassify for use with plot_dataframe

    Parameters
    ----------
    values
        Series to be plotted
    scheme : str
        One of mapclassify classification schemes
        Options are BoxPlot, EqualInterval, FisherJenks,
        FisherJenksSampled, HeadTailBreaks, JenksCaspall,
        JenksCaspallForced, JenksCaspallSampled, MaxP,
        MaximumBreaks, NaturalBreaks, Quantiles, Percentiles, StdMean,
        UserDefined

    **classification_kwds : dict
        Keyword arguments for classification scheme
        For details see mapclassify documentation:
        https://mapclassify.readthedocs.io/en/latest/api.html

    Returns
    -------
    binning
        Binning objects that holds the Series with values replaced with
        class identifier and the bins.
    """
    try:
        import mapclassify.classifiers as classifiers

    except ImportError:
        raise ImportError(
            "The 'mapclassify' >= 2.2.0 package is required to use the 'scheme' keyword"
        )
    from mapclassify import __version__ as mc_version

    if mc_version < LooseVersion("2.2.0"):
        raise ImportError(
            "The 'mapclassify' >= 2.2.0 package is required to use the 'scheme' keyword"
        )
    schemes = {}
    for classifier in classifiers.CLASSIFIERS:
        schemes[classifier.lower()] = getattr(classifiers, classifier)

    scheme = scheme.lower()

    # mapclassify < 2.1 cleaned up the scheme names (removing underscores)
    # trying both to keep compatibility with older versions and provide
    # compatibility with newer versions of mapclassify
    oldnew = {
        "Box_Plot": "BoxPlot",
        "Equal_Interval": "EqualInterval",
        "Fisher_Jenks": "FisherJenks",
        "Fisher_Jenks_Sampled": "FisherJenksSampled",
        "HeadTail_Breaks": "HeadTailBreaks",
        "Jenks_Caspall": "JenksCaspall",
        "Jenks_Caspall_Forced": "JenksCaspallForced",
        "Jenks_Caspall_Sampled": "JenksCaspallSampled",
        "Max_P_Plassifier": "MaxP",
        "Maximum_Breaks": "MaximumBreaks",
        "Natural_Breaks": "NaturalBreaks",
        "Std_Mean": "StdMean",
        "User_Defined": "UserDefined",
    }
    scheme_names_mapping = {}
    scheme_names_mapping.update(
        {old.lower(): new.lower() for old, new in oldnew.items()}
    )
    scheme_names_mapping.update(
        {new.lower(): old.lower() for old, new in oldnew.items()}
    )

    try:
        scheme_class = schemes[scheme]
    except KeyError:
        scheme = scheme_names_mapping.get(scheme, scheme)
        try:
            scheme_class = schemes[scheme]
        except KeyError:
            raise ValueError(
                "Invalid scheme. Scheme must be in the set: %r" % schemes.keys()
            )

    if classification_kwds["k"] is not None:
        from inspect import getfullargspec as getspec

        spec = getspec(scheme_class.__init__)
        if "k" not in spec.args:
            del classification_kwds["k"]
    try:
        binning = scheme_class(np.asarray(values), **classification_kwds)
    except TypeError:
        raise TypeError("Invalid keyword argument for %r " % scheme)
    return binning