1111from pandas .core .indexes .datetimes import date_range
1212from pandas .core .indexes .period import PeriodIndex , period_range
1313from pandas .core .indexes .timedeltas import TimedeltaIndex , timedelta_range
14+ from pandas .core .resample import _asfreq_compat
1415
1516# a fixture value can be overridden by the test parameter value. Note that the
1617# value of the fixture can be overridden this way even if the test doesn't use
@@ -103,10 +104,8 @@ def test_resample_empty_series(freq, empty_series, resample_method):
103104 result = getattr (s .resample (freq ), resample_method )()
104105
105106 expected = s .copy ()
106- if isinstance (s .index , PeriodIndex ):
107- expected .index = s .index .asfreq (freq = freq )
108- else :
109- expected .index = s .index ._shallow_copy (freq = freq )
107+ expected .index = _asfreq_compat (s .index , freq )
108+
110109 tm .assert_index_equal (result .index , expected .index )
111110 assert result .index .freq == expected .index .freq
112111 tm .assert_series_equal (result , expected , check_dtype = False )
@@ -119,10 +118,8 @@ def test_resample_count_empty_series(freq, empty_series, resample_method):
119118 # GH28427
120119 result = getattr (empty_series .resample (freq ), resample_method )()
121120
122- if isinstance (empty_series .index , PeriodIndex ):
123- index = empty_series .index .asfreq (freq = freq )
124- else :
125- index = empty_series .index ._shallow_copy (freq = freq )
121+ index = _asfreq_compat (empty_series .index , freq )
122+
126123 expected = pd .Series ([], dtype = "int64" , index = index , name = empty_series .name )
127124
128125 tm .assert_series_equal (result , expected )
@@ -141,10 +138,8 @@ def test_resample_empty_dataframe(empty_frame, freq, resample_method):
141138 # GH14962
142139 expected = Series ([], dtype = object )
143140
144- if isinstance (df .index , PeriodIndex ):
145- expected .index = df .index .asfreq (freq = freq )
146- else :
147- expected .index = df .index ._shallow_copy (freq = freq )
141+ expected .index = _asfreq_compat (df .index , freq )
142+
148143 tm .assert_index_equal (result .index , expected .index )
149144 assert result .index .freq == expected .index .freq
150145 tm .assert_almost_equal (result , expected , check_dtype = False )
@@ -162,10 +157,8 @@ def test_resample_count_empty_dataframe(freq, empty_frame):
162157
163158 result = empty_frame .resample (freq ).count ()
164159
165- if isinstance (empty_frame .index , PeriodIndex ):
166- index = empty_frame .index .asfreq (freq = freq )
167- else :
168- index = empty_frame .index ._shallow_copy (freq = freq )
160+ index = _asfreq_compat (empty_frame .index , freq )
161+
169162 expected = pd .DataFrame ({"a" : []}, dtype = "int64" , index = index )
170163
171164 tm .assert_frame_equal (result , expected )
@@ -181,10 +174,8 @@ def test_resample_size_empty_dataframe(freq, empty_frame):
181174
182175 result = empty_frame .resample (freq ).size ()
183176
184- if isinstance (empty_frame .index , PeriodIndex ):
185- index = empty_frame .index .asfreq (freq = freq )
186- else :
187- index = empty_frame .index ._shallow_copy (freq = freq )
177+ index = _asfreq_compat (empty_frame .index , freq )
178+
188179 expected = pd .Series ([], dtype = "int64" , index = index )
189180
190181 tm .assert_series_equal (result , expected )
0 commit comments