hippke / tls

Transit Least Squares: An optimized transit-fitting algorithm to search for periodic transits of small planets
MIT License
48 stars 24 forks source link

Bug: calls numpy.int which is deprecated since numpy version 1.20 #111

Closed saigrain closed 5 months ago

saigrain commented 5 months ago
AttributeError                            Traceback (most recent call last)
Cell In[9], line 6
      4 l = (t >= TMIN) * (t < TMAX) * np.isfinite(f_flat)
      5 model = transitleastsquares(t[l], f_flat[l])
----> 6 results = model.power()

File ~/miniforge3/lib/python3.10/site-packages/transitleastsquares/main.py:269, in transitleastsquares.power(self, **kwargs)
    267     before_transit_count = numpy.nan
    268 else:
--> 269     SR, power_raw, power, SDE_raw, SDE = spectra(chi2, self.oversampling_factor)
    270     index_highest_power = numpy.argmax(power)
    271     period = test_statistic_periods[index_highest_power]

File ~/miniforge3/lib/python3.10/site-packages/transitleastsquares/stats.py:119, in spectra(chi2, oversampling_factor)
    117     kernel = kernel + 1
    118 if len(power_raw) > 2 * kernel:
--> 119     my_median = running_median(power_raw, kernel)
    120     power = power_raw - my_median
    121     # Re-normalize to range between median = 0 and peak = SDE
    122     # shift down to the mean being zero

File ~/miniforge3/lib/python3.10/site-packages/transitleastsquares/helpers.py:96, in running_median(data, kernel)
     94 """Returns sliding median of width 'kernel' and same length as data """
     95 idx = numpy.arange(kernel) + numpy.arange(len(data) - kernel + 1)[:, None]
---> 96 idx = idx.astype(numpy.int)  # needed if oversampling_factor is not int
     97 med = numpy.median(data[idx], axis=1)
     99 # Append the first/last value at the beginning/end to match the length of
    100 # data and returned median

File ~/miniforge3/lib/python3.10/site-packages/numpy/__init__.py:324, in __getattr__(attr)
    319     warnings.warn(
    320         f"In the future `np.{attr}` will be defined as the "
    321         "corresponding NumPy scalar.", FutureWarning, stacklevel=2)
    323 if attr in __former_attrs__:
--> 324     raise AttributeError(__former_attrs__[attr])
    326 if attr == 'testing':
    327     import numpy.testing as testing

AttributeError: module 'numpy' has no attribute 'int'.
`np.int` was a deprecated alias for the builtin `int`. To avoid this error in existing code, use `int` by itself. Doing this will not modify any behavior and is safe. When replacing `np.int`, you may wish to use e.g. `np.int64` or `np.int32` to specify the precision. If you wish to review your current use, check the release note link for additional information.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
    https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
hippke commented 5 months ago

Thanks for pointing this out! In the repository it was fixed for quite some time but I had missed to also push the new version to PyPI. Now, you can upgrade with pip install transitleastsquares --upgrade to version 1.32 and the error should be gone.

saigrain commented 5 months ago

Thanks! I can confirm I have upgraded the package via pip and it works now.