11"""Test module for classes in pandas.api.typing."""
22
3- from pathlib import Path
4-
53import numpy as np
64import pandas as pd
75from pandas ._testing import ensure_clean
2018 Rolling ,
2119 RollingGroupby ,
2220 SeriesGroupBy ,
21+ StataReader ,
2322 TimedeltaIndexResamplerGroupby ,
2423 TimeGrouper ,
2524 Window ,
3029from tests import check
3130
3231from pandas .io .json ._json import read_json
33- from pandas .io .stata import StataReader
32+
33+ ResamplerGroupBy = (
34+ DatetimeIndexResamplerGroupby
35+ | PeriodIndexResamplerGroupby
36+ | TimedeltaIndexResamplerGroupby
37+ )
3438
3539
3640def test_dataframegroupby ():
@@ -59,13 +63,10 @@ def tests_datetimeindexersamplergroupby() -> None:
5963 )
6064 gb_df = df .groupby ("col2" )
6165
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 )
6768
68- check (gb_df .resample ("ME" ), DatetimeIndexResamplerGroupby )
69+ f1 (gb_df .resample ("ME" ))
6970
7071
7172def test_timedeltaindexresamplergroupby () -> None :
@@ -75,27 +76,21 @@ def test_timedeltaindexresamplergroupby() -> None:
7576 )
7677 gb_df = df .groupby ("col2" )
7778
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 )
8381
84- check (gb_df .resample ("1D" ), TimedeltaIndexResamplerGroupby )
82+ f1 (gb_df .resample ("1D" ))
8583
8684
8785@pytest .mark .skip ("Resampling with a PeriodIndex is deprecated." )
8886def test_periodindexresamplergroupby () -> None :
8987 idx = pd .period_range ("2020-01-28 09:00" , periods = 4 , freq = "D" )
9088 df = pd .DataFrame (data = 4 * [range (2 )], index = idx , columns = ["a" , "b" ])
9189
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 )
9792
98- check (df .groupby ("a" ).resample ("3min" ), PeriodIndexResamplerGroupby )
93+ f1 (df .groupby ("a" ).resample ("3min" ))
9994
10095
10196def test_natype () -> None :
@@ -204,17 +199,17 @@ def f1(gb: Window):
204199 f1 (ser .rolling (2 , win_type = "gaussian" ))
205200
206201
207- def test_statereader (tmp_path : Path ) -> None :
202+ def test_statereader () -> None :
208203 df = pd .DataFrame ([[1 , 2 ], [3 , 4 ]], columns = ["col_1" , "col_2" ])
209204 time_stamp = pd .Timestamp (2000 , 2 , 29 , 14 , 21 )
210205 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+ )
215210
216- def f1 (gb : StataReader ):
217- check (gb , StataReader )
211+ def f1 (gb : StataReader ):
212+ check (gb , StataReader )
218213
219- with StataReader (path ) as reader :
220- f1 (reader )
214+ with StataReader (path ) as reader :
215+ f1 (reader )
0 commit comments