Operators of _BaseTsd
It would be convenient to compare to have a binary operators for time series which would can be an easy way to filter the data.
For example, if one has two time series, and what to only select time points where one time series is greater then the other, one could do:
sel = tsd1 > tsd2
tsd_greater = tsd1[sel]
Directly, instead of doing tsd1 > tsd2.values.
An additional benefit is that we can check that the two time series are temporally aligned, making the comparison less bug prone. Users can always circumvent our checks using the old syntax tsd1 > tsd2.values if they know what they are doing, and it won't be a breaking change.
Proposed Implementation
When comparing tsd1 and tsd2:
- If time and time_support (and columns if TsdFrame) are equal return:
- A time series with data object with same time and time_support as the original with values:
operator(tsd1.values, tsd2.values)
- When metadata is present, always drop it (usually the output of the equal operator is used to filter the array so it is unlikely that the metadata will be needed).
- Otherwise:
- Raise
ValueError: the two time series are not comparable because time or columns are misaligned.
Other Considerations
We may relax the strict equality for time and time_support by using np.allclose with the temporal tolerance that pynapple assumes.
Operators of
_BaseTsdIt would be convenient to compare to have a binary operators for time series which would can be an easy way to filter the data.
For example, if one has two time series, and what to only select time points where one time series is greater then the other, one could do:
Directly, instead of doing
tsd1 > tsd2.values.An additional benefit is that we can check that the two time series are temporally aligned, making the comparison less bug prone. Users can always circumvent our checks using the old syntax
tsd1 > tsd2.valuesif they know what they are doing, and it won't be a breaking change.Proposed Implementation
When comparing tsd1 and tsd2:
operator(tsd1.values, tsd2.values)ValueError: the two time series are not comparable because time or columns are misaligned.Other Considerations
We may relax the strict equality for time and time_support by using
np.allclosewith the temporal tolerance that pynapple assumes.