Repository: unit8co/darts

Issue:
[BUG] Unexpected split_before/split_after result when split_point is between two time indices
**Describe the bug**
If `TimeSeries.split_after` is performed using a timepoint which is located between two time-indices of the `TimeSeries` as `split_point` parameter, `split_after` splits the `TimeSeries` after the next date after the split_point. 

For example:
Let's say I have a `TimeSeries` with the following timepoints as indices:
`[2020-01-01, 2020-01-03, 2020-01-05]`
Using `split_after` with `2020-01-02`  as `split_point` I would expect the following split:
`[2020-01-01], [2020-01-03, 2020-01-05]`
However the actual split is the following:
`[2020-01-01, 2020-01-03], [2020-01-05]`
This is unexpected, as a date that is after `split_point` is allocated to the first result.

The analogous problem happens with `split_before`.

**To Reproduce**
```python
import pandas as pd
import numpy as np
from darts import TimeSeries

dates = pd.date_range(pd.Timestamp(2020,1,1), pd.Timestamp(2020,1,6), freq='2D')
vals = np.random.rand(3)
ts = TimeSeries.from_times_and_values(dates, vals)

before, after = ts.split_after(pd.Timestamp(2020,1,2))
print(before.time_index)

# prints: DatetimeIndex(['2020-01-01', '2020-01-03'], dtype='datetime64[ns]', name='time', freq='2D')
```

**Expected behavior**
After using `split_after`, all timepoints in the 1st result should be `<= split_point`, regardless of whether `split_point` is contained as index in the series or inbetween two indices.

**System (please complete the following information):**
 - Python version: 3.10
 - darts version: 0.21.0


Discussion:
codecov-commenter: # [Codecov](https://codecov.io/gh/unit8co/darts/pull/1415?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=unit8co) Report
Base: **93.97**% // Head: **93.97**% // Increases project coverage by **`+0.00%`** :tada:
> Coverage data is based on head [(`3855e9c`)](https://codecov.io/gh/unit8co/darts/pull/1415?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=unit8co) compared to base [(`e9f850d`)](https://codecov.io/gh/unit8co/darts/commit/e9f850dcda5d4a5ac48e491eea2914c1a0d20d7d?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=unit8co).
> Patch coverage: 100.00% of modified lines in pull request are covered.

<details><summary>Additional details and impacted files</summary>


```diff
@@           Coverage Diff           @@
##           master    #1415   +/-   ##
=======================================
  Coverage   93.97%   93.97%           
=======================================
  Files          82       82           
  Lines        8915     8903   -12     
=======================================
- Hits         8378     8367   -11     
+ Misses        537      536    -1     
```


| [Impacted Files](https://codecov.io/gh/unit8co/darts/pull/1415?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=unit8co) | Coverage Δ | |
|---|---|---|
| [darts/timeseries.py](https://codecov.io/gh/unit8co/darts/pull/1415/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=unit8co#diff-ZGFydHMvdGltZXNlcmllcy5weQ==) | `92.03% <100.00%> (+0.03%)` | :arrow_up: |
| [...arts/models/forecasting/torch\_forecasting\_model.py](https://codecov.io/gh/unit8co/darts/pull/1415/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=unit8co#diff-ZGFydHMvbW9kZWxzL2ZvcmVjYXN0aW5nL3RvcmNoX2ZvcmVjYXN0aW5nX21vZGVsLnB5) | `87.68% <0.00%> (-0.06%)` | :arrow_down: |
| [darts/models/forecasting/block\_rnn\_model.py](https://codecov.io/gh/unit8co/darts/pull/1415/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=unit8co#diff-ZGFydHMvbW9kZWxzL2ZvcmVjYXN0aW5nL2Jsb2NrX3Jubl9tb2RlbC5weQ==) | `98.24% <0.00%> (-0.04%)` | :arrow_down: |
| [darts/models/forecasting/nhits.py](https://codecov.io/gh/unit8co/darts/pull/1415/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=unit8co#diff-ZGFydHMvbW9kZWxzL2ZvcmVjYXN0aW5nL25oaXRzLnB5) | `99.27% <0.00%> (-0.01%)` | :arrow_down: |

Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=unit8co). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=unit8co)

</details>

[:umbrella: View full report at Codecov](https://codecov.io/gh/unit8co/darts/pull/1415?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=unit8co).   
:loudspeaker: Do you have feedback about the report comment? [Let us know in this issue](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=unit8co).


Patch:
diff --git a/darts/timeseries.py b/darts/timeseries.py
index 9512f1d9..fc757f58 100644
--- a/darts/timeseries.py
+++ b/darts/timeseries.py
@@ -2085,7 +2085,8 @@ class TimeSeries:
         self, split_point: Union[pd.Timestamp, float, int], after: bool = True
     ) -> Tuple["TimeSeries", "TimeSeries"]:
 
-        point_index = self.get_index_at_point(split_point, after)
+        # Get index with not after in order to avoid moving twice if split_point is not in self
+        point_index = self.get_index_at_point(split_point, not after)
         return (
             self[: point_index + (1 if after else 0)],
             self[point_index + (1 if after else 0) :],


Test patch:
diff --git a/darts/tests/test_timeseries.py b/darts/tests/test_timeseries.py
index b809cf6b..c4414a13 100644
--- a/darts/tests/test_timeseries.py
+++ b/darts/tests/test_timeseries.py
@@ -397,6 +397,18 @@ class TimeSeriesTestCase(DartsBaseTestClass):
             with test_case.assertRaises(ValueError):
                 test_series.split_before(value)
 
+        # Test split points between series indeces
+        times = pd.date_range("20130101", "20130120", freq="2D")
+        pd_series = pd.Series(range(10), index=times)
+        test_series2: TimeSeries = TimeSeries.from_series(pd_series)
+        split_date = pd.Timestamp("20130110")
+        seriesM, seriesN = test_series2.split_before(split_date)
+        seriesO, seriesP = test_series2.split_after(split_date)
+        test_case.assertLess(seriesM.end_time(), split_date)
+        test_case.assertGreaterEqual(seriesN.start_time(), split_date)
+        test_case.assertLessEqual(seriesO.end_time(), split_date)
+        test_case.assertGreater(seriesP.start_time(), split_date)
+
     @staticmethod
     def helper_test_drop(test_case, test_series: TimeSeries):
         seriesA = test_series.drop_after(pd.Timestamp("20130105"))