Unexpected behavior when using crop function
Created by: dethodav
The use of floor division in the Series.crop()
function can result in unexpected behavior due to float precision:
https://github.com/gwpy/gwpy/blob/5a8b781d6e0b398e4fe435a3f818d98ea2e04daf/gwpy/types/series.py#L1019
This generally results in one less sample returned than expected. For example, cropping a series with dx=0.01
with end=1.0
returns one fewer sample if the series x-values extend past 1.0:
>>> from gwpy.types import Series
>>> Series([0]*100, dx=0.01).crop(end=1.).xindex[-1]
<Quantity 0.99>
>>> Series([0]*101, dx=0.01).crop(end=1.).xindex[-1]
<Quantity 0.98>
These errors are due to floating point precision. For example, we don't see the same issue when dx=1
:
>>> Series([0]*100, dx=1).crop(end=100).xindex[-1]
<Quantity 99.>
>>> Series([0]*101, dx=1).crop(end=100).xindex[-1]
<Quantity 99.>