-
Notifications
You must be signed in to change notification settings - Fork 1k
feat(timeseries): add idxmin / idxmax to TimeSeries #3115
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
Open
jbbqqf
wants to merge
3
commits into
unit8co:master
Choose a base branch
from
jbbqqf:feat/2696-add-idxmin-idxmax
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4764,6 +4764,7 @@ def min(self, axis: int = 2) -> Self: | |
|
|
||
| If ``axis=1``, the static covariates and the hierarchy are discarded from the series. | ||
|
|
||
|
|
||
| Parameters | ||
| ---------- | ||
| axis | ||
|
|
@@ -4793,6 +4794,7 @@ def max(self, axis: int = 2) -> Self: | |
|
|
||
| If ``axis=1``, the static covariates and the hierarchy are discarded from the series. | ||
|
|
||
|
|
||
| Parameters | ||
| ---------- | ||
| axis | ||
|
|
@@ -4812,6 +4814,75 @@ def max(self, axis: int = 2) -> Self: | |
| **(self._attrs if axis != 1 else dict()), | ||
| ) | ||
|
|
||
| def idxmin(self) -> pd.Series: | ||
| """Return the time index value of the minimum of each component. | ||
|
|
||
| For a stochastic series the median over samples is taken before | ||
| finding the minimum, so the returned index is well-defined regardless | ||
| of ``n_samples``. | ||
|
|
||
|
|
||
|
Comment on lines
+4823
to
+4824
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i'd say this is unnecesssary |
||
| Returns | ||
| ------- | ||
| pandas.Series | ||
| A series indexed by component name. Each value is the timestamp | ||
| (or integer index, if the series uses an ``RangeIndex``) at which | ||
| that component attains its minimum. | ||
|
|
||
| Examples | ||
| -------- | ||
| >>> import pandas as pd | ||
| >>> from darts import TimeSeries | ||
| >>> df = pd.DataFrame({"a": [1, 0, 0], "b": [0, 0, 1]}) | ||
| >>> series = TimeSeries.from_dataframe(df) | ||
| >>> series.idxmin() | ||
| a 1 | ||
| b 0 | ||
| dtype: int64 | ||
| """ | ||
| deterministic = ( | ||
| self._values | ||
| if self.is_deterministic | ||
| else np.median(self._values, axis=2, keepdims=True) | ||
| ) | ||
| # argmin along time axis → shape (n_components,) | ||
| idxs = deterministic[:, :, 0].argmin(axis=0) | ||
| return pd.Series(self._time_index[idxs], index=self.components) | ||
|
|
||
| def idxmax(self) -> pd.Series: | ||
| """Return the time index value of the maximum of each component. | ||
|
|
||
| For a stochastic series the median over samples is taken before | ||
| finding the maximum, so the returned index is well-defined regardless | ||
| of ``n_samples``. | ||
|
|
||
|
|
||
|
Comment on lines
+4858
to
+4859
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
||
| Returns | ||
| ------- | ||
| pandas.Series | ||
| A series indexed by component name. Each value is the timestamp | ||
| (or integer index, if the series uses an ``RangeIndex``) at which | ||
| that component attains its maximum. | ||
|
|
||
| Examples | ||
| -------- | ||
| >>> import pandas as pd | ||
| >>> from darts import TimeSeries | ||
| >>> df = pd.DataFrame({"a": [1, 0, 0], "b": [0, 0, 1]}) | ||
| >>> series = TimeSeries.from_dataframe(df) | ||
| >>> series.idxmax() | ||
| a 0 | ||
| b 2 | ||
| dtype: int64 | ||
| """ | ||
| deterministic = ( | ||
| self._values | ||
| if self.is_deterministic | ||
| else np.median(self._values, axis=2, keepdims=True) | ||
| ) | ||
| idxs = deterministic[:, :, 0].argmax(axis=0) | ||
| return pd.Series(self._time_index[idxs], index=self.components) | ||
|
|
||
| def quantile(self, q: float | Sequence[float] = 0.5, **kwargs) -> Self: | ||
| """Return a deterministic series with the desired quantile(s) `q` of each component computed over the samples | ||
| of the stochastic series. | ||
|
|
||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.