11
11
from pandas .core .indexes .datetimes import date_range
12
12
from pandas .core .indexes .period import PeriodIndex , period_range
13
13
from pandas .core .indexes .timedeltas import TimedeltaIndex , timedelta_range
14
+ from pandas .core .resample import _asfreq_compat
14
15
15
16
# a fixture value can be overridden by the test parameter value. Note that the
16
17
# 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):
103
104
result = getattr (s .resample (freq ), resample_method )()
104
105
105
106
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
+
110
109
tm .assert_index_equal (result .index , expected .index )
111
110
assert result .index .freq == expected .index .freq
112
111
tm .assert_series_equal (result , expected , check_dtype = False )
@@ -119,10 +118,8 @@ def test_resample_count_empty_series(freq, empty_series, resample_method):
119
118
# GH28427
120
119
result = getattr (empty_series .resample (freq ), resample_method )()
121
120
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
+
126
123
expected = pd .Series ([], dtype = "int64" , index = index , name = empty_series .name )
127
124
128
125
tm .assert_series_equal (result , expected )
@@ -141,10 +138,8 @@ def test_resample_empty_dataframe(empty_frame, freq, resample_method):
141
138
# GH14962
142
139
expected = Series ([], dtype = object )
143
140
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
+
148
143
tm .assert_index_equal (result .index , expected .index )
149
144
assert result .index .freq == expected .index .freq
150
145
tm .assert_almost_equal (result , expected , check_dtype = False )
@@ -162,10 +157,8 @@ def test_resample_count_empty_dataframe(freq, empty_frame):
162
157
163
158
result = empty_frame .resample (freq ).count ()
164
159
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
+
169
162
expected = pd .DataFrame ({"a" : []}, dtype = "int64" , index = index )
170
163
171
164
tm .assert_frame_equal (result , expected )
@@ -181,10 +174,8 @@ def test_resample_size_empty_dataframe(freq, empty_frame):
181
174
182
175
result = empty_frame .resample (freq ).size ()
183
176
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
+
188
179
expected = pd .Series ([], dtype = "int64" , index = index )
189
180
190
181
tm .assert_series_equal (result , expected )
0 commit comments