# Buggy code
def __call__(self, df):
    if self.col_names is not None:
        # if col_names is a list, return a DataFrame, else return a Series
        if isinstance(self._col_names, list):
            dtypes = df.dtypes[self._col_names]
            columns = parse_index(pd.Index(self._col_names), store_data=True)
            return self.new_dataframe(
                [df],
                shape=(df.shape[0], len(self._col_names)),
                dtypes=dtypes,
                index_value=df.index_value,
                columns_value=columns,
            )
        else:
            dtype = df.dtypes[self._col_names]
            return self.new_series(
                [df],
                shape=(df.shape[0],),
                dtype=dtype,
                index_value=df.index_value,
                name=self._col_names,
            )
    else:
        if isinstance(self.mask, (SERIES_TYPE, DATAFRAME_TYPE)):
            index_value = parse_index(
                pd.Index([], dtype=df.index_value.to_pandas().dtype), df, self._mask
            )
            return self.new_dataframe(
                [df, self._mask],
                shape=(np.nan, df.shape[1]),
                dtypes=df.dtypes,
                index_value=index_value,
                columns_value=df.columns_value,
            )
        else:
            index_value = parse_index(
                pd.Index([], dtype=df.index_value.to_pandas().dtype), df, self._mask
            )
            return self.new_dataframe(
                [df],
                shape=(np.nan, df.shape[1]),
                dtypes=df.dtypes,
                index_value=index_value,
                columns_value=df.columns_value,
            )


# Traceback (ValueError)
In [4]: import mars.dataframe as md

In [5]: md.Series(['1-1', '2-2']).map(lambda x: x.split('-')[0]).execute()
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-5-90507c117e4f> in <module>
----> 1 md.Series(['1-1', '2-2']).map(lambda x: x.split('-')[0]).execute()

~/Workspace/mars/mars/dataframe/base/map.py in map_(series, arg, na_action, dtype)
155 def map_(series, arg, na_action=None, dtype=None):
156     op = DataFrameMap(arg=arg, na_action=na_action)
--> 157     return op(series, dtype=dtype)

~/Workspace/mars/mars/utils.py in _inner(*args, **kwargs)
449         def _inner(*args, **kwargs):
450             with self:
--> 451                 return func(*args, **kwargs)
452
453         return _inner

~/Workspace/mars/mars/dataframe/base/map.py in __call__(self, series, dtype)
93
94         if dtype is None:
---> 95             raise ValueError('cannot infer dtype, '
96                              'it needs to be specified manually for `map`')
97         else:

ValueError: cannot infer dtype, it needs to be specified manually for `map`

# Fixed code
def __call__(self, df):
    if self.col_names is not None:
        # if col_names is a list, return a DataFrame, else return a Series
        if isinstance(self._col_names, list):
            dtypes = df.dtypes[self._col_names]
            columns = parse_index(pd.Index(self._col_names), store_data=True)
            return self.new_dataframe(
                [df],
                shape=(df.shape[0], len(self._col_names)),
                dtypes=dtypes,
                index_value=df.index_value,
                columns_value=columns,
            )
        else:
            dtype = df.dtypes[self._col_names]
            return self.new_series(
                [df],
                shape=(df.shape[0],),
                dtype=dtype,
                index_value=df.index_value,
                name=self._col_names,
            )
    else:
        if isinstance(self.mask, (SERIES_TYPE, DATAFRAME_TYPE)):
            index_value = parse_index(
                pd.Index(
                    [], dtype=df.index_value.to_pandas().dtype, name=df.index_value.name
                ),
                df,
                self._mask,
            )
            return self.new_dataframe(
                [df, self._mask],
                shape=(np.nan, df.shape[1]),
                dtypes=df.dtypes,
                index_value=index_value,
                columns_value=df.columns_value,
            )
        else:
            index_value = parse_index(
                pd.Index(
                    [], dtype=df.index_value.to_pandas().dtype, name=df.index_value.name
                ),
                df,
                self._mask,
            )
            return self.new_dataframe(
                [df],
                shape=(np.nan, df.shape[1]),
                dtypes=df.dtypes,
                index_value=index_value,
                columns_value=df.columns_value,
            )