-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
user-selectable rounding strategies for time <-> index conversion? #26
Comments
The docs are pretty clear on this at least for the start index:
So at time 1.5s, the most recent sample taken at that time is index 2. At tiem 2.5s the most recent sample is index 3. I guess then the right-closed definition gives you |
I think the solution might be to convert the final index back to time, and see if it needs to be adjusted down by 1 (e.g., if |
Related to #20. @ericphanson and I discussed this irl, and determined that, similar to #20, this is an example of pre-specified rounding behavior (in Line 215 in eb8b794
Line 237 in eb8b794
We propose that we disallow calling
In this new paradigm, current invocations of
We could then provide a deprecation path to the current |
From further discussion w @ericphanson, @kleinschmidt , one reason that we have to be careful with deprecation paths is that we use this all over the place when indexing into |
After some discussion with @hannahilea and @ericphanson, we concluded that we can handle this behavior with something like the "rounding mode" behavior of Another issue with a default rounding mode is that there isn't a rounding mode that is going to make sense or obey folks' intuitions in all cases. If you use the "intersect with any sample period" rounding mode (my proposal above), you will get spans of different lengths depending on whether you're exactly aligned with span times. If you round to a consistent number of samples, you will sometimes omit final (or initial) samples, so the interpretation of the timespan as an interval fails. Same (on both counts) for rounding up/down/in/out. So it seems worthwhile to tradeoff some convenience (being able to do things like |
💯 Yup, it's all about just picking whatever strategy lines up with your expectations about which invariants/properties you want to preserve. For simplicity's sake, TimeSpans just demands callers to align their expectations with the strategy it happens to implement 😅 not fun for callers who might desire a different interpretation but it is at least self-consistent worth noting #2, in which case usages of I also wonder if more concretely baking the "interpretation choice" into these kinds of structures would also help, e.g. having callers use |
TimeSpans.index_from_time
is correct
I think the retitling doesn't quite capture everything here--- I see it as three issues that came up here: 1. Docs issueThe current implementation of What do I mean this is undocumented? Well,
documents the Line 237 in eb8b794
and we only document the Line 221 in eb8b794
which leaves it unclear exactly what 2. Implementation bugThe implementation of those semantics isn't correct when the right endpoint of the span doesn't fall exactly on a sample; we always throw away the right-endpoint even when it is well within the
would fix that, I think. 3. Suggestion to change the semantics.ref #26 (comment), #26 (comment) To add to those-- I think there's too much magic right now: |
sounds like I've retitled this to issue 3, the other two can be filed separately?
I think I'd need to consider this (or at least review associated PR a bit more deeply), haven't gotten a chance to thoroughly dig into it but i suspect there's a possibility that fixing the perceived bug might change the intended semantics (i.e. break existing tests). maybe not though and it really is just a simple bug that needs fixing |
I think this mischaracterizes what the package is intended to provide...it shouldn't result in the class of bugs one would normally refer to as "magical" - it's not trying to guess a rounding mode for you and then guessing wrong. It's intended to only provide a single implementation that has one particular "rounding mode" baked in. I think this is really the docs issue you brought up, because it seems like people ARE expecting TimeSpans to guess a rounding mode for their use case, which I agree is a bad expectation and is not a feasible thing to try to implement I also agree that providing user-selectable rounding modes is a fine idea, but I'm not sure I want to put further development into TimeSpans.jl when the intention from the inception of the package was supposed to be to deprecate it in favor of Intervals (it was originally split out of Onda at the time to facilitate decoupling the interface). Though maybe the index <-> time conversion parts should live in their own package to compose with Intervals.jl. either way
this is definitely true and should be true for anybody using TimeSpans today as-is, regardless of future changes |
Sounds good, will do.
Hm, the thing I'm calling "too magical" is
To me, it doesn't really matter what package we use; we'll have the same questions about "how to ergonomically grab subsets of
Yes totally, my point is I don't think that's not happening right now to the extent it needs to (and I am definitely as guilty of that as anyone else). |
I think the bug that spawned this issue has been fixed as of #51 julia> TimeSpans.index_from_time(1, TimeSpan(Millisecond(1500), Millisecond(2500)))
2:3 |
Consider a signal with sample rate 1 Hz.
Now, consider the time span 1.5s to 2.5s. Using brackets to highlight this span:
What indicies should be associated to this span?
To me, looks like index 3.
But:
The text was updated successfully, but these errors were encountered: