1
1
"""Test module for classes in pandas.api.typing."""
2
2
3
- from pathlib import Path
4
-
5
3
import numpy as np
6
4
import pandas as pd
7
5
from pandas ._testing import ensure_clean
20
18
Rolling ,
21
19
RollingGroupby ,
22
20
SeriesGroupBy ,
21
+ StataReader ,
23
22
TimedeltaIndexResamplerGroupby ,
24
23
TimeGrouper ,
25
24
Window ,
30
29
from tests import check
31
30
32
31
from pandas .io .json ._json import read_json
33
- from pandas .io .stata import StataReader
32
+
33
+ ResamplerGroupBy = (
34
+ DatetimeIndexResamplerGroupby
35
+ | PeriodIndexResamplerGroupby
36
+ | TimedeltaIndexResamplerGroupby
37
+ )
34
38
35
39
36
40
def test_dataframegroupby ():
@@ -59,13 +63,10 @@ def tests_datetimeindexersamplergroupby() -> None:
59
63
)
60
64
gb_df = df .groupby ("col2" )
61
65
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"))
66
+ def f1 (gb : ResamplerGroupBy ):
67
+ check (gb , DatetimeIndexResamplerGroupby )
67
68
68
- check (gb_df .resample ("ME" ), DatetimeIndexResamplerGroupby )
69
+ f1 (gb_df .resample ("ME" ))
69
70
70
71
71
72
def test_timedeltaindexresamplergroupby () -> None :
@@ -75,27 +76,21 @@ def test_timedeltaindexresamplergroupby() -> None:
75
76
)
76
77
gb_df = df .groupby ("col2" )
77
78
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"))
79
+ def f1 (gb : ResamplerGroupBy ):
80
+ check (gb , TimedeltaIndexResamplerGroupby )
83
81
84
- check (gb_df .resample ("1D" ), TimedeltaIndexResamplerGroupby )
82
+ f1 (gb_df .resample ("1D" ))
85
83
86
84
87
85
@pytest .mark .skip ("Resampling with a PeriodIndex is deprecated." )
88
86
def test_periodindexresamplergroupby () -> None :
89
87
idx = pd .period_range ("2020-01-28 09:00" , periods = 4 , freq = "D" )
90
88
df = pd .DataFrame (data = 4 * [range (2 )], index = idx , columns = ["a" , "b" ])
91
89
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"))
90
+ def f1 (gb : ResamplerGroupBy ):
91
+ check (gb , PeriodIndexResamplerGroupby )
97
92
98
- check (df .groupby ("a" ).resample ("3min" ), PeriodIndexResamplerGroupby )
93
+ f1 (df .groupby ("a" ).resample ("3min" ))
99
94
100
95
101
96
def test_natype () -> None :
@@ -204,17 +199,17 @@ def f1(gb: Window):
204
199
f1 (ser .rolling (2 , win_type = "gaussian" ))
205
200
206
201
207
- def test_statereader (tmp_path : Path ) -> None :
202
+ def test_statereader () -> None :
208
203
df = pd .DataFrame ([[1 , 2 ], [3 , 4 ]], columns = ["col_1" , "col_2" ])
209
204
time_stamp = pd .Timestamp (2000 , 2 , 29 , 14 , 21 )
210
205
variable_labels = {"col_1" : "This is an example" }
211
- path = tmp_path / "file"
212
- df .to_stata (
213
- path , time_stamp = time_stamp , variable_labels = variable_labels , version = None
214
- )
206
+ with ensure_clean () as path :
207
+ df .to_stata (
208
+ path , time_stamp = time_stamp , variable_labels = variable_labels , version = None
209
+ )
215
210
216
- def f1 (gb : StataReader ):
217
- check (gb , StataReader )
211
+ def f1 (gb : StataReader ):
212
+ check (gb , StataReader )
218
213
219
- with StataReader (path ) as reader :
220
- f1 (reader )
214
+ with StataReader (path ) as reader :
215
+ f1 (reader )
0 commit comments