def gen_mapper_fn(mapper: Union[(Dict, Callable[([Any], Any)])]) -> Tuple[(Callable[([Any], Any)], Dtype, DataType)]:
    if isinstance(mapper, dict):
        mapper_dict = mapper
        type_set = set(map((lambda x: type(x)), mapper_dict.values()))
        if (len(type_set) > 1):
            raise ValueError('Mapper dict should have the same value type.')
        (dtype, spark_return_type) = pandas_on_spark_type(list(type_set)[0])

        def mapper_fn(x: Any) -> Any:
            if (x in mapper_dict):
                return mapper_dict[x]
            else:
                if (errors == 'raise'):
                    raise KeyError('Index include value which is not in the `mapper`')
                return x
    elif callable(mapper):
        mapper_callable = cast(Callable, mapper)
        return_type = cast(ScalarType, infer_return_type(mapper))
        dtype = return_type.dtype
        spark_return_type = return_type.spark_type

        def mapper_fn(x: Any) -> Any:
            return mapper_callable(x)
    else:
        raise ValueError('`mapper` or `index` or `columns` should be either dict-like or function type.')
    return (mapper_fn, dtype, spark_return_type)
def gen_mapper_fn(mapper: Union[(Dict, Callable[([Any], Any)])]) -> Tuple[(Callable[([Any], Any)], Dtype, DataType)]:
    if isinstance(mapper, dict):
        mapper_dict = mapper
        type_set = set(map((lambda x: type(x)), mapper_dict.values()))
        if (len(type_set) > 1):
            raise ValueError('Mapper dict should have the same value type.')
        (dtype, spark_return_type) = pandas_on_spark_type(list(type_set)[0])

        def mapper_fn(x: Any) -> Any:
            if (x in mapper_dict):
                return mapper_dict[x]
            else:
                if (errors == 'raise'):
                    raise KeyError('Index include value which is not in the `mapper`')
                return x
    elif callable(mapper):
        mapper_callable = cast(Callable, mapper)
        return_type = cast(ScalarType, infer_return_type(mapper))
        dtype = return_type.dtype
        spark_return_type = return_type.spark_type

        def mapper_fn(x: Any) -> Any:
            return mapper_callable(x)
    else:
        raise ValueError('`mapper` or `index` or `columns` should be either dict-like or function type.')
    return (mapper_fn, dtype, spark_return_type)