Skip to content

CLN: testing window namespace #38095

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 2 commits into from
Nov 26, 2020
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
11 changes: 4 additions & 7 deletions pandas/tests/window/moments/test_moments_consistency_rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

import pandas.util._test_decorators as td

import pandas as pd
from pandas import DataFrame, DatetimeIndex, Index, Series
from pandas import DataFrame, DatetimeIndex, Index, MultiIndex, Series
import pandas._testing as tm
from pandas.core.window.common import flex_binary_moment

Expand Down Expand Up @@ -240,7 +239,7 @@ def test_rolling_functions_window_non_shrinkage_binary(f):
)
df_expected = DataFrame(
columns=Index(["A", "B"], name="foo"),
index=pd.MultiIndex.from_product([df.index, df.columns], names=["bar", "foo"]),
index=MultiIndex.from_product([df.index, df.columns], names=["bar", "foo"]),
dtype="float64",
)
df_result = f(df)
Expand Down Expand Up @@ -482,12 +481,10 @@ def test_moment_functions_zero_length_pairwise(f):
df2["a"] = df2["a"].astype("float64")

df1_expected = DataFrame(
index=pd.MultiIndex.from_product([df1.index, df1.columns]), columns=Index([])
index=MultiIndex.from_product([df1.index, df1.columns]), columns=Index([])
)
df2_expected = DataFrame(
index=pd.MultiIndex.from_product(
[df2.index, df2.columns], names=["bar", "foo"]
),
index=MultiIndex.from_product([df2.index, df2.columns], names=["bar", "foo"]),
columns=Index(["a"], name="foo"),
dtype="float64",
)
Expand Down
5 changes: 2 additions & 3 deletions pandas/tests/window/moments/test_moments_rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

import pandas.util._test_decorators as td

import pandas as pd
from pandas import DataFrame, Series
from pandas import DataFrame, Series, date_range
import pandas._testing as tm


Expand Down Expand Up @@ -546,7 +545,7 @@ def test_rolling_quantile_np_percentile():
# is analogous to Numpy's percentile
row = 10
col = 5
idx = pd.date_range("20100101", periods=row, freq="B")
idx = date_range("20100101", periods=row, freq="B")
df = DataFrame(np.random.rand(row * col).reshape((row, -1)), index=idx)

df_quantile = df.quantile([0.25, 0.5, 0.75], axis=0)
Expand Down
45 changes: 27 additions & 18 deletions pandas/tests/window/test_api.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import numpy as np
import pytest

import pandas as pd
from pandas import DataFrame, Index, Series, Timestamp, concat
from pandas import (
DataFrame,
Index,
MultiIndex,
Period,
Series,
Timestamp,
concat,
date_range,
timedelta_range,
)
import pandas._testing as tm
from pandas.core.base import SpecificationError

Expand Down Expand Up @@ -78,7 +87,7 @@ def test_agg():

result = r.aggregate([np.mean, np.std])
expected = concat([a_mean, a_std, b_mean, b_std], axis=1)
expected.columns = pd.MultiIndex.from_product([["A", "B"], ["mean", "std"]])
expected.columns = MultiIndex.from_product([["A", "B"], ["mean", "std"]])
tm.assert_frame_equal(result, expected)

result = r.aggregate({"A": np.mean, "B": np.std})
Expand All @@ -88,7 +97,7 @@ def test_agg():

result = r.aggregate({"A": ["mean", "std"]})
expected = concat([a_mean, a_std], axis=1)
expected.columns = pd.MultiIndex.from_tuples([("A", "mean"), ("A", "std")])
expected.columns = MultiIndex.from_tuples([("A", "mean"), ("A", "std")])
tm.assert_frame_equal(result, expected)

result = r["A"].aggregate(["mean", "sum"])
Expand All @@ -110,7 +119,7 @@ def test_agg():
expected = concat([a_mean, a_std, b_mean, b_std], axis=1)

