From 2aa5234a54844d1327da1d570024c426db62d75c Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Wed, 28 Jun 2023 23:45:36 +0200 Subject: [PATCH] TST: add the parameter MonthEnd(2) to some tests with freq= 2M --- pandas/tests/arrays/period/test_constructors.py | 8 +++++--- pandas/tests/frame/methods/test_asfreq.py | 17 +++++++++++++---- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/pandas/tests/arrays/period/test_constructors.py b/pandas/tests/arrays/period/test_constructors.py index 4e8ab56435749..ecc9ee745bad8 100644 --- a/pandas/tests/arrays/period/test_constructors.py +++ b/pandas/tests/arrays/period/test_constructors.py @@ -2,6 +2,7 @@ import pytest from pandas._libs.tslibs import iNaT +from pandas._libs.tslibs.offsets import MonthEnd from pandas._libs.tslibs.period import IncompatibleFrequency import pandas as pd @@ -56,12 +57,13 @@ def test_from_datetime64_freq_changes(): tm.assert_period_array_equal(result, expected) -def test_from_datetime64_freq_2M(): +@pytest.mark.parametrize("freq", ["2M", MonthEnd(2)]) +def test_from_datetime64_freq_2M(freq): arr = np.array( ["2020-01-01T00:00:00", "2020-01-02T00:00:00"], dtype="datetime64[ns]" ) - result = PeriodArray._from_datetime64(arr, "2M") - expected = period_array(["2020-01", "2020-01"], freq="2M") + result = PeriodArray._from_datetime64(arr, freq) + expected = period_array(["2020-01", "2020-01"], freq=freq) tm.assert_period_array_equal(result, expected) diff --git a/pandas/tests/frame/methods/test_asfreq.py b/pandas/tests/frame/methods/test_asfreq.py index 42997de78ecaa..a36f0d11fcfb4 100644 --- a/pandas/tests/frame/methods/test_asfreq.py +++ b/pandas/tests/frame/methods/test_asfreq.py @@ -3,6 +3,8 @@ import numpy as np import pytest +from pandas._libs.tslibs.offsets import MonthEnd + from pandas import ( DataFrame, DatetimeIndex, @@ -212,11 +214,18 @@ def test_asfreq_after_normalize(self, unit): expected = DatetimeIndex(["2000-01-01", "2000-01-02"], freq="D").as_unit(unit) tm.assert_index_equal(result, expected) - def test_asfreq_2M(self): - index = date_range("1/1/2000", periods=6, freq="M") + @pytest.mark.parametrize( + "freq, freq_half", + [ + ("2M", "M"), + (MonthEnd(2), MonthEnd(1)), + ], + ) + def test_asfreq_2M(self, freq, freq_half): + index = date_range("1/1/2000", periods=6, freq=freq_half) df = DataFrame({"s": Series([0.0, 1.0, 2.0, 3.0, 4.0, 5.0], index=index)}) - expected = df.asfreq(freq="2M") + expected = df.asfreq(freq=freq) - index = date_range("1/1/2000", periods=3, freq="2M") + index = date_range("1/1/2000", periods=3, freq=freq) result = DataFrame({"s": Series([0.0, 2.0, 4.0], index=index)}) tm.assert_frame_equal(result, expected)