Skip to content

CLN: Create tests/window/moments/conftest for specific fixtures #41430

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 1 commit into from
May 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
181 changes: 1 addition & 180 deletions pandas/tests/window/conftest.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
from datetime import (
datetime,
timedelta,
)
from datetime import timedelta

import numpy as np
import pytest

import pandas.util._test_decorators as td

from pandas import (
DataFrame,
Series,
bdate_range,
notna,
to_datetime,
)

Expand Down Expand Up @@ -141,168 +134,6 @@ def engine_and_raw(request):
return request.param


# create the data only once as we are not setting it
def _create_consistency_data():
def create_series():
return [
Series(dtype=object),
Series([np.nan]),
Series([np.nan, np.nan]),
Series([3.0]),
Series([np.nan, 3.0]),
Series([3.0, np.nan]),
Series([1.0, 3.0]),
Series([2.0, 2.0]),
Series([3.0, 1.0]),
Series(
[5.0, 5.0, 5.0, 5.0, np.nan, np.nan, np.nan, 5.0, 5.0, np.nan, np.nan]
),
Series(
[
np.nan,
5.0,
5.0,
5.0,
np.nan,
np.nan,
np.nan,
5.0,
5.0,
np.nan,
np.nan,
]
),
Series(
[
np.nan,
np.nan,
5.0,
5.0,
np.nan,
np.nan,
np.nan,
5.0,
5.0,
np.nan,
np.nan,
]
),
Series(
[
np.nan,
3.0,
np.nan,
3.0,
4.0,
5.0,
6.0,
np.nan,
np.nan,
7.0,
12.0,
13.0,
14.0,
15.0,
]
),
Series(
[
np.nan,
5.0,
np.nan,
2.0,
4.0,
0.0,
9.0,
np.nan,
np.nan,
3.0,
12.0,
13.0,
14.0,
15.0,
]
),
Series(
[
2.0,
3.0,
np.nan,
3.0,
4.0,
5.0,
6.0,
np.nan,
np.nan,
7.0,
12.0,
13.0,
14.0,
15.0,
]
),
Series(
[
2.0,
5.0,
np.nan,
2.0,
4.0,
0.0,
9.0,
np.nan,
np.nan,
3.0,
12.0,
13.0,
14.0,
15.0,
]
),
Series(range(10)),
Series(range(20, 0, -2)),
]

def create_dataframes():
return [
DataFrame(),
DataFrame(columns=["a"]),
DataFrame(columns=["a", "a"]),
DataFrame(columns=["a", "b"]),
DataFrame(np.arange(10).reshape((5, 2))),
DataFrame(np.arange(25).reshape((5, 5))),
DataFrame(np.arange(25).reshape((5, 5)), columns=["a", "b", 99, "d", "d"]),
] + [DataFrame(s) for s in create_series()]

def is_constant(x):
values = x.values.ravel("K")
return len(set(values[notna(values)])) == 1

def no_nans(x):
return x.notna().all().all()

# data is a tuple(object, is_constant, no_nans)
data = create_series() + create_dataframes()

return [(x, is_constant(x), no_nans(x)) for x in data]


@pytest.fixture(params=_create_consistency_data())
def consistency_data(request):
"""Create consistency data"""
return request.param


@pytest.fixture
def frame():
"""Make mocked frame as fixture."""
return DataFrame(
np.random.randn(100, 10),
index=bdate_range(datetime(2009, 1, 1), periods=100),
columns=np.arange(10),
)


@pytest.fixture
def times_frame():
"""Frame for testing times argument in EWM groupby."""
Expand All @@ -328,16 +159,6 @@ def times_frame():
)


@pytest.fixture
def series():
"""Make mocked series as fixture."""
arr = np.random.randn(100)
locs = np.arange(20, 40)
arr[locs] = np.NaN
series = Series(arr, index=bdate_range(datetime(2009, 1, 1), periods=100))
return series


@pytest.fixture(params=["1 day", timedelta(days=1)])
def halflife_with_times(request):
"""Halflife argument for EWM when times is specified."""
Expand Down
183 changes: 183 additions & 0 deletions pandas/tests/window/moments/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
from datetime import datetime

import numpy as np
import pytest

from pandas import (
DataFrame,
Series,
bdate_range,
notna,
)


@pytest.fixture
def series():
"""Make mocked series as fixture."""
arr = np.random.randn(100)
locs = np.arange(20, 40)
arr[locs] = np.NaN
series = Series(arr, index=bdate_range(datetime(2009, 1, 1), periods=100))
return series


@pytest.fixture
def frame():
"""Make mocked frame as fixture."""
return DataFrame(
np.random.randn(100, 10),
index=bdate_range(datetime(2009, 1, 1), periods=100),
columns=np.arange(10),
)


# create the data only once as we are not setting it
def _create_consistency_data():
def create_series():
return [
Series(dtype=object),
Series([np.nan]),
Series([np.nan, np.nan]),
Series([3.0]),
Series([np.nan, 3.0]),
Series([3.0, np.nan]),
Series([1.0, 3.0]),
Series([2.0, 2.0]),
Series([3.0, 1.0]),
Series(
[5.0, 5.0, 5.0, 5.0, np.nan, np.nan, np.nan, 5.0, 5.0, np.nan, np.nan]
),
Series(
[
np.nan,
5.0,
5.0,
5.0,
np.nan,
np.nan,
np.nan,
5.0,
5.0,
np.nan,
np.nan,
]
),
Series(
[
np.nan,
np.nan,
5.0,
5.0,
np.nan,
np.nan,
np.nan,
5.0,
5.0,
np.nan,
np.nan,
]
),
Series(
[
np.nan,
3.0,
np.nan,
3.0,
4.0,
5.0,
6.0,
np.nan,
np.nan,
7.0,
12.0,
13.0,
14.0,
15.0,
]
),
Series(
[
np.nan,
5.0,
np.nan,
2.0,
4.0,
0.0,
9.0,
np.nan,
np.nan,
3.0,
12.0,
13.0,
14.0,
15.0,
]
),
Series(
[
2.0,
3.0,
np.nan,
3.0,
4.0,
5.0,
6.0,
np.nan,
np.nan,
7.0,
12.0,
13.0,
14.0,
15.0,
]
),
Series(
[
2.0,
5.0,
np.nan,
2.0,
4.0,
0.0,
9.0,
np.nan,
np.nan,
3.0,
12.0,
13.0,
14.0,
15.0,
]
),
Series(range(10)),
Series(range(20, 0, -2)),
]

def create_dataframes():
return [
DataFrame(),
DataFrame(columns=["a"]),
DataFrame(columns=["a", "a"]),
DataFrame(columns=["a", "b"]),
DataFrame(np.arange(10).reshape((5, 2))),
DataFrame(np.arange(25).reshape((5, 5))),
DataFrame(np.arange(25).reshape((5, 5)), columns=["a", "b", 99, "d", "d"]),
] + [DataFrame(s) for s in create_series()]

def is_constant(x):
values = x.values.ravel("K")
return len(set(values[notna(values)])) == 1

def no_nans(x):
return x.notna().all().all()

# data is a tuple(object, is_constant, no_nans)
data = create_series() + create_dataframes()

return [(x, is_constant(x), no_nans(x)) for x in data]


@pytest.fixture(params=_create_consistency_data())
def consistency_data(request):
"""Create consistency data"""
return request.param
3 changes: 2 additions & 1 deletion pandas/tests/window/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
from pandas.core.base import SpecificationError


def test_getitem(frame):
def test_getitem():
frame = DataFrame(np.random.randn(5, 5))
r = frame.rolling(window=5)
tm.assert_index_equal(r._selected_obj.columns, frame.columns)

Expand Down