shbhuk / barycorrpy

Python version of Barycorr
GNU General Public License v3.0
37 stars 6 forks source link

int object is not callable error for python == 3.8.5 #36

Closed gmbrandt closed 3 years ago

gmbrandt commented 3 years ago

using get_BC_vel in python 3.8 with up to date packages (e.g. astropy etc.) raises a int object is not callable error. The stack trace follows

~/envs/nres/lib/python3.8/site-packages/barycorrpy/barycorrpy.py in get_BC_vel(JDUTC, starname, hip_id, ra, dec, epoch, pmra, pmdec, px, rv, obsname, lat, longi, alt, zmeas, ephemeris, leap_dir, leap_update, predictive, SolSystemTarget, HorizonsID_type)
    215         vel = []
    216 
--> 217         for jdutc,zm in zip(JDUTC,np.repeat(zmeas,np.size(JDUTC)/np.size(zmeas))):
    218             a = BCPy(JDUTC=jdutc,
    219                      zmeas=zm,

<__array_function__ internals> in size(*args, **kwargs)

~/envs/nres/lib/python3.8/site-packages/astropy/utils/shapes.py in __array_function__(self, function, types, args, kwargs)
    245             method = getattr(self, name, None)
    246             if method is not None:
--> 247                 return method(*args[1:], **kwargs)
    248 
    249         # Fall-back, just pass the arguments on since perhaps the function

TypeError: 'int' object is not callable

Minimal working example to reproduce the above issue (package versions follow at the end of this issue)

from astropy.time import Time
from barycorrpy import get_BC_vel
import numpy as np

mid_obstime = Time(1991, format='decimalyear')

bc_vel, warnings, status = get_BC_vel(JDUTC=Time(np.array([mid_obstime.jd]), format='jd'), 
                                      obsname='Cerro Tololo',
                                      ra=215.8146, dec=1.2394,
                                      epoch=Time(2016, format='decimalyear').jd,
                                      pmra=223.5314, pmdec=-478.2748, px=57.27057,
                                      ephemeris='de430',
                                      leap_update=False, rv=1000)

Calling the above in e.g. Ipython will cause the aforementioned error. This seems like an issue with np.size() crashing on a length 1 astropy.time.Time object.One gets the same error with JDUTC=mid_obstime, i.e. using the actual Time value results in the same error.

This was not an issue in python 3.5

My environment to reproduce the error: python == 3.8.5 astropy==4.2 numpy==1.20.0 (also fails with numpy==1.19.5)

shbhuk commented 3 years ago

Hi @gmbrandt , thank you for pointing this out, the traceback and the MWE. I'll try to reproduce it, and get back to you!

shbhuk commented 3 years ago

Hi @gmbrandt,

I'm unable to replicate the error using your MWE with my current environment, here are my versions - python == 3.8.1 numpy == 1.19.4 barycorrpy == 0.3.4 astropy == 4.1

I'll update them and check.

shbhuk commented 3 years ago

I do reproduce the error using numpy==1.20.0 and astropy==4.2. Closing it with #37

Thanks!