Skip to content

Commit 8bbfea4

Browse files
tests
1 parent 7c9ba0d commit 8bbfea4

File tree

2 files changed

+42
-24
lines changed

2 files changed

+42
-24
lines changed

pandas/core/arrays/period.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ def to_timestamp(self, freq=None, how: str = "start") -> DatetimeArray:
825825
is_start = how == "S"
826826
if is_start:
827827
new_data = np.asarray(
828-
[getattr(period, "start_time", period) for period in new_parr]
828+
[(NaT if period is NaT else period.start_time) for period in new_parr]
829829
)
830830
else:
831831
new_data = libperiod.periodarr_to_dt64arr(new_parr.asi8, base)

pandas/tests/resample/test_period_index.py

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -127,20 +127,30 @@ def test_selection(self, freq, kwargs):
127127

128128
@pytest.mark.parametrize("month", MONTHS)
129129
@pytest.mark.parametrize("meth", ["ffill", "bfill"])
130-
@pytest.mark.parametrize("conv", ["start", "end"])
131130
@pytest.mark.parametrize(
132-
("offset", "period"), [("D", "D"), ("B", "B"), ("ME", "M"), ("QE", "Q")]
131+
("offset", "period", "conv"),
132+
[
133+
("D", "D", "start"),
134+
("D", "D", "end"),
135+
("B", "B", "start"),
136+
("B", "B", "end"),
137+
("MS", "M", "start"),
138+
("ME", "M", "end"),
139+
("QS", "Q", "start"),
140+
("QE", "Q", "end"),
141+
],
133142
)
134143
def test_annual_upsample_cases(
135144
self, offset, period, conv, meth, month, simple_period_range_series
136145
):
137146
ts = simple_period_range_series("1/1/1990", "12/31/1991", freq=f"Y-{month}")
138-
warn = FutureWarning if period == "B" else None
139-
msg = r"PeriodDtype\[B\] is deprecated"
140-
if warn is None:
141-
msg = "Resampling with a PeriodIndex is deprecated"
142-
warn = FutureWarning
143-
with tm.assert_produces_warning(warn, match=msg):
147+
148+
msg = (
149+
r"PeriodDtype\[B\] is deprecated"
150+
if period == "B"
151+
else "Resampling with a PeriodIndex is deprecated"
152+
)
153+
with tm.assert_produces_warning(FutureWarning, match=msg):
144154
result = getattr(ts.resample(period, convention=conv), meth)()
145155
expected = result.to_timestamp(period, how=conv)
146156
expected = expected.asfreq(offset, meth).to_period()
@@ -217,21 +227,29 @@ def test_annual_upsample2(self):
217227
tm.assert_series_equal(result, expected)
218228

219229
@pytest.mark.parametrize("month", MONTHS)
220-
@pytest.mark.parametrize("convention", ["start", "end"])
221230
@pytest.mark.parametrize(
222-
("offset", "period"), [("D", "D"), ("B", "B"), ("ME", "M")]
231+
("offset", "period", "convention"),
232+
[
233+
("D", "D", "start"),
234+
("D", "D", "end"),
235+
("B", "B", "start"),
236+
("B", "B", "end"),
237+
("MS", "M", "start"),
238+
("ME", "M", "end"),
239+
],
223240
)
224241
def test_quarterly_upsample(
225242
self, month, offset, period, convention, simple_period_range_series
226243
):
227244
freq = f"Q-{month}"
228245
ts = simple_period_range_series("1/1/1990", "12/31/1995", freq=freq)
229-
warn = FutureWarning if period == "B" else None
230-
msg = r"PeriodDtype\[B\] is deprecated"
231-
if warn is None:
232-
msg = "Resampling with a PeriodIndex is deprecated"
233-
warn = FutureWarning
234-
with tm.assert_produces_warning(warn, match=msg):
246+
247+
msg = (
248+
r"PeriodDtype\[B\] is deprecated"
249+
if period == "B"
250+
else "Resampling with a PeriodIndex is deprecated"
251+
)
252+
with tm.assert_produces_warning(FutureWarning, match=msg):
235253
result = ts.resample(period, convention=convention).ffill()
236254
expected = result.to_timestamp(period, how=convention)
237255
expected = expected.asfreq(offset, "ffill").to_period()
@@ -242,12 +260,12 @@ def test_quarterly_upsample(
242260
def test_monthly_upsample(self, target, convention, simple_period_range_series):
243261
ts = simple_period_range_series("1/1/1990", "12/31/1995", freq="M")
244262

245-
warn = None if target == "D" else FutureWarning
246-
msg = r"PeriodDtype\[B\] is deprecated"
247-
if warn is None:
248-
msg = "Resampling with a PeriodIndex is deprecated"
249-
warn = FutureWarning
250-
with tm.assert_produces_warning(warn, match=msg):
263+
msg = (
264+
"Resampling with a PeriodIndex is deprecated"
265+
if target == "D"
266+
else r"PeriodDtype\[B\] is deprecated"
267+
)
268+
with tm.assert_produces_warning(FutureWarning, match=msg):
251269
result = ts.resample(target, convention=convention).ffill()
252270
expected = result.to_timestamp(target, how=convention)
253271
expected = expected.asfreq(target, "ffill").to_period()
@@ -923,7 +941,7 @@ def test_resample_with_offset_month(self):
923941
rs = ser.resample("M", offset="3h")
924942
result = rs.mean()
925943
result = result.to_timestamp("M")
926-
expected = ser.to_timestamp().resample("ME", offset="3h").mean()
944+
expected = ser.to_timestamp().resample("MS", offset="3h").mean()
927945
# TODO: is non-tick the relevant characteristic? (GH 33815)
928946
expected.index = expected.index._with_freq(None)
929947
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)