Skip to content

Commit 227a095

Browse files
GH1055 new test format
1 parent 85742e4 commit 227a095

File tree

1 file changed

+84
-21
lines changed

1 file changed

+84
-21
lines changed

tests/test_api_typing.py

Lines changed: 84 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ def tests_datetimeindexersamplergroupby() -> None:
5858
np.random.standard_normal((365, 2)), index=idx, columns=["col1", "col2"]
5959
)
6060
gb_df = df.groupby("col2")
61+
62+
# TODO the groupby here is too wide and returns _ResamplerGroupby alias
63+
# def f1(gb: DatetimeIndexResamplerGroupby):
64+
# check(gb, DatetimeIndexResamplerGroupby)
65+
#
66+
# f1(gb_df.resample("ME"))
67+
6168
check(gb_df.resample("ME"), DatetimeIndexResamplerGroupby)
6269

6370

@@ -67,9 +74,30 @@ def test_timedeltaindexresamplergroupby() -> None:
6774
np.random.standard_normal((5, 2)), index=idx, columns=["col1", "col2"]
6875
)
6976
gb_df = df.groupby("col2")
77+
78+
# TODO the groupby here is too wide and returns _ResamplerGroupby alias
79+
# def f1(gb: TimedeltaIndexResamplerGroupby):
80+
# check(gb, TimedeltaIndexResamplerGroupby)
81+
#
82+
# f1(gb_df.resample("1D"))
83+
7084
check(gb_df.resample("1D"), TimedeltaIndexResamplerGroupby)
7185

7286

87+
@pytest.mark.skip("Resampling with a PeriodIndex is deprecated.")
88+
def test_periodindexresamplergroupby() -> None:
89+
idx = pd.period_range("2020-01-28 09:00", periods=4, freq="D")
90+
df = pd.DataFrame(data=4 * [range(2)], index=idx, columns=["a", "b"])
91+
92+
# TODO the groupby here is too wide and returns _ResamplerGroupby alias
93+
# def f1(gb: PeriodIndexResamplerGroupby):
94+
# check(gb, PeriodIndexResamplerGroupby)
95+
#
96+
# f1(df.groupby("a").resample("3min"))
97+
98+
check(df.groupby("a").resample("3min"), PeriodIndexResamplerGroupby)
99+
100+
73101
def test_natype() -> None:
74102
i64dt = pd.Int64Dtype()
75103
check(assert_type(i64dt.na_value, NAType), NAType)
@@ -78,71 +106,102 @@ def test_natype() -> None:
78106
def test_nattype() -> None:
79107
td = pd.Timedelta("1 day")
80108
as_nat = pd.NaT
109+
81110
check(assert_type(td + as_nat, NaTType), NaTType)
82111

83112

84113
def test_expanding() -> None:
85114
df = pd.DataFrame({"B": [0, 1, 2, np.nan, 4]})
86-
check(df.expanding(), Expanding)
115+
116+
def f1(gb: Expanding):
117+
check(gb, Expanding)
118+
119+
f1(df.expanding())
87120

88121

89122
def test_expanding_groubpy() -> None:
90123
df = pd.DataFrame({"B": [0, 1, 2, np.nan, 4]})
91-
check(df.groupby("B").expanding(), ExpandingGroupby)
124+
125+
def f1(gb: ExpandingGroupby):
126+
check(gb, ExpandingGroupby)
127+
128+
f1(df.groupby("B").expanding())
92129

93130

94131
def test_ewm() -> None:
95132
df = pd.DataFrame({"B": [0, 1, 2, np.nan, 4]})
96-
check(df.ewm(2), ExponentialMovingWindow)
133+
134+
def f1(gb: ExponentialMovingWindow):
135+
check(gb, ExponentialMovingWindow)
136+
137+
f1(df.ewm(2))
97138

98139

99140
def test_ewm_groubpy() -> None:
100141
df = pd.DataFrame({"B": [0, 1, 2, np.nan, 4]})
101-
check(df.groupby("B").ewm(2), ExponentialMovingWindowGroupby)
142+
143+
def f1(gb: ExponentialMovingWindowGroupby):
144+
check(gb, ExponentialMovingWindowGroupby)
145+
146+
f1(df.groupby("B").ewm(2))
102147

103148

104149
def test_json_reader() -> None:
105150
df = pd.DataFrame({"B": [0, 1, 2, np.nan, 4]})
106151

152+
def f1(gb: JsonReader):
153+
check(gb, JsonReader)
154+
107155
with ensure_clean() as path:
108156
check(assert_type(df.to_json(path), None), type(None))
109157
json_reader = read_json(path, chunksize=1, lines=True)
110-
check(json_reader, JsonReader)
158+
f1(json_reader)
111159
json_reader.close()
112160

113161

114-
@pytest.mark.skip("Resampling with a PeriodIndex is deprecated.")
115-
def test_periodindexresamplergroupby() -> None:
116-
idx = pd.period_range("2020-01-28 09:00", periods=4, freq="D")
117-
df = pd.DataFrame(data=4 * [range(2)], index=idx, columns=["a", "b"])
118-
check(
119-
df.groupby("a").resample("3min"),
120-
PeriodIndexResamplerGroupby,
121-
)
122-
123-
124162
def test_resampler() -> None:
125163
s = pd.Series([1, 2, 3, 4, 5], index=pd.date_range("20130101", periods=5, freq="s"))
126-
check(s.resample("3min"), Resampler)
164+
165+
def f1(gb: Resampler):
166+
check(gb, Resampler)
167+
168+
f1(s.resample("3min"))
127169

128170

129171
def test_rolling() -> None:
130172
df = pd.DataFrame({"B": [0, 1, 2, np.nan, 4]})
131-
check(df.rolling(2), Rolling)
173+
174+
def f1(gb: Rolling):
175+
check(gb, Rolling)
176+
177+
f1(df.rolling(2))
132178

133179

134180
def test_rolling_groupby() -> None:
135181
df = pd.DataFrame({"B": [0, 1, 2, np.nan, 4]})
136-
check(df.groupby("B").rolling(2), RollingGroupby)
182+
183+
def f1(gb: RollingGroupby):
184+
check(gb, RollingGroupby)
185+
186+
f1(df.groupby("B").rolling(2))
137187

138188

139189
def test_timegrouper() -> None:
140-
check(pd.Grouper(key="Publish date", freq="1W"), TimeGrouper)
190+
grouper = pd.Grouper(key="Publish date", freq="1W")
191+
192+
def f1(gb: TimeGrouper):
193+
check(gb, TimeGrouper)
194+
195+
f1(grouper)
141196

142197

143198
def test_window() -> None:
144199
ser = pd.Series([0, 1, 5, 2, 8])
145-
check(ser.rolling(2, win_type="gaussian"), Window)
200+
201+
def f1(gb: Window):
202+
check(gb, Window)
203+
204+
f1(ser.rolling(2, win_type="gaussian"))
146205

147206

148207
def test_statereader(tmp_path: Path) -> None:
@@ -153,5 +212,9 @@ def test_statereader(tmp_path: Path) -> None:
153212
df.to_stata(
154213
path, time_stamp=time_stamp, variable_labels=variable_labels, version=None
155214
)
215+
216+
def f1(gb: StataReader):
217+
check(gb, StataReader)
218+
156219
with StataReader(path) as reader:
157-
check(reader, StataReader)
220+
f1(reader)

0 commit comments

Comments
 (0)