# Buggy code
def build_df(df_obj, fill_value=1, size=1):
    empty_df = build_empty_df(df_obj.dtypes, index=df_obj.index_value.to_pandas()[:0])
    dtypes = empty_df.dtypes
    record = [_generate_value(dtype, fill_value) for dtype in empty_df.dtypes]
    if isinstance(empty_df.index, pd.MultiIndex):
        index = tuple(
            _generate_value(level.dtype, fill_value) for level in empty_df.index.levels
        )
        empty_df.loc[index,] = record
    else:
        index = _generate_value(empty_df.index.dtype, fill_value)
        empty_df.loc[index] = record

    empty_df = pd.concat([empty_df] * size)
    # make sure dtypes correct for MultiIndex
    empty_df = empty_df.astype(dtypes, copy=False)
    return empty_df


# Traceback (KeyError)
KeyError
Traceback (most recent call last)
<ipython-input-73-3d10a0dadb7d> in <module>
5 data = pd.merge(data,data.groupby(['c']).size().reset_index(),on = ['c'],how='left')
6 data = pd.merge(data,data.groupby(['d']).size().reset_index(),on = ['d'],how='left')
----> 7 data = pd.merge(data,data.groupby(['e']).size().reset_index(),on = ['3'],how='left')
8 print(data.columns.execute())

D:\kinggsoft\anaconda\lib\site-packages\mars\dataframe\merge\merge.py in merge(df, right, how, on, left_on, right_on, left_index, right_index, sort, suffixes, copy, indicator, strategy, validate)
357         left_index=left_index, right_index=right_index, sort=sort, suffixes=suffixes,
358         copy=copy, indicator=indicator, validate=validate, object_type=ObjectType.dataframe)
--> 359     return op(df, right)
360
361

D:\kinggsoft\anaconda\lib\site-packages\mars\dataframe\merge\merge.py in __call__(self, left, right)
175
176     def __call__(self, left, right):
--> 177         empty_left, empty_right = build_df(left), build_df(right)
178         # this `merge` will check whether the combination of those arguments is valid
179         merged = empty_left.merge(empty_right, how=self.how, on=self.on,

D:\kinggsoft\anaconda\lib\site-packages\mars\dataframe\utils.py in build_df(df_obj, fill_value, size)
442     empty_df = pd.concat([empty_df] * size)
443     # make sure dtypes correct for MultiIndex
--> 444     empty_df = empty_df.astype(dtypes, copy=False)
445     return empty_df
446

D:\kinggsoft\anaconda\lib\site-packages\pandas\core\generic.py in astype(self, dtype, copy, errors, **kwargs)
5863                     results.append(
5864                         col.astype(
-> 5865                             dtype=dtype[col_name], copy=copy, errors=errors, **kwargs
5866                         )
5867                     )

D:\kinggsoft\anaconda\lib\site-packages\pandas\core\generic.py in astype(self, dtype, copy, errors, **kwargs)
5846                 if len(dtype) > 1 or self.name not in dtype:
5847                     raise KeyError(
-> 5848                         "Only the Series name can be used for "
5849                         "the key in Series dtype mappings."
5850                     )

KeyError: 'Only the Series name can be used for the key in Series dtype mappings.'

# Fixed code
def build_df(df_obj, fill_value=1, size=1):
    empty_df = build_empty_df(df_obj.dtypes, index=df_obj.index_value.to_pandas()[:0])
    dtypes = empty_df.dtypes
    record = [_generate_value(dtype, fill_value) for dtype in empty_df.dtypes]
    if isinstance(empty_df.index, pd.MultiIndex):
        index = tuple(
            _generate_value(level.dtype, fill_value) for level in empty_df.index.levels
        )
        empty_df.loc[index,] = record
    else:
        index = _generate_value(empty_df.index.dtype, fill_value)
        empty_df.loc[index] = record

    empty_df = pd.concat([empty_df] * size)
    # make sure dtypes correct for MultiIndex
    for i, dtype in enumerate(dtypes.tolist()):
        s = empty_df.iloc[:, i]
        if s.dtype != dtype:
            empty_df.iloc[:, i] = s.astype(dtype)
    return empty_df