exp_cols = [("A", "mean"), ("A", "std"), ("B", "mean"), ("B", "std")]
expected.columns = pd.MultiIndex.from_tuples(exp_cols)
expected.columns = MultiIndex.from_tuples(exp_cols)
tm.assert_frame_equal(result, expected, check_like=True)


Expand All @@ -134,15 +143,15 @@ def test_agg_consistency():
r = df.rolling(window=3)

result = r.agg([np.sum, np.mean]).columns
expected = pd.MultiIndex.from_product([list("AB"), ["sum", "mean"]])
expected = MultiIndex.from_product([list("AB"), ["sum", "mean"]])
tm.assert_index_equal(result, expected)

result = r["A"].agg([np.sum, np.mean]).columns
expected = Index(["sum", "mean"])
tm.assert_index_equal(result, expected)

result = r.agg({"A": [np.sum, np.mean]}).columns
expected = pd.MultiIndex.from_tuples([("A", "sum"), ("A", "mean")])
expected = MultiIndex.from_tuples([("A", "sum"), ("A", "mean")])
tm.assert_index_equal(result, expected)


Expand All @@ -159,7 +168,7 @@ def test_agg_nested_dicts():
expected = concat(
[r["A"].mean(), r["A"].std(), r["B"].mean(), r["B"].std()], axis=1
)
expected.columns = pd.MultiIndex.from_tuples(
expected.columns = MultiIndex.from_tuples(
[("ra", "mean"), ("ra", "std"), ("rb", "mean"), ("rb", "std")]
)
with pytest.raises(SpecificationError, match=msg):
Expand Down Expand Up @@ -191,21 +200,21 @@ def test_count_nonnumeric_types():
"int": [1, 2, 3],
"float": [4.0, 5.0, 6.0],
"string": list("abc"),
"datetime": pd.date_range("20170101", periods=3),
"timedelta": pd.timedelta_range("1 s", periods=3, freq="s"),
"datetime": date_range("20170101", periods=3),
"timedelta": timedelta_range("1 s", periods=3, freq="s"),
"periods": [
pd.Period("2012-01"),
pd.Period("2012-02"),
pd.Period("2012-03"),
Period("2012-01"),
Period("2012-02"),
Period("2012-03"),
],
"fl_inf": [1.0, 2.0, np.Inf],
"fl_nan": [1.0, 2.0, np.NaN],
"str_nan": ["aa", "bb", np.NaN],
"dt_nat": dt_nat_col,
"periods_nat": [
pd.Period("2012-01"),
pd.Period("2012-02"),
pd.Period(None),
Period("2012-01"),
Period("2012-02"),
Period(None),
],
},
columns=cols,
Expand Down Expand Up @@ -298,11 +307,11 @@ def test_multiple_agg_funcs(func, window_size, expected_vals):
else:
window = f()

index = pd.MultiIndex.from_tuples(
index = MultiIndex.from_tuples(
[("A", 0), ("A", 1), ("A", 2), ("B", 3), ("B", 4), ("B", 5), ("B", 6)],
names=["stock", None],
)
columns = pd.MultiIndex.from_tuples(
columns = MultiIndex.from_tuples(
[("low", "mean"), ("low", "max"), ("high", "mean"), ("high", "min")]
)
expected = DataFrame(expected_vals, index=index, columns=columns)
Expand Down
7 changes: 3 additions & 4 deletions pandas/tests/window/test_expanding.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

from pandas.errors import UnsupportedFunctionCall

import pandas as pd
from pandas import DataFrame, Series
from pandas import DataFrame, DatetimeIndex, Series
import pandas._testing as tm
from pandas.core.window import Expanding

Expand Down Expand Up @@ -82,8 +81,8 @@ def test_empty_df_expanding(expander):

# Verifies that datetime and integer expanding windows can be applied
# to empty DataFrames with datetime index
expected = DataFrame(index=pd.DatetimeIndex([]))
result = DataFrame(index=pd.DatetimeIndex([])).expanding(expander).sum()
expected = DataFrame(index=DatetimeIndex([]))
result = DataFrame(index=DatetimeIndex([])).expanding(expander).sum()
tm.assert_frame_equal(result, expected)


Expand Down
Loading