# Buggy code
def execute(cls, ctx, op: "DataFrameValueCounts"):
    if op.stage != OperandStage.map:
        in_data = ctx[op.input.key]
        if op.convert_index_to_interval:
            result = in_data.value_counts(
                normalize=False,
                sort=op.sort,
                ascending=op.ascending,
                bins=op.bins,
                dropna=op.dropna,
            )
            if op.normalize:
                result /= in_data.shape[0]
        else:
            try:
                result = in_data.value_counts(
                    normalize=op.normalize,
                    sort=op.sort,
                    ascending=op.ascending,
                    bins=op.bins,
                    dropna=op.dropna,
                )
            except ValueError:
                in_data = in_data.copy()
                result = in_data.value_counts(
                    normalize=op.normalize,
                    sort=op.sort,
                    ascending=op.ascending,
                    bins=op.bins,
                    dropna=op.dropna,
                )
    else:
        result = ctx[op.input.key]
    if op.convert_index_to_interval:
        # convert CategoricalDtype which generated in `cut`
        # to IntervalDtype
        result.index = result.index.astype("interval")
    ctx[op.outputs[0].key] = result


# 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 execute(cls, ctx, op: "DataFrameValueCounts"):
    if op.stage != OperandStage.map:
        in_data = ctx[op.input.key]
        if op.convert_index_to_interval:
            result = in_data.value_counts(
                normalize=False,
                sort=op.sort,
                ascending=op.ascending,
                bins=op.bins,
                dropna=op.dropna,
            )
            if op.normalize:
                result /= in_data.shape[0]
        else:
            try:
                result = in_data.value_counts(
                    normalize=op.normalize,
                    sort=op.sort,
                    ascending=op.ascending,
                    bins=op.bins,
                    dropna=op.dropna,
                )
            except ValueError:
                in_data = in_data.copy()
                result = in_data.value_counts(
                    normalize=op.normalize,
                    sort=op.sort,
                    ascending=op.ascending,
                    bins=op.bins,
                    dropna=op.dropna,
                )
    else:
        result = ctx[op.input.key]
        # set index name to None to keep consistency with pandas
        result.index.name = None
    if op.convert_index_to_interval:
        # convert CategoricalDtype which generated in `cut`
        # to IntervalDtype
        result.index = result.index.astype("interval")
    ctx[op.outputs[0].key] = result