Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] signif function crashes with 0 #201

Closed
2 tasks done
fkgruber opened this issue Feb 5, 2024 · 5 comments
Closed
2 tasks done

[BUG] signif function crashes with 0 #201

fkgruber opened this issue Feb 5, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@fkgruber
Copy link

fkgruber commented Feb 5, 2024

datar version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of datar and its backends.

Issue Description

from datar.all import signif
signif(0)

returns:

signif(0)

Traceback (most recent call last):
File "", line 1, in
File "/Users/USER/miniconda3/envs/benchmark/lib/python3.8/site-packages/pipda/function.py", line 447, in wrapper
return func(*args, **kwargs)
File "/Users/USER/miniconda3/envs/benchmark/lib/python3.8/site-packages/datar_numpy/api/arithm.py", line 159, in _signif
return np.vectorize(np.round)(x, digits)
File "/Users/USER/miniconda3/envs/benchmark/lib/python3.8/site-packages/numpy/lib/function_base.py", line 2329, in call
return self._vectorize_call(func=func, args=vargs)
File "/Users/USER/miniconda3/envs/benchmark/lib/python3.8/site-packages/numpy/lib/function_base.py", line 2407, in _vectorize_call
ufunc, otypes = self.get_ufunc_and_otypes(func=func, args=args)
File "/Users/USER/miniconda3/envs/benchmark/lib/python3.8/site-packages/numpy/lib/function_base.py", line 2367, in get_ufunc_and_otypes
outputs = func(*inputs)
File "<array_function internals>", line 200, in round

File "/Users/USER/miniconda3/envs/benchmark/lib/python3.8/site-packages/numpy/core/fromnumeric.py", line 3763, in round

return around(a, decimals=decimals, out=out)
File "<array_function internals>", line 200, in around
File "/Users/USER/miniconda3/envs/benchmark/lib/python3.8/site-packages/numpy/core/fromnumeric.py", line 3337, in around
return _wrapfunc(a, 'round', decimals=decimals, out=out)
File "/Users/USER/miniconda3/envs/benchmark/lib/python3.8/site-packages/numpy/core/fromnumeric.py", line 57, in _wrapfunc
return bound(*args, **kwds)
OverflowError: signed integer is greater than maximum

Expected Behavior

return 0

Installed Versions

datar.get_versions()
python : 3.8.18 (default, Sep 11 2023, 08:17:16)
[Clang 14.0.6 ]
datar : 0.15.4
simplug : 0.3.2
executing : 2.0.1
pipda : 0.13.1
datar-numpy : 0.3.2
numpy : 1.24.3
datar-pandas: 0.5.4
pandas : 2.0.3

@fkgruber fkgruber added the bug Something isn't working label Feb 5, 2024
@pwwang
Copy link
Owner

pwwang commented Feb 5, 2024

Looks like it's more of a problem for python3.8

In [1]: from datar.all import signif

In [2]: from datar import get_versions

In [3]: signif(0)
/path/to/lib/python3.9/site-packages/datar_numpy/api/arithm.py:156: RuntimeWarning: divide by zero encountered in log10
  digits = digits - np.ceil(np.log10(np.abs(x)))
/path/to/lib/python3.9/site-packages/datar_numpy/api/arithm.py:157: RuntimeWarning: invalid value encountered in cast
  digits = np.broadcast_arrays(0, digits.astype(int))
Out[3]: array(0)

In [4]: get_versions()
python      : 3.9.16 | packaged by conda-forge | (main, Feb  1 2023, 21:39:03) 
              [GCC 11.3.0]
datar       : 0.15.4
simplug     : 0.3.2
executing   : 2.0.1
pipda       : 0.13.1
datar-numpy : 0.3.2
numpy       : 1.24.4
datar-pandas: 0.5.4
pandas      : 2.1.1

Still need to eliminate the warnings though.

pwwang added a commit to pwwang/datar-numpy that referenced this issue Feb 5, 2024
@pwwang
Copy link
Owner

pwwang commented Feb 5, 2024

Fixed by datar-numpy v0.3.3

Try pip install -U datar-numpy

@pwwang pwwang closed this as completed Feb 5, 2024
@fkgruber
Copy link
Author

fkgruber commented Feb 5, 2024

this. this update solves that issue with signif

@fkgruber
Copy link
Author

fkgruber commented Feb 8, 2024

Now I have a different problem:

Python 3.8.18 (default, Sep 11 2023, 08:17:16) 
[Clang 14.0.6 ] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import os

>>> import os

import pandas as pd

>>> import numpy as np

from datar.all import tibble, mutate, bind_rows, f, tribble,select,signif,if_else,unite,distinct

>>> >>> >>> df=pd.DataFrame({'A':range(1,11),'B':np.random.randn(10)})
df>>mutate(B=signif(f.B,1))
>>> /Users/fgruber/miniconda3/envs/benchmark/lib/python3.8/site-packages/pipda/utils.py:82: PipeableCallCheckWarning: Failed to detect AST node calling `signif`, assuming a normal call.
  warnings.warn(
/Users/fgruber/miniconda3/envs/benchmark/lib/python3.8/site-packages/pipda/utils.py:89: PipeableCallCheckWarning: Failed to detect AST node calling `mutate`, assuming a piping call.
  warnings.warn(
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/fgruber/miniconda3/envs/benchmark/lib/python3.8/site-packages/pipda/verb.py", line 73, in _pipda_eval
    return func(data, *self._pipda_args, **self._pipda_kwargs)
  File "/Users/fgruber/miniconda3/envs/benchmark/lib/python3.8/site-packages/datar_pandas/api/dplyr/mutate.py", line 62, in _mutate
    val = evaluate_expr(val, data, Context.EVAL)
  File "/Users/fgruber/miniconda3/envs/benchmark/lib/python3.8/site-packages/pipda/utils.py", line 124, in evaluate_expr
    return expr._pipda_eval(data, context)
  File "/Users/fgruber/miniconda3/envs/benchmark/lib/python3.8/site-packages/pipda/function.py", line 108, in _pipda_eval
    return impl(*args, **kwargs)
  File "/Users/fgruber/miniconda3/envs/benchmark/lib/python3.8/site-packages/datar_pandas/factory.py", line 115, in wrapper
    out = func(*args, **kwargs)
  File "/Users/fgruber/miniconda3/envs/benchmark/lib/python3.8/site-packages/datar_pandas/factory.py", line 324, in _pandasobject_apply
    return apply_df(args_frame, bound, exclude, func)
  File "/Users/fgruber/miniconda3/envs/benchmark/lib/python3.8/functools.py", line 875, in wrapper
    return dispatch(args[0].__class__)(*args, **kw)
  File "/Users/fgruber/miniconda3/envs/benchmark/lib/python3.8/site-packages/datar_pandas/factory.py", line 304, in apply_df
    return func(*bound.args, **bound.kwargs)
  File "/Users/fgruber/miniconda3/envs/benchmark/lib/python3.8/site-packages/datar_numpy/api/arithm.py", line 156, in _signif
    if x == 0:
  File "/Users/fgruber/miniconda3/envs/benchmark/lib/python3.8/site-packages/pandas/core/generic.py", line 1466, in __nonzero__
    raise ValueError(
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
>>> 

@pwwang pwwang reopened this Feb 8, 2024
@pwwang
Copy link
Owner

pwwang commented Feb 8, 2024

Fixed by datar-numpy v0.3.4

Try pip install -U datar-numpy

@pwwang pwwang closed this as completed Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants