-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
quantile: rename interpolation arg to method #6108
Merged
Merged
Changes from 12 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
090b49b
quantile: rename interpolation arg to method
mathause ea5dcf2
add whats new entry
mathause cb8d24e
Apply suggestions from code review
mathause 7d074d2
Merge branch 'main' into quantile_interpolation_method
mathause bfe4857
fix ArrayLike
mathause dcfa900
Merge branch 'main' into quantile_interpolation_method
mathause 545e4d8
Merge branch 'main' into quantile_interpolation_method
mathause 7bea46f
type dim
mathause a8bd471
cleanup
mathause c304977
Merge branch 'main' into quantile_interpolation_method
mathause 0e5e4d3
update docstrings
mathause 8fe04af
indentation and quotation marks
mathause a74e8ec
Merge branch 'main' into quantile_interpolation_method
mathause 938a621
Merge branch 'main' into quantile_interpolation_method
mathause e4b3c3c
use Literal
mathause 5d5502a
Merge branch 'main' into quantile_interpolation_method
mathause a4881de
update whats new
mathause cb929d0
remove newline
mathause 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 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 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 |
---|---|---|
|
@@ -53,6 +53,7 @@ | |
from .indexes import Index, Indexes, default_indexes, propagate_indexes | ||
from .indexing import is_fancy_indexer | ||
from .merge import PANDAS_TYPES, MergeError, _extract_indexes_from_coords | ||
from .npcompat import ArrayLike | ||
from .options import OPTIONS, _get_keep_attrs | ||
from .utils import ( | ||
Default, | ||
|
@@ -3426,11 +3427,12 @@ def sortby( | |
|
||
def quantile( | ||
self, | ||
q: Any, | ||
dim: Hashable | Sequence[Hashable] | None = None, | ||
interpolation: str = "linear", | ||
q: ArrayLike, | ||
dim: str | Sequence[Hashable] | None = None, | ||
method: str = "linear", | ||
keep_attrs: bool = None, | ||
skipna: bool = True, | ||
interpolation: str = None, | ||
) -> DataArray: | ||
"""Compute the qth quantile of the data along the specified dimension. | ||
|
||
|
@@ -3442,18 +3444,34 @@ def quantile( | |
Quantile to compute, which must be between 0 and 1 inclusive. | ||
dim : hashable or sequence of hashable, optional | ||
Dimension(s) over which to apply quantile. | ||
interpolation : {"linear", "lower", "higher", "midpoint", "nearest"}, default: "linear" | ||
dcherian marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This optional parameter specifies the interpolation method to | ||
use when the desired quantile lies between two data points | ||
``i < j``: | ||
|
||
- linear: ``i + (j - i) * fraction``, where ``fraction`` is | ||
the fractional part of the index surrounded by ``i`` and | ||
``j``. | ||
- lower: ``i``. | ||
- higher: ``j``. | ||
- nearest: ``i`` or ``j``, whichever is nearest. | ||
- midpoint: ``(i + j) / 2``. | ||
method : str, default: "linear" | ||
This optional parameter specifies the interpolation method to use when the | ||
desired quantile lies between two data points. The options sorted by their R | ||
type as summarized in the H&F paper [1]_ are: | ||
|
||
1. "inverted_cdf" (*) | ||
2. "averaged_inverted_cdf" (*) | ||
3. "closest_observation" (*) | ||
4. "interpolated_inverted_cdf" (*) | ||
5. "hazen" (*) | ||
6. "weibull" (*) | ||
7. "linear" (default) | ||
8. "median_unbiased" (*) | ||
9. "normal_unbiased" (*) | ||
|
||
The first three methods are discontiuous. The following discontinuous | ||
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. Typo in "discontiuous" |
||
variations of the default "linear" (7.) option are also available: | ||
|
||
* "lower" | ||
* "higher" | ||
* "midpoint" | ||
* "nearest" | ||
|
||
See :py:func:`numpy.quantile` or [1]_ for details. Methods marked with | ||
an asterix require numpy version 1.22 or newer. The "method" argument was | ||
previously called "interpolation", renamed in accordance with numpy | ||
version 1.22.0. | ||
|
||
keep_attrs : bool, optional | ||
If True, the dataset's attributes (`attrs`) will be copied from | ||
the original object to the new one. If False (default), the new | ||
|
@@ -3505,14 +3523,21 @@ def quantile( | |
Coordinates: | ||
* y (y) float64 1.0 1.5 2.0 2.5 | ||
* quantile (quantile) float64 0.0 0.5 1.0 | ||
|
||
References | ||
---------- | ||
.. [1] R. J. Hyndman and Y. Fan, | ||
"Sample quantiles in statistical packages," | ||
The American Statistician, 50(4), pp. 361-365, 1996 | ||
""" | ||
|
||
ds = self._to_temp_dataset().quantile( | ||
q, | ||
dim=dim, | ||
keep_attrs=keep_attrs, | ||
interpolation=interpolation, | ||
method=method, | ||
skipna=skipna, | ||
interpolation=interpolation, | ||
) | ||
return self._from_temp_dataset(ds) | ||
|
||
|
This file contains 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 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can use
Literal["linear", etc]
here instead ofstr
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel that's a bit over the top - can I get away without it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree it would be cool, definitely fine without out too! :)