-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from MothNik/fix/median_performance
Fix/median performance
- Loading branch information
Showing
10 changed files
with
83 additions
and
27 deletions.
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
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
pytest>=8.1.1 |
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 |
---|---|---|
|
@@ -2,4 +2,3 @@ certifi>=2019.11.28 | |
docutils>=0.15.2 | ||
numpy>=1.18.0 | ||
statistics>=1.0.3.5 | ||
pytest>=8.1.1 |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
from .robustbase import Qn | ||
from .robustbase import Sn | ||
from .robustbase import iqr | ||
from .robustbase import mad | ||
from .robustbase import Qn # noqa: F401 | ||
from .robustbase import Sn # noqa: F401 | ||
from .robustbase import iqr # noqa: F401 | ||
from .robustbase import mad # noqa: F401 | ||
|
||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from .Qn import Qn | ||
from .Sn import Sn | ||
from .iqr import iqr | ||
from .mad import mad | ||
from .iqr import iqr # noqa: F401 | ||
from .mad import mad # noqa: F401 | ||
from .Qn import Qn # noqa: F401 | ||
from .Sn import Sn # noqa: F401 |
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
from .mean import mean | ||
from .median import median | ||
from .mean import mean # noqa: F401 | ||
from .median import median # noqa: F401 |
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from typing import Optional, Tuple, Union | ||
|
||
import numpy as np | ||
import pytest | ||
|
||
from robustbase.utils.median import median | ||
|
||
X_EMPTY = [] | ||
X_ODD_N = [5.5, 3.2, -10.0, -2.1, 8.4] | ||
X_EVEN_N = [5.5, 3.2, -10.0, -2.1, 8.4, 0.0] | ||
|
||
|
||
@pytest.mark.parametrize("as_array", [False, True]) | ||
@pytest.mark.parametrize( | ||
"comb", | ||
[ | ||
(X_EMPTY, False, False, None), | ||
(X_EMPTY, True, False, None), | ||
(X_EMPTY, False, True, None), | ||
(X_EMPTY, True, True, None), | ||
(X_ODD_N, False, False, 3.2), | ||
(X_ODD_N, True, False, 3.2), | ||
(X_ODD_N, False, True, 3.2), | ||
(X_ODD_N, True, True, 3.2), | ||
(X_EVEN_N, False, False, 1.6), | ||
(X_EVEN_N, True, False, 0.0), | ||
(X_EVEN_N, False, True, 3.2), | ||
(X_EVEN_N, True, True, 0.0), | ||
], | ||
) | ||
def test_median( | ||
comb: Tuple[Union[list, np.ndarray], bool, bool, Optional[float]], | ||
as_array: bool, | ||
): | ||
x, low, high, expected = comb | ||
if as_array: | ||
x = np.array(x) | ||
|
||
# for empty samples, an error should be raised | ||
if expected is None: | ||
with pytest.raises(ValueError): | ||
median(x, low=low, high=high) | ||
|
||
return | ||
|
||
# otherwise, the expected median should be returned | ||
assert median(x, low=low, high=high) == expected |