# Buggy code
def get_data(self, df):
    from superset.data import countries

    fd = self.form_data
    cols = [fd.get("entity")]
    metric = utils.get_metric_name(fd.get("metric"))
    secondary_metric = utils.get_metric_name(fd.get("secondary_metric"))
    columns = ["country", "m1", "m2"]
    if metric == secondary_metric:
        ndf = df[cols]
        # df[metric] will be a DataFrame
        # because there are duplicate column names
        ndf["m1"] = df[metric].iloc[:, 0]
        ndf["m2"] = ndf["m1"]
    else:
        if secondary_metric:
            cols += [metric, secondary_metric]
        else:
            cols += [metric]
            columns = ["country", "m1"]
        ndf = df[cols]
    df = ndf
    df.columns = columns
    d = df.to_dict(orient="records")
    for row in d:
        country = None
        if isinstance(row["country"], str):
            country = countries.get(fd.get("country_fieldtype"), row["country"])

        if country:
            row["country"] = country["cca3"]
            row["latitude"] = country["lat"]
            row["longitude"] = country["lng"]
            row["name"] = country["name"]
        else:
            row["country"] = "XXX"
    return d


# Traceback (IndexingError)
Mar 11 11:08:03 analytics-tool1004 superset[27831]: 2019-03-11 11:08:03,985:ERROR:root:Too many indexers
Mar 11 11:08:03 analytics-tool1004 superset[27831]: Traceback (most recent call last):
Mar 11 11:08:03 analytics-tool1004 superset[27831]:   File "/srv/deployment/analytics/superset/venv/lib/python3.7/site-packages/superset/views/base.py", line 96, in wraps
Mar 11 11:08:03 analytics-tool1004 superset[27831]:     return f(self, *args, **kwargs)
Mar 11 11:08:03 analytics-tool1004 superset[27831]:   File "/srv/deployment/analytics/superset/venv/lib/python3.7/site-packages/superset/views/core.py", line 1211, in explore_json
Mar 11 11:08:03 analytics-tool1004 superset[27831]:     samples=samples,
Mar 11 11:08:03 analytics-tool1004 superset[27831]:   File "/srv/deployment/analytics/superset/venv/lib/python3.7/site-packages/superset/views/core.py", line 1142, in generate_json
Mar 11 11:08:03 analytics-tool1004 superset[27831]:     payload = viz_obj.get_payload()
Mar 11 11:08:03 analytics-tool1004 superset[27831]:   File "/srv/deployment/analytics/superset/venv/lib/python3.7/site-packages/superset/viz.py", line 374, in get_payload
Mar 11 11:08:03 analytics-tool1004 superset[27831]:     payload['data'] = self.get_data(df)
Mar 11 11:08:03 analytics-tool1004 superset[27831]:   File "/srv/deployment/analytics/superset/venv/lib/python3.7/site-packages/superset/viz.py", line 1745, in get_data
Mar 11 11:08:03 analytics-tool1004 superset[27831]:     ndf['m1'] = df[metric].iloc[:,0]
Mar 11 11:08:03 analytics-tool1004 superset[27831]:   File "/srv/deployment/analytics/superset/venv/lib/python3.7/site-packages/pandas/core/indexing.py", line 1471, in __getitem__
Mar 11 11:08:03 analytics-tool1004 superset[27831]:     return self._getitem_tuple(key)
Mar 11 11:08:03 analytics-tool1004 superset[27831]:   File "/srv/deployment/analytics/superset/venv/lib/python3.7/site-packages/pandas/core/indexing.py", line 2012, in _getitem_tuple
Mar 11 11:08:03 analytics-tool1004 superset[27831]:     self._has_valid_tuple(tup)
Mar 11 11:08:03 analytics-tool1004 superset[27831]:   File "/srv/deployment/analytics/superset/venv/lib/python3.7/site-packages/pandas/core/indexing.py", line 219, in _has_valid_tuple
Mar 11 11:08:03 analytics-tool1004 superset[27831]:     raise IndexingError('Too many indexers')
Mar 11 11:08:03 analytics-tool1004 superset[27831]: pandas.core.indexing.IndexingError: Too many indexers

# Fixed code
def get_data(self, df):
    from superset.data import countries

    fd = self.form_data
    cols = [fd.get("entity")]
    metric = utils.get_metric_name(fd.get("metric"))
    secondary_metric = utils.get_metric_name(fd.get("secondary_metric"))
    columns = ["country", "m1", "m2"]
    if metric == secondary_metric:
        ndf = df[cols]
        ndf["m1"] = df[metric]
        ndf["m2"] = ndf["m1"]
    else:
        if secondary_metric:
            cols += [metric, secondary_metric]
        else:
            cols += [metric]
            columns = ["country", "m1"]
        ndf = df[cols]
    df = ndf
    df.columns = columns
    d = df.to_dict(orient="records")
    for row in d:
        country = None
        if isinstance(row["country"], str):
            country = countries.get(fd.get("country_fieldtype"), row["country"])

        if country:
            row["country"] = country["cca3"]
            row["latitude"] = country["lat"]
            row["longitude"] = country["lng"]
            row["name"] = country["name"]
        else:
            row["country"] = "XXX"
    return d