Skip to content

BUG: Series rolling count ignores min_periods #30923

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

Merged
Merged
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
398bf7d
BUG: Series rolling count ignores min_periods (GH26996)
fujiaxiang Jan 11, 2020
5d471c9
Merge remote-tracking branch 'upstream/master' into series_rolling_co…
fujiaxiang Jan 17, 2020
47f4e61
ENH: handles min_periods argument in rolling.count (GH26996)
fujiaxiang Jan 17, 2020
df2a3e9
DOC: moved whatsnew to V1.1.0
fujiaxiang Jan 18, 2020
554abfa
Merge remote-tracking branch 'upstream/master' into series_rolling_co…
fujiaxiang Jan 18, 2020
c4878b0
Merge remote-tracking branch 'upstream/master' into series_rolling_co…
fujiaxiang Jan 18, 2020
b0f5baa
Merge remote-tracking branch 'upstream/master' into series_rolling_co…
fujiaxiang Jan 19, 2020
bfe10f0
TST: added more tests (GH26996)
fujiaxiang Jan 21, 2020
1a90629
Merge branch 'master' into series_rolling_count_ignores_min_periods
fujiaxiang Jan 21, 2020
be0926b
Merge remote-tracking branch 'upstream/master' into series_rolling_co…
fujiaxiang Jan 21, 2020
c0046b6
BUG: updated rolling and expanding count for consistency (GH26996)
fujiaxiang Jan 21, 2020
8807ba1
CLN: further cleaned code (GH26996)
fujiaxiang Jan 22, 2020
7aa1582
Merge remote-tracking branch 'upstream/master' into series_rolling_co…
fujiaxiang Jan 23, 2020
bcce129
TST: cleaned up tests (GH26996)
fujiaxiang Jan 24, 2020
1a4352b
BUG: changed min_periods default to 0 for rolling and expanding (GH26…
fujiaxiang Jan 24, 2020
9fa4531
BUG: reverted non-relevant changes accidentally added (GH26996)
fujiaxiang Jan 24, 2020
987c033
BUG: small change in whatsnew (GH26996)
fujiaxiang Jan 25, 2020
a00532a
CLN: slight cleanup (GH26996)
fujiaxiang Jan 25, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
TST: cleaned up tests (GH26996)
  • Loading branch information
fujiaxiang committed Jan 24, 2020
commit bcce1291eaf4a7ebd085d23dd0e0cd6c9ded2c3f
32 changes: 10 additions & 22 deletions pandas/tests/window/test_rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,21 +448,16 @@ def test_min_periods1():
tm.assert_series_equal(result, expected)


@pytest.mark.parametrize("test_series", [True, False])
def test_rolling_count_with_min_periods(test_series):
@pytest.mark.parametrize("constructor", [Series, DataFrame])
def test_rolling_count_with_min_periods(constructor):
# GH 26996
if test_series:
result = Series(range(5)).rolling(3, min_periods=3).count()
expected = Series([np.nan, np.nan, 3.0, 3.0, 3.0])
tm.assert_series_equal(result, expected)
else:
result = DataFrame(range(5)).rolling(3, min_periods=3).count()
expected = DataFrame([np.nan, np.nan, 3.0, 3.0, 3.0])
tm.assert_frame_equal(result, expected)
result = constructor(range(5)).rolling(3, min_periods=3).count()
expected = constructor([np.nan, np.nan, 3.0, 3.0, 3.0])
tm.assert_equal(result, expected)


@pytest.mark.parametrize("test_series", [True, False])
def test_rolling_count_default_min_periods_with_null_values(test_series):
@pytest.mark.parametrize("constructor", [Series, DataFrame])
def test_rolling_count_default_min_periods_with_null_values(constructor):
# GH 26996
# We need rolling count to have default min_periods=0,
# as the method is meant to count how many non-null values,
Expand All @@ -471,13 +466,6 @@ def test_rolling_count_default_min_periods_with_null_values(test_series):
values = [1, 2, 3, np.nan, 4, 5, 6]
expected_counts = [np.nan, np.nan, 3.0, 2.0, 2.0, 2.0, 3.0]

if test_series:
ser = Series(values)
result = ser.rolling(3).count()
expected = Series(expected_counts)
tm.assert_series_equal(result, expected)
else:
df = DataFrame(values)
result = df.rolling(3).count()
expected = DataFrame(expected_counts)
tm.assert_frame_equal(result, expected)
result = constructor(values).rolling(3).count()
expected = constructor(expected_counts)
tm.assert_equal(result, expected)