StingraySoftware / stingray

Anything can happen in the next half hour (including spectral timing made easy)!
https://stingray.science/stingray
MIT License
172 stars 141 forks source link

Add is_sorted utility, and use it. #723

Closed matteobachetti closed 1 year ago

matteobachetti commented 1 year ago

I realized that the code for periodograms was not robust when events were not sorted, so I forced it. I wrote a new is_sorted function, that goes through the array and gives False at the first instance of a non-sorted list (super fast in random arrays, O(n) in quasi-sorted arrays), but it is only fast if numba-compiled. I also used the standard (np.diff(array) >=0).all() implementation if Numba is not installed. I took the chance to use the new function in a number of places where we used different checks of the same kind, and to fix the test data (that were unsorted themselves).

codecov[bot] commented 1 year ago

Codecov Report

Merging #723 (b7d4c94) into main (5f13650) will decrease coverage by 0.06%. The diff coverage is 83.33%.

@@            Coverage Diff             @@
##             main     #723      +/-   ##
==========================================
- Coverage   97.22%   97.16%   -0.06%     
==========================================
  Files          42       42              
  Lines        7848     7869      +21     
==========================================
+ Hits         7630     7646      +16     
- Misses        218      223       +5     
Impacted Files Coverage Δ
stingray/utils.py 98.29% <78.94%> (-0.73%) :arrow_down:
stingray/io.py 98.49% <87.50%> (-0.30%) :arrow_down:
stingray/gti.py 99.27% <100.00%> (+<0.01%) :arrow_up:
stingray/lightcurve.py 97.83% <100.00%> (-0.01%) :arrow_down:

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more

dhuppenkothen commented 1 year ago

Codecov seems to be complaining?

matteobachetti commented 1 year ago

@dhuppenkothen there is just one line not tested, the one about detector_id which should be trivial ( and needs to change the data files). The numba function is executed (I'm sure of it, because the line that calls that function is executed) but codecov is probably not able to go inside it.