Skip to content

Commit ade94e5

Browse files
mroeschkeMatt Roeschke
and
Matt Roeschke
authored
CLN: pd. namespace in tests/window (#38095)
Co-authored-by: Matt Roeschke <[email protected]>
1 parent 66c3c6f commit ade94e5

File tree

6 files changed

+161
-154
lines changed

6 files changed

+161
-154
lines changed

pandas/tests/window/moments/test_moments_consistency_rolling.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55

66
import pandas.util._test_decorators as td
77

8-
import pandas as pd
9-
from pandas import DataFrame, DatetimeIndex, Index, Series
8+
from pandas import DataFrame, DatetimeIndex, Index, MultiIndex, Series
109
import pandas._testing as tm
1110
from pandas.core.window.common import flex_binary_moment
1211

@@ -240,7 +239,7 @@ def test_rolling_functions_window_non_shrinkage_binary(f):
240239
)
241240
df_expected = DataFrame(
242241
columns=Index(["A", "B"], name="foo"),
243-
index=pd.MultiIndex.from_product([df.index, df.columns], names=["bar", "foo"]),
242+
index=MultiIndex.from_product([df.index, df.columns], names=["bar", "foo"]),
244243
dtype="float64",
245244
)
246245
df_result = f(df)
@@ -482,12 +481,10 @@ def test_moment_functions_zero_length_pairwise(f):
482481
df2["a"] = df2["a"].astype("float64")
483482

484483
df1_expected = DataFrame(
485-
index=pd.MultiIndex.from_product([df1.index, df1.columns]), columns=Index([])
484+
index=MultiIndex.from_product([df1.index, df1.columns]), columns=Index([])
486485
)
487486
df2_expected = DataFrame(
488-
index=pd.MultiIndex.from_product(
489-
[df2.index, df2.columns], names=["bar", "foo"]
490-
),
487+
index=MultiIndex.from_product([df2.index, df2.columns], names=["bar", "foo"]),
491488
columns=Index(["a"], name="foo"),
492489
dtype="float64",
493490
)

pandas/tests/window/moments/test_moments_rolling.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33

44
import pandas.util._test_decorators as td
55

6-
import pandas as pd
7-
from pandas import DataFrame, Series
6+
from pandas import DataFrame, Series, date_range
87
import pandas._testing as tm
98

109

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

552551
df_quantile = df.quantile([0.25, 0.5, 0.75], axis=0)

pandas/tests/window/test_api.py

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
import numpy as np
22
import pytest
33

4-
import pandas as pd
5-
from pandas import DataFrame, Index, Series, Timestamp, concat
4+
from pandas import (
5+
DataFrame,
6+
Index,
7+
MultiIndex,
8+
Period,
9+
Series,
10+
Timestamp,
11+
concat,
12+
date_range,
13+
timedelta_range,
14+
)
615
import pandas._testing as tm
716
from pandas.core.base import SpecificationError
817

@@ -78,7 +87,7 @@ def test_agg():
7887

7988
result = r.aggregate([np.mean, np.std])
8089
expected = concat([a_mean, a_std, b_mean, b_std], axis=1)
81-
expected.columns = pd.MultiIndex.from_product([["A", "B"], ["mean", "std"]])
90+
expected.columns = MultiIndex.from_product([["A", "B"], ["mean", "std"]])
8291
tm.assert_frame_equal(result, expected)
8392

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

8998
result = r.aggregate({"A": ["mean", "std"]})
9099
expected = concat([a_mean, a_std], axis=1)
91-
expected.columns = pd.MultiIndex.from_tuples([("A", "mean"), ("A", "std")])
100+
expected.columns = MultiIndex.from_tuples([("A", "mean"), ("A", "std")])
92101
tm.assert_frame_equal(result, expected)
93102

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

112121
exp_cols = [("A", "mean"), ("A", "std"), ("B", "mean"), ("B", "std")]
113-
expected.columns = pd.MultiIndex.from_tuples(exp_cols)
122+
expected.columns = MultiIndex.from_tuples(exp_cols)
114123
tm.assert_frame_equal(result, expected, check_like=True)
115124

116125

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

136145
result = r.agg([np.sum, np.mean]).columns
137-
expected = pd.MultiIndex.from_product([list("AB"), ["sum", "mean"]])
146+
expected = MultiIndex.from_product([list("AB"), ["sum", "mean"]])
138147
tm.assert_index_equal(result, expected)
139148

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

144153
result = r.agg({"A": [np.sum, np.mean]}).columns
145-
expected = pd.MultiIndex.from_tuples([("A", "sum"), ("A", "mean")])
154+
expected = MultiIndex.from_tuples([("A", "sum"), ("A", "mean")])
146155
tm.assert_index_equal(result, expected)
147156

148157

@@ -159,7 +168,7 @@ def test_agg_nested_dicts():
159168
expected = concat(
160169
[r["A"].mean(), r["A"].std(), r["B"].mean(), r["B"].std()], axis=1
161170
)
162-
expected.columns = pd.MultiIndex.from_tuples(
171+
expected.columns = MultiIndex.from_tuples(
163172
[("ra", "mean"), ("ra", "std"), ("rb", "mean"), ("rb", "std")]
164173
)
165174
with pytest.raises(SpecificationError, match=msg):
@@ -191,21 +200,21 @@ def test_count_nonnumeric_types():
191200
"int": [1, 2, 3],
192201
"float": [4.0, 5.0, 6.0],
193202
"string": list("abc"),
194-
"datetime": pd.date_range("20170101", periods=3),
195-
"timedelta": pd.timedelta_range("1 s", periods=3, freq="s"),
203+
"datetime": date_range("20170101", periods=3),
204+
"timedelta": timedelta_range("1 s", periods=3, freq="s"),
196205
"periods": [
197-
pd.Period("2012-01"),
198-
pd.Period("2012-02"),
199-
pd.Period("2012-03"),
206+
Period("2012-01"),
207+
Period("2012-02"),
208+
Period("2012-03"),
200209
],
201210
"fl_inf": [1.0, 2.0, np.Inf],
202211
"fl_nan": [1.0, 2.0, np.NaN],
203212
"str_nan": ["aa", "bb", np.NaN],
204213
"dt_nat": dt_nat_col,
205214
"periods_nat": [
206-
pd.Period("2012-01"),
207-
pd.Period("2012-02"),
208-
pd.Period(None),
215+
Period("2012-01"),
216+
Period("2012-02"),
217+
Period(None),
209218
],
210219
},
211220
columns=cols,
@@ -298,11 +307,11 @@ def test_multiple_agg_funcs(func, window_size, expected_vals):
298307
else:
299308
window = f()
300309

301-
index = pd.MultiIndex.from_tuples(
310+
index = MultiIndex.from_tuples(
302311
[("A", 0), ("A", 1), ("A", 2), ("B", 3), ("B", 4), ("B", 5), ("B", 6)],
303312
names=["stock", None],
304313
)
305-
columns = pd.MultiIndex.from_tuples(
314+
columns = MultiIndex.from_tuples(
306315
[("low", "mean"), ("low", "max"), ("high", "mean"), ("high", "min")]
307316
)
308317
expected = DataFrame(expected_vals, index=index, columns=columns)

pandas/tests/window/test_expanding.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33

44
from pandas.errors import UnsupportedFunctionCall
55

6-
import pandas as pd
7-
from pandas import DataFrame, Series
6+
from pandas import DataFrame, DatetimeIndex, Series
87
import pandas._testing as tm
98
from pandas.core.window import Expanding
109

@@ -82,8 +81,8 @@ def test_empty_df_expanding(expander):
8281

8382
# Verifies that datetime and integer expanding windows can be applied
8483
# to empty DataFrames with datetime index
85-
expected = DataFrame(index=pd.DatetimeIndex([]))
86-
result = DataFrame(index=pd.DatetimeIndex([])).expanding(expander).sum()
84+
expected = DataFrame(index=DatetimeIndex([]))
85+
result = DataFrame(index=DatetimeIndex([])).expanding(expander).sum()
8786
tm.assert_frame_equal(result, expected)
8887

8988

0 commit comments

Comments
 (0)