Skip to content

Commit 8339623

Browse files
committed
Implemented review suggestions
1 parent 4f3f6dc commit 8339623

File tree

3 files changed

+15
-31
lines changed

3 files changed

+15
-31
lines changed

pandas/_libs/window/aggregations.pyx

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -494,34 +494,18 @@ cdef float64_t calc_skew(int64_t minp, int64_t nobs,
494494
int64_t num_consecutive_same_value
495495
) noexcept nogil:
496496
cdef:
497-
float64_t result, dnobs, m2_cutoff
497+
float64_t result, dnobs
498498
float64_t moments_ratio, correction
499499

500500
if nobs >= minp:
501501
dnobs = <float64_t>nobs
502502

503-
# Relative cutoff as introduced in #62405
504-
# See the comment in nanops.nankurt for further explanation
505-
m2_cutoff = ((EpsF64 * mean) ** 2) * dnobs
506-
507503
if nobs < 3:
508504
result = NaN
509505
# GH 42064 46431
510506
# uniform case, force result to be 0
511507
elif num_consecutive_same_value >= nobs:
512508
result = 0.0
513-
# #18044: with degenerate distribution, floating issue will
514-
# cause m2 != 0. and cause the result is a very
515-
# large number.
516-
#
517-
# in core/nanops.py nanskew/nankurt call the function
518-
# _zero_out_fperr(m2) to fix floating error.
519-
# if the variance is less than a relative cutoff value
520-
# it could be treated as zero, here we follow the original
521-
# skew/kurt behaviour to check
522-
# m2 <= ((float64_machine_eps * mean) ** 2) * observations
523-
elif m2 <= m2_cutoff:
524-
result = NaN
525509
else:
526510
moments_ratio = m3 / (m2 * sqrt(m2))
527511
correction = dnobs * sqrt((dnobs - 1)) / (dnobs - 2)

pandas/tests/window/conftest.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,6 @@ def series():
109109
return series
110110

111111

112-
@pytest.fixture
113-
def low_variance_series():
114-
"""Make a mocked low variance series as a fixture"""
115-
arr = np.random.default_rng(505).normal(loc=0e0, scale=1e-8, size=100)
116-
locs = np.arange(20, 40)
117-
arr[locs] = np.nan
118-
series = Series(arr, index=bdate_range(datetime(2009, 1, 1), periods=100))
119-
return series
120-
121-
122112
@pytest.fixture
123113
def frame():
124114
"""Make mocked frame as fixture."""

pandas/tests/window/test_rolling_skew_kurt.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from datetime import datetime
12
from functools import partial
23

34
import numpy as np
@@ -6,6 +7,7 @@
67
from pandas import (
78
DataFrame,
89
Series,
10+
bdate_range,
911
concat,
1012
isna,
1113
notna,
@@ -26,13 +28,21 @@ def test_series(series, sp_func, roll_func):
2628

2729

2830
@pytest.mark.parametrize("sp_func, roll_func", [["kurtosis", "kurt"], ["skew", "skew"]])
29-
def test_low_variance_series(low_variance_series, sp_func, roll_func):
31+
def test_low_variance_series(sp_func, roll_func):
3032
sp_stats = pytest.importorskip("scipy.stats")
3133

34+
arr = np.random.default_rng(505).normal(loc=0e0, scale=1e-16, size=100)
35+
locs = np.arange(20, 40)
36+
arr[locs] = np.nan
37+
low_variance_series = Series(
38+
arr, index=bdate_range(datetime(2009, 1, 1), periods=100)
39+
)
40+
3241
compare_func = partial(getattr(sp_stats, sp_func), bias=False)
33-
result = getattr(low_variance_series.rolling(50), roll_func)()
34-
assert isinstance(result, Series)
35-
tm.assert_almost_equal(result.iloc[-1], compare_func(low_variance_series[-50:]))
42+
window = low_variance_series.rolling(50)
43+
result = getattr(window, roll_func)()
44+
expected = window.apply(compare_func)
45+
tm.assert_almost_equal(result, expected)
3646

3747

3848
@pytest.mark.parametrize("sp_func, roll_func", [["kurtosis", "kurt"], ["skew", "skew"]])

0 commit comments

Comments
 (0)