# Buggy code
def __call__(self, a, bins, range, weights):
    if range is not None:
        _check_range(range)
    if isinstance(bins, str):
        # string, 'auto', 'stone', ...
        # shape is unknown
        bin_name = bins
        # if `bins` is a string for an automatic method,
        # this will replace it with the number of bins calculated
        if bin_name not in _hist_bin_selectors:
            raise ValueError(f"{bin_name!r} is not a valid estimator for `bins`")
        if weights is not None:
            raise TypeError(
                "Automated estimation of the number of "
                "bins is not supported for weighted data"
            )
        if isinstance(range, tuple) and len(range) == 2:
            # if `bins` is a string, e.g. 'auto', 'stone'...,
            # and `range` provided as well,
            # `a` should be trimmed first
            first_edge, last_edge = _get_outer_edges(a, range)
            a = a[(a >= first_edge) & (a <= last_edge)]
        shape = (np.nan,)
    elif mt.ndim(bins) == 0:
        try:
            n_equal_bins = operator.index(bins)
        except TypeError:  # pragma: no cover
            raise TypeError("`bins` must be an integer, a string, or an array")
        if n_equal_bins < 1:
            raise ValueError("`bins` must be positive, when an integer")
        shape = (bins + 1,)
    elif mt.ndim(bins) == 1:
        if not isinstance(bins, TENSOR_TYPE):
            bins = np.asarray(bins)
            if not is_asc_sorted(bins):
                raise ValueError("`bins` must increase monotonically, when an array")
        shape = astensor(bins).shape
    else:
        raise ValueError("`bins` must be 1d, when an array")

    inputs = [a]
    if isinstance(bins, TENSOR_TYPE):
        inputs.append(bins)
    if weights is not None:
        inputs.append(weights)
    if a.size > 0 and (isinstance(bins, str) or mt.ndim(bins) == 0) and not range:
        # for bins that is str or integer,
        # requires min max calculated first
        input_min = self._input_min = a.min()
        inputs.append(input_min)
        input_max = self._input_max = a.max()
        inputs.append(input_max)

    return self.new_tensor(inputs, shape=shape, order=TensorOrder.C_ORDER)


# Traceback (ValueError)
Traceback (most recent call last):
File "/home/smartguo/lib/anaconda3/envs/mars/lib/python3.7/site-packages/pandas/core/dtypes/common.py", line 171, in ensure_python_int
new_value = int(value)
ValueError: cannot convert float NaN to integer

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "tensor_loop.py", line 14, in <module>
df_res = md.DataFrame(score, columns=["probability"])
File "/home/smartguo/lib/anaconda3/envs/mars/lib/python3.7/site-packages/mars/dataframe/initializer.py", line 47, in __init__
df = dataframe_from_tensor(data, index=index, columns=columns, gpu=gpu, sparse=sparse)
File "/home/smartguo/lib/anaconda3/envs/mars/lib/python3.7/site-packages/mars/dataframe/datasource/from_tensor.py", line 357, in dataframe_from_tensor
return op(tensor, index, columns)
File "/home/smartguo/lib/anaconda3/envs/mars/lib/python3.7/site-packages/mars/utils.py", line 451, in _inner
return func(*args, **kwargs)
File "/home/smartguo/lib/anaconda3/envs/mars/lib/python3.7/site-packages/mars/dataframe/datasource/from_tensor.py", line 83, in __call__
return self._call_input_tensor(input_tensor, index, columns)
File "/home/smartguo/lib/anaconda3/envs/mars/lib/python3.7/site-packages/mars/dataframe/datasource/from_tensor.py", line 156, in _call_input_tensor
index_value = parse_index(pd.RangeIndex(start=0, stop=input_tensor.shape[0]))
File "/home/smartguo/lib/anaconda3/envs/mars/lib/python3.7/site-packages/pandas/core/indexes/range.py", line 107, in __new__
stop = ensure_python_int(stop)
File "/home/smartguo/lib/anaconda3/envs/mars/lib/python3.7/site-packages/pandas/core/dtypes/common.py", line 174, in ensure_python_int
raise TypeError(f"Wrong type {type(value)} for value {value}") from err
TypeError: Wrong type <class 'float'> for value nan

# Fixed code
def __call__(self, a, bins, range, weights):
    if range is not None:
        _check_range(range)
    if isinstance(bins, str):
        # string, 'auto', 'stone', ...
        # shape is unknown
        bin_name = bins
        # if `bins` is a string for an automatic method,
        # this will replace it with the number of bins calculated
        if bin_name not in _hist_bin_selectors:
            raise ValueError(f"{bin_name!r} is not a valid estimator for `bins`")
        if weights is not None:
            raise TypeError(
                "Automated estimation of the number of "
                "bins is not supported for weighted data"
            )
        if isinstance(range, tuple) and len(range) == 2:
            # if `bins` is a string, e.g. 'auto', 'stone'...,
            # and `range` provided as well,
            # `a` should be trimmed first
            first_edge, last_edge = _get_outer_edges(a, range)
            a = a[(a >= first_edge) & (a <= last_edge)]
        shape = (np.nan,)
    elif mt.ndim(bins) == 0:
        try:
            n_equal_bins = operator.index(bins)
        except TypeError:  # pragma: no cover
            raise TypeError("`bins` must be an integer, a string, or an array")
        if n_equal_bins < 1:
            raise ValueError("`bins` must be positive, when an integer")
        shape = (bins + 1,)
    elif mt.ndim(bins) == 1:
        if not isinstance(bins, TENSOR_TYPE):
            bins = np.asarray(bins)
            if not is_asc_sorted(bins):
                raise ValueError("`bins` must increase monotonically, when an array")
        shape = astensor(bins).shape
    else:
        raise ValueError("`bins` must be 1d, when an array")

    inputs = [a]
    if isinstance(bins, TENSOR_TYPE):
        inputs.append(bins)
    if weights is not None:
        inputs.append(weights)
    if (
        (a.size > 0 or np.isnan(a.size))
        and (isinstance(bins, str) or mt.ndim(bins) == 0)
        and not range
    ):
        # for bins that is str or integer,
        # requires min max calculated first
        input_min = self._input_min = a.min()
        inputs.append(input_min)
        input_max = self._input_max = a.max()
        inputs.append(input_max)

    return self.new_tensor(inputs, shape=shape, order=TensorOrder.C_ORDER)