Repository navigation
fix: preserve mode in extract_subseries and handle all-NaN series in strip - #3285
Open
shyamsharmas124-commits wants to merge 1 commit into
Open
shyamsharmas124-commits wants to merge 1 commit into
shyamsharmas124-commits wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3285 +/- ##
=======================================
Coverage 97.13% 97.13%
=======================================
Files 175 175
Lines 19408 19416 +8
=======================================
+ Hits 18851 18859 +8
Misses 557 557 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…strip - In _finite_rows_boundaries, return None, None if not finite_rows.any() - In TimeSeries.strip, return empty series self[:0] when no finite rows exist - In TimeSeries.longest_contiguous_slice, pass how=mode to self.strip and handle empty stripped series - In extract_subseries, pass how=mode to series.strip and return [] when series is empty - Add unit tests across test_timeseries_multivariate.py, test_timeseries.py, and test_utils.py - Update CHANGELOG.md under Unreleased
shyamsharmas124-commits
force-pushed
the
fix/missing-values-strip-mode
branch
from
October 26, 2026 03:53
0cc96a8 to
e7f0a53
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This PR addresses two interconnected edge cases in
TimeSeries.strip(),TimeSeries.longest_contiguous_slice(), andextract_subseries():extract_subseries()crashed on boundary NaNs withmode="any":darts/utils/missing_values.py,series.strip()was called with defaulthow="all"instead ofhow=mode. Whenmode="any"on a multivariate series with partialNaNs at the start or end, those rows were left unstripped.series.gaps(mode=mode)then detected boundary gaps starting at index 0 or ending at index -1, resulting inend_times = gap_start - freq(outside the series start) and crashing withValueError: Timestamp must be between ...orValueError: The index corresponding to the provided point (-1) should be a valid index in series.how=modetoseries.strip(how=mode)and returns[]immediately iflen(series) == 0.TimeSeries.strip()failed on all-NaNand empty series:_finite_rows_boundaries(),finite_rows.argmax()returns0on an all-False boolean array. For an all-NaNseries (or underhow="any"when all rows have at least oneNaN),strip()returned the entire series ofNaNs untouched instead of stripping them. On empty series,argmax()threwValueError: attempt to get argmax of an empty sequence.if not finite_rows.any(): return None, NoneandTimeSeries.strip()returnsself[:0].TimeSeries.longest_contiguous_slice()boundaryNaNs:self.strip(how=mode)and returnsstripped_seriesimmediately iflen(stripped_series) == 0.Changes Made
darts/timeseries.py:_finite_rows_boundaries(): ReturnNone, Noneifnot finite_rows.any().TimeSeries.strip(): Returnself[:0]iffirst_finite_row is None.TimeSeries.longest_contiguous_slice(): Passhow=modetoself.strip(how=mode)and check for empty stripped series.darts/utils/missing_values.py:extract_subseries(): Passhow=modetoseries.strip(how=mode)and return[]iflen(series) == 0.darts/tests/:test_timeseries_multivariate.py,test_timeseries.py, andtest_utils.pycovering all-NaNseries, empty series, and multivariate partial-NaNboundaries.CHANGELOG.md:[Unreleased] -> **Fixed**.Verification
All 250 unit tests across
test_timeseries_multivariate.py,test_utils.py,test_missing_values.py, andtest_longest_contiguous_slicepass cleanly with zero linting/formatting errors (ruff checkandruff format).