Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TST: add the parameter MonthEnd(2) to 2 tests with freq= 2M #53916

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions pandas/tests/arrays/period/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)


Expand Down
17 changes: 13 additions & 4 deletions pandas/tests/frame/methods/test_asfreq.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import numpy as np
import pytest

from pandas._libs.tslibs.offsets import MonthEnd

from pandas import (
DataFrame,
DatetimeIndex,
Expand Down Expand Up @@ -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)