# Buggy code
def __call__(self, series, dtype):
    if dtype is None:
        inferred_dtype = None
        if callable(self._arg):
            # arg is a function, try to inspect the signature
            sig = inspect.signature(self._arg)
            return_type = sig.return_annotation
            if return_type is not inspect._empty:
                inferred_dtype = np.dtype(return_type)
        else:
            if isinstance(self._arg, MutableMapping):
                inferred_dtype = pd.Series(self._arg).dtype
            else:
                inferred_dtype = self._arg.dtype
        if inferred_dtype is not None and np.issubdtype(inferred_dtype, np.number):
            if np.issubdtype(inferred_dtype, np.inexact):
                # for the inexact e.g. float
                # we can make the decision,
                # but for int, due to the nan which may occur,
                # we cannot infer the dtype
                dtype = inferred_dtype
        else:
            dtype = inferred_dtype

    if dtype is None:
        raise ValueError(
            "cannot infer dtype, it needs to be specified manually for `map`"
        )
    else:
        dtype = np.int64 if dtype is int else dtype
        dtype = np.dtype(dtype)

    inputs = [series]
    if isinstance(self._arg, SERIES_TYPE):
        inputs.append(self._arg)
    return self.new_series(
        inputs,
        shape=series.shape,
        dtype=dtype,
        index_value=series.index_value,
        name=series.name,
    )


# 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, series, dtype):
    if dtype is None:
        inferred_dtype = None
        if callable(self._arg):
            # arg is a function, try to inspect the signature
            sig = inspect.signature(self._arg)
            return_type = sig.return_annotation
            if return_type is not inspect._empty:
                inferred_dtype = np.dtype(return_type)
            else:
                try:
                    # try to infer dtype by calling the function
                    inferred_dtype = (
                        build_series(series)
                        .map(self._arg, na_action=self._na_action)
                        .dtype
                    )
                except:  # noqa: E722  # nosec
                    pass
        else:
            if isinstance(self._arg, MutableMapping):
                inferred_dtype = pd.Series(self._arg).dtype
            else:
                inferred_dtype = self._arg.dtype
        if inferred_dtype is not None and np.issubdtype(inferred_dtype, np.number):
            if np.issubdtype(inferred_dtype, np.inexact):
                # for the inexact e.g. float
                # we can make the decision,
                # but for int, due to the nan which may occur,
                # we cannot infer the dtype
                dtype = inferred_dtype
        else:
            dtype = inferred_dtype

    if dtype is None:
        raise ValueError(
            "cannot infer dtype, it needs to be specified manually for `map`"
        )
    else:
        dtype = np.int64 if dtype is int else dtype
        dtype = np.dtype(dtype)

    inputs = [series]
    if isinstance(self._arg, SERIES_TYPE):
        inputs.append(self._arg)
    return self.new_series(
        inputs,
        shape=series.shape,
        dtype=dtype,
        index_value=series.index_value,
        name=series.name,
    )