-
-
Notifications
You must be signed in to change notification settings - Fork 19.3k
BUG: Aligned skew and kurt results with scipy.stats #62925
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
base: main
Are you sure you want to change the base?
Changes from 9 commits
99a602f
612ec5f
a5e4680
ade3f0c
b74c98a
7e1ac6a
6275874
86f416d
3369506
e2b8b7f
98356d6
2dd44a8
251d809
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,6 @@ | |
|
|
||
| import pandas as pd | ||
| from pandas import ( | ||
| DataFrame, | ||
| Series, | ||
| date_range, | ||
| ) | ||
|
|
@@ -228,47 +227,10 @@ def test_sem(self): | |
| result = s.sem(ddof=1) | ||
| assert pd.isna(result) | ||
|
|
||
| def test_skew(self): | ||
|
Member
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. Why are you removing this test?
Author
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. HI Alvaro, Thank you for the review. In my previous commit I thought these were duplicated tests, but looking at it again these should not be removed. I will revert and update the tests. |
||
| sp_stats = pytest.importorskip("scipy.stats") | ||
|
|
||
| string_series = Series(range(20), dtype=np.float64, name="series") | ||
|
|
||
| alt = lambda x: sp_stats.skew(x, bias=False) | ||
| self._check_stat_op("skew", alt, string_series) | ||
|
|
||
| # test corner cases, skew() returns NaN unless there's at least 3 | ||
| # values | ||
| min_N = 3 | ||
| for i in range(1, min_N + 1): | ||
| s = Series(np.ones(i)) | ||
| df = DataFrame(np.ones((i, i))) | ||
| if i < min_N: | ||
| assert np.isnan(s.skew()) | ||
| assert np.isnan(df.skew()).all() | ||
| else: | ||
| assert 0 == s.skew() | ||
| assert isinstance(s.skew(), np.float64) # GH53482 | ||
| assert (df.skew() == 0).all() | ||
|
|
||
| def test_kurt(self): | ||
| sp_stats = pytest.importorskip("scipy.stats") | ||
|
|
||
| string_series = Series(range(20), dtype=np.float64, name="series") | ||
|
|
||
| alt = lambda x: sp_stats.kurtosis(x, bias=False) | ||
| self._check_stat_op("kurt", alt, string_series) | ||
|
|
||
| def test_kurt_corner(self): | ||
|
Member
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. Why are you removing this test? |
||
| # test corner cases, kurt() returns NaN unless there's at least 4 | ||
| # values | ||
| min_N = 4 | ||
| for i in range(1, min_N + 1): | ||
| s = Series(np.ones(i)) | ||
| df = DataFrame(np.ones((i, i))) | ||
| if i < min_N: | ||
| assert np.isnan(s.kurt()) | ||
| assert np.isnan(df.kurt()).all() | ||
| else: | ||
| assert 0 == s.kurt() | ||
| assert isinstance(s.kurt(), np.float64) # GH53482 | ||
| assert (df.kurt() == 0).all() | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -559,10 +559,10 @@ def _skew_kurt_wrap(self, values, axis=None, func=None): | |||||||||||||||||
| result = func(values, axis=axis, bias=False) | ||||||||||||||||||
| # fix for handling cases where all elements in an axis are the same | ||||||||||||||||||
| if isinstance(result, np.ndarray): | ||||||||||||||||||
| result[np.max(values, axis=axis) == np.min(values, axis=axis)] = 0 | ||||||||||||||||||
| result[np.max(values, axis=axis) == np.min(values, axis=axis)] = np.nan | ||||||||||||||||||
| return result | ||||||||||||||||||
| elif np.max(values) == np.min(values): | ||||||||||||||||||
| return 0.0 | ||||||||||||||||||
| return np.nan | ||||||||||||||||||
|
Comment on lines
560
to
+565
Member
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 think these branches can be removed, since SciPy already assigns
Suggested change
|
||||||||||||||||||
| return result | ||||||||||||||||||
|
|
||||||||||||||||||
| def test_nanskew(self, skipna): | ||||||||||||||||||
|
|
@@ -1021,7 +1021,7 @@ def test_constant_series(self, val): | |||||||||||||||||
| # xref GH 11974 | ||||||||||||||||||
| data = val * np.ones(300) | ||||||||||||||||||
| skew = nanops.nanskew(data) | ||||||||||||||||||
| assert skew == 0.0 | ||||||||||||||||||
| assert np.isnan(skew) | ||||||||||||||||||
|
|
||||||||||||||||||
| def test_all_finite(self): | ||||||||||||||||||
| alpha, beta = 0.3, 0.1 | ||||||||||||||||||
|
|
@@ -1089,7 +1089,7 @@ def test_constant_series(self, val): | |||||||||||||||||
| # xref GH 11974 | ||||||||||||||||||
| data = val * np.ones(300) | ||||||||||||||||||
| kurt = nanops.nankurt(data) | ||||||||||||||||||
| tm.assert_equal(kurt, 0.0) | ||||||||||||||||||
| tm.assert_equal(kurt, np.nan) | ||||||||||||||||||
|
|
||||||||||||||||||
| def test_all_finite(self): | ||||||||||||||||||
| alpha, beta = 0.3, 0.1 | ||||||||||||||||||
|
|
||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.