hetio / hetmatpy

Python package for matrix storage and operations on hetnets
Other
14 stars 9 forks source link

Fix division error #17

Closed dhimmel closed 2 years ago

dhimmel commented 2 years ago

Got this error on CI:

____________________________ test_add_gamma_hurdle _____________________________

    def test_add_gamma_hurdle():
        df_dict = {
            'nnz': [1, 3, 3],
            'sum': [4.0, 4.0, 3.0],
            'sum_of_squares': [4.0, 6.0, 3.0 + 1e-15],
        }
        dgp_df = pandas.DataFrame(df_dict)
>       dgp_df = add_gamma_hurdle_to_dgp_df(dgp_df)

hetmatpy/tests/test_pipeline.py:174: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/opt/hostedtoolcache/Python/3.6.15/x64/lib/python3.6/site-packages/hetmatpy/pipeline.py:60: in add_gamma_hurdle_to_dgp_df
    dgp_df['beta'] = (dgp_df['mean_nz'] / dgp_df['sd_nz'] ** 2).replace(numpy.inf, numpy.nan)
/opt/hostedtoolcache/Python/3.6.15/x64/lib/python3.6/site-packages/pandas/core/ops/common.py:65: in new_method
    return method(self, other)
/opt/hostedtoolcache/Python/3.6.15/x64/lib/python3.6/site-packages/pandas/core/ops/__init__.py:343: in wrapper
    result = arithmetic_op(lvalues, rvalues, op)
/opt/hostedtoolcache/Python/3.6.15/x64/lib/python3.6/site-packages/pandas/core/ops/array_ops.py:190: in arithmetic_op
    res_values = na_arithmetic_op(lvalues, rvalues, op)
/opt/hostedtoolcache/Python/3.6.15/x64/lib/python3.6/site-packages/pandas/core/ops/array_ops.py:143: in na_arithmetic_op
    result = expressions.evaluate(op, left, right)
/opt/hostedtoolcache/Python/3.6.15/x64/lib/python3.6/site-packages/pandas/core/computation/expressions.py:2[33](https://github.com/hetio/hetmatpy/runs/5833262318?check_suite_focus=true#step:5:33): in evaluate
    return _evaluate(op, op_str, a, b)  # type: ignore
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

op = <built-in function truediv>, op_str = '/'
a = array([4.        , 1.33333333, 1.        ])
b = array([nan, 0.33333333333333[34](https://github.com/hetio/hetmatpy/runs/5833262318?check_suite_focus=true#step:5:34), 0.0], dtype=object)

    def _evaluate_standard(op, op_str, a, b):
        """
        Standard evaluation.
        """
        if _TEST_MODE:
            _store_test_result(False)
        with np.errstate(all="ignore"):
>           return op(a, b)
E           ZeroDivisionError: float division by zero

Looks like something has changed in how division by zero is being handled. Noting https://github.com/pandas-dev/pandas/issues/46292.