circstat / pycircstat

Toolbox for circular statistics with Python
MIT License
157 stars 42 forks source link

ValueError in descriptive.py/moment #80

Open mk-mccann opened 2 years ago

mk-mccann commented 2 years ago

When running the moment function, I get a ValueError: Function moment does not have variable ci. Giving a confidence interval doesn't change the output.

The issue seems to be related to the bootstrapping wrapper; full error is below:

~\AppData\Local\Temp/ipykernel_26892/2463399625.py in <module>
      1 data = 2*np.pi*np.random.rand(10)
----> 2 mp = circ.moment(data)

~\Miniconda3\envs\prey_capture\lib\site-packages\decorator.py in fun(*args, **kw)
    230             if not kwsyntax:
    231                 args, kw = fix(args, kw, sig)
--> 232             return caller(func, *(extras + args), **kw)
    233     fun.__name__ = func.__name__
    234     fun.__doc__ = func.__doc__

~\Miniconda3\envs\prey_capture\lib\site-packages\pycircstat-0.0.2-py3.8.egg\pycircstat\descriptive.py in wrapper(f, *args, **kwargs)
     64         def wrapper(f, *args, **kwargs):
     65             args = list(args)
---> 66             ci = self._get_var(f, 'ci', None, args, kwargs, remove=True)
     67             bootstrap_iter = self._get_var(f, 'bootstrap_iter', None,
     68                                            args, kwargs, remove=True)

~\Miniconda3\envs\prey_capture\lib\site-packages\pycircstat-0.0.2-py3.8.egg\pycircstat\descriptive.py in _get_var(self, f, what, default, args, kwargs, remove)
     40             what_idx = varnames.index(what)
     41         else:
---> 42             raise ValueError('Function %s does not have variable %s.' %
     43                              (f.__name__, what))
     44 

ValueError: Function moment does not have variable ci.
mk-mccann commented 2 years ago

After a bit of digging, this seems to be related to getting function argument names in Python 3 (in the bootstrap class - descriptive.py, line 18). The method func.__code__.co_varnames is depreciated in Python 3.

I found a solution here using the inspect library: inspect.getfullargspec(func).args yields a list of input arguments.