Skip to content

Commit a123c74

Browse files
natmokvalim-vinicius
authored and
im-vinicius
committed
TST: add the parameter MonthEnd(2) to 2 tests with freq= 2M (pandas-dev#53916)
TST: add the parameter MonthEnd(2) to some tests with freq= 2M
1 parent 3ada856 commit a123c74

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

pandas/tests/arrays/period/test_constructors.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import pytest
33

44
from pandas._libs.tslibs import iNaT
5+
from pandas._libs.tslibs.offsets import MonthEnd
56
from pandas._libs.tslibs.period import IncompatibleFrequency
67

78
import pandas as pd
@@ -56,12 +57,13 @@ def test_from_datetime64_freq_changes():
5657
tm.assert_period_array_equal(result, expected)
5758

5859

59-
def test_from_datetime64_freq_2M():
60+
@pytest.mark.parametrize("freq", ["2M", MonthEnd(2)])
61+
def test_from_datetime64_freq_2M(freq):
6062
arr = np.array(
6163
["2020-01-01T00:00:00", "2020-01-02T00:00:00"], dtype="datetime64[ns]"
6264
)
63-
result = PeriodArray._from_datetime64(arr, "2M")
64-
expected = period_array(["2020-01", "2020-01"], freq="2M")
65+
result = PeriodArray._from_datetime64(arr, freq)
66+
expected = period_array(["2020-01", "2020-01"], freq=freq)
6567
tm.assert_period_array_equal(result, expected)
6668

6769

pandas/tests/frame/methods/test_asfreq.py

+13-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import numpy as np
44
import pytest
55

6+
from pandas._libs.tslibs.offsets import MonthEnd
7+
68
from pandas import (
79
DataFrame,
810
DatetimeIndex,
@@ -212,11 +214,18 @@ def test_asfreq_after_normalize(self, unit):
212214
expected = DatetimeIndex(["2000-01-01", "2000-01-02"], freq="D").as_unit(unit)
213215
tm.assert_index_equal(result, expected)
214216

215-
def test_asfreq_2M(self):
216-
index = date_range("1/1/2000", periods=6, freq="M")
217+
@pytest.mark.parametrize(
218+
"freq, freq_half",
219+
[
220+
("2M", "M"),
221+
(MonthEnd(2), MonthEnd(1)),
222+
],
223+
)
224+
def test_asfreq_2M(self, freq, freq_half):
225+
index = date_range("1/1/2000", periods=6, freq=freq_half)
217226
df = DataFrame({"s": Series([0.0, 1.0, 2.0, 3.0, 4.0, 5.0], index=index)})
218-
expected = df.asfreq(freq="2M")
227+
expected = df.asfreq(freq=freq)
219228

220-
index = date_range("1/1/2000", periods=3, freq="2M")
229+
index = date_range("1/1/2000", periods=3, freq=freq)
221230
result = DataFrame({"s": Series([0.0, 2.0, 4.0], index=index)})
222231
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)