Skip to content

TST: move index tests to correct files (#27045) #42952

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

Merged
merged 5 commits into from
Aug 10, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
24 changes: 24 additions & 0 deletions pandas/tests/tseries/offsets/test_business_month.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import pytest

import pandas as pd
from pandas.tests.tseries.offsets.common import (
Base,
assert_is_on_offset,
Expand All @@ -19,6 +20,29 @@
)


@pytest.mark.parametrize("n", [-2, 1])
@pytest.mark.parametrize(
"cls",
[
BMonthBegin,
BMonthEnd,
],
)
def test_apply_index(cls, n):
offset = cls(n=n)
rng = pd.date_range(start="1/1/2000", periods=100000, freq="T")
ser = pd.Series(rng)

res = rng + offset
assert res.freq is None # not retained
assert res[0] == rng[0] + offset
assert res[-1] == rng[-1] + offset
res2 = ser + offset
# apply_index is only for indexes, not series, so no res2_v2
assert res2.iloc[0] == ser.iloc[0] + offset
assert res2.iloc[-1] == ser.iloc[-1] + offset


class TestBMonthBegin(Base):
_offset = BMonthBegin

Expand Down
24 changes: 24 additions & 0 deletions pandas/tests/tseries/offsets/test_business_quarter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import pytest

import pandas as pd
from pandas.tests.tseries.offsets.common import (
Base,
assert_is_on_offset,
Expand All @@ -19,6 +20,29 @@
)


@pytest.mark.parametrize("n", [-2, 1])
@pytest.mark.parametrize(
"cls",
[
BQuarterBegin,
BQuarterEnd,
],
)
def test_apply_index(cls, n):
offset = cls(n=n)
rng = pd.date_range(start="1/1/2000", periods=100000, freq="T")
ser = pd.Series(rng)

res = rng + offset
assert res.freq is None # not retained
assert res[0] == rng[0] + offset
assert res[-1] == rng[-1] + offset
res2 = ser + offset
# apply_index is only for indexes, not series, so no res2_v2
assert res2.iloc[0] == ser.iloc[0] + offset
assert res2.iloc[-1] == ser.iloc[-1] + offset


def test_quarterly_dont_normalize():
date = datetime(2012, 3, 31, 5, 30)

Expand Down
24 changes: 24 additions & 0 deletions pandas/tests/tseries/offsets/test_business_year.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import pytest

import pandas as pd
from pandas.tests.tseries.offsets.common import (
Base,
assert_is_on_offset,
Expand All @@ -19,6 +20,29 @@
)


@pytest.mark.parametrize("n", [-2, 1])
@pytest.mark.parametrize(
"cls",
[
BYearBegin,
BYearEnd,
],
)
def test_apply_index(cls, n):
offset = cls(n=n)
rng = pd.date_range(start="1/1/2000", periods=100000, freq="T")
ser = pd.Series(rng)

res = rng + offset
assert res.freq is None # not retained
assert res[0] == rng[0] + offset
assert res[-1] == rng[-1] + offset
res2 = ser + offset
# apply_index is only for indexes, not series, so no res2_v2
assert res2.iloc[0] == ser.iloc[0] + offset
assert res2.iloc[-1] == ser.iloc[-1] + offset


class TestBYearBegin(Base):
_offset = BYearBegin

Expand Down
24 changes: 24 additions & 0 deletions pandas/tests/tseries/offsets/test_month.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
SemiMonthEnd,
)

import pandas as pd
from pandas import (
DatetimeIndex,
Series,
Expand All @@ -30,6 +31,29 @@
)


@pytest.mark.parametrize("n", [-2, 1])
@pytest.mark.parametrize(
"cls",
[
MonthBegin,
MonthEnd,
],
)
def test_apply_index(cls, n):
offset = cls(n=n)
rng = pd.date_range(start="1/1/2000", periods=100000, freq="T")
ser = pd.Series(rng)

res = rng + offset
assert res.freq is None # not retained
assert res[0] == rng[0] + offset
assert res[-1] == rng[-1] + offset
res2 = ser + offset
# apply_index is only for indexes, not series, so no res2_v2
assert res2.iloc[0] == ser.iloc[0] + offset
assert res2.iloc[-1] == ser.iloc[-1] + offset


class TestSemiMonthEnd(Base):
_offset = SemiMonthEnd
offset1 = _offset()
Expand Down
24 changes: 24 additions & 0 deletions pandas/tests/tseries/offsets/test_quarter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import pytest

import pandas as pd
from pandas.tests.tseries.offsets.common import (
Base,
assert_is_on_offset,
Expand All @@ -19,6 +20,29 @@
)


@pytest.mark.parametrize("n", [-2, 1])
@pytest.mark.parametrize(
"cls",
[
QuarterBegin,
QuarterEnd,
],
)
def test_apply_index(cls, n):
offset = cls(n=n)
rng = pd.date_range(start="1/1/2000", periods=100000, freq="T")
ser = pd.Series(rng)

res = rng + offset
assert res.freq is None # not retained
assert res[0] == rng[0] + offset
assert res[-1] == rng[-1] + offset
res2 = ser + offset
# apply_index is only for indexes, not series, so no res2_v2
assert res2.iloc[0] == ser.iloc[0] + offset
assert res2.iloc[-1] == ser.iloc[-1] + offset


def test_quarterly_dont_normalize():
date = datetime(2012, 3, 31, 5, 30)

Expand Down
24 changes: 24 additions & 0 deletions pandas/tests/tseries/offsets/test_year.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import pytest

import pandas as pd
from pandas.tests.tseries.offsets.common import (
Base,
assert_is_on_offset,
Expand All @@ -19,6 +20,29 @@
)


@pytest.mark.parametrize("n", [-2, 1])
@pytest.mark.parametrize(
"cls",
[
YearBegin,
YearEnd,
],
)
def test_apply_index(cls, n):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't want to have this test duplicated in a bunch of places

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally understandable. Consolidated those into a different file.

offset = cls(n=n)
rng = pd.date_range(start="1/1/2000", periods=100000, freq="T")
ser = pd.Series(rng)

res = rng + offset
assert res.freq is None # not retained
assert res[0] == rng[0] + offset
assert res[-1] == rng[-1] + offset
res2 = ser + offset
# apply_index is only for indexes, not series, so no res2_v2
assert res2.iloc[0] == ser.iloc[0] + offset
assert res2.iloc[-1] == ser.iloc[-1] + offset


class TestYearBegin(Base):
_offset = YearBegin

Expand Down