Fix/split at when split_point is not in series #1415
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #1312
Summary
This PR changes the behavior of
TimeSeries._split_at
- and therefore alsosplit_before
andsplit_after
- whensplit_point
is aTimestamp
which is not an index of theTimeSeries
but lies between two indeces.It also adds an appropriate test to the ´TimeSeriesTestCase.test_split` unit test.
Let's say we have a
TimeSeries
indexed by dates2020-01-01
,2020-01-03
and2020-01-05
:Current behavior:
TimeSeries._split_at(2020-01-02, after=True)
produces twoTimeSeries
with indeces[2020-01-01, 2020-01-03]
for the first, and2020-01-05
for the second.TimeSeries._split_at(2020-01-02, after=False)
tries to produce twoTimeSeries
with indeces[ ]
for the first, and[2020-01-01, 2020-01-03, 2020-01-05]
for the second, but errors because the first one is empty.Proposed behavior:
TimeSeries._split_at(2020-01-02)
produces twoTimeSeries
with indeces2020-01-01
for the first, and[2020-01-03, 2020-01-05]
irrespective of whetherafter
isTrue
orFalse
.I believe this is the behavior most people would expect when splitting a
TimeSeries
at a point that lies between two dates.This PR does not change the behavior of
TimeSeries
splits whensplit_point
is not a Timestamp, orsplit_point
is a Timestamp contained in the series.Other Information