@@ -58,6 +58,13 @@ def tests_datetimeindexersamplergroupby() -> None:
58
58
np .random .standard_normal ((365 , 2 )), index = idx , columns = ["col1" , "col2" ]
59
59
)
60
60
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
+
61
68
check (gb_df .resample ("ME" ), DatetimeIndexResamplerGroupby )
62
69
63
70
@@ -67,9 +74,30 @@ def test_timedeltaindexresamplergroupby() -> None:
67
74
np .random .standard_normal ((5 , 2 )), index = idx , columns = ["col1" , "col2" ]
68
75
)
69
76
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
+
70
84
check (gb_df .resample ("1D" ), TimedeltaIndexResamplerGroupby )
71
85
72
86
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
+
73
101
def test_natype () -> None :
74
102
i64dt = pd .Int64Dtype ()
75
103
check (assert_type (i64dt .na_value , NAType ), NAType )
@@ -78,71 +106,102 @@ def test_natype() -> None:
78
106
def test_nattype () -> None :
79
107
td = pd .Timedelta ("1 day" )
80
108
as_nat = pd .NaT
109
+
81
110
check (assert_type (td + as_nat , NaTType ), NaTType )
82
111
83
112
84
113
def test_expanding () -> None :
85
114
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 ())
87
120
88
121
89
122
def test_expanding_groubpy () -> None :
90
123
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 ())
92
129
93
130
94
131
def test_ewm () -> None :
95
132
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 ))
97
138
98
139
99
140
def test_ewm_groubpy () -> None :
100
141
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 ))
102
147
103
148
104
149
def test_json_reader () -> None :
105
150
df = pd .DataFrame ({"B" : [0 , 1 , 2 , np .nan , 4 ]})
106
151
152
+ def f1 (gb : JsonReader ):
153
+ check (gb , JsonReader )
154
+
107
155
with ensure_clean () as path :
108
156
check (assert_type (df .to_json (path ), None ), type (None ))
109
157
json_reader = read_json (path , chunksize = 1 , lines = True )
110
- check (json_reader , JsonReader )
158
+ f1 (json_reader )
111
159
json_reader .close ()
112
160
113
161
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
-
124
162
def test_resampler () -> None :
125
163
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" ))
127
169
128
170
129
171
def test_rolling () -> None :
130
172
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 ))
132
178
133
179
134
180
def test_rolling_groupby () -> None :
135
181
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 ))
137
187
138
188
139
189
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 )
141
196
142
197
143
198
def test_window () -> None :
144
199
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" ))
146
205
147
206
148
207
def test_statereader (tmp_path : Path ) -> None :
@@ -153,5 +212,9 @@ def test_statereader(tmp_path: Path) -> None:
153
212
df .to_stata (
154
213
path , time_stamp = time_stamp , variable_labels = variable_labels , version = None
155
214
)
215
+
216
+ def f1 (gb : StataReader ):
217
+ check (gb , StataReader )
218
+
156
219
with StataReader (path ) as reader :
157
- check (reader , StataReader )
220
+ f1 (reader )
0 commit comments