Skip to content

Commit be1eb3e

Browse files
committed
TST: move index tests to correct files (pandas-dev#27045)
1 parent 4f0e2e9 commit be1eb3e

File tree

6 files changed

+144
-0
lines changed

6 files changed

+144
-0
lines changed

pandas/tests/tseries/offsets/test_business_month.py

+24
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import pytest
99

10+
import pandas as pd
1011
from pandas.tests.tseries.offsets.common import (
1112
Base,
1213
assert_is_on_offset,
@@ -19,6 +20,29 @@
1920
)
2021

2122

23+
@pytest.mark.parametrize("n", [-2, 1])
24+
@pytest.mark.parametrize(
25+
"cls",
26+
[
27+
BMonthBegin,
28+
BMonthEnd,
29+
],
30+
)
31+
def test_apply_index(cls, n):
32+
offset = cls(n=n)
33+
rng = pd.date_range(start="1/1/2000", periods=100000, freq="T")
34+
ser = pd.Series(rng)
35+
36+
res = rng + offset
37+
assert res.freq is None # not retained
38+
assert res[0] == rng[0] + offset
39+
assert res[-1] == rng[-1] + offset
40+
res2 = ser + offset
41+
# apply_index is only for indexes, not series, so no res2_v2
42+
assert res2.iloc[0] == ser.iloc[0] + offset
43+
assert res2.iloc[-1] == ser.iloc[-1] + offset
44+
45+
2246
class TestBMonthBegin(Base):
2347
_offset = BMonthBegin
2448

pandas/tests/tseries/offsets/test_business_quarter.py

+24
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import pytest
99

10+
import pandas as pd
1011
from pandas.tests.tseries.offsets.common import (
1112
Base,
1213
assert_is_on_offset,
@@ -19,6 +20,29 @@
1920
)
2021

2122

23+
@pytest.mark.parametrize("n", [-2, 1])
24+
@pytest.mark.parametrize(
25+
"cls",
26+
[
27+
BQuarterBegin,
28+
BQuarterEnd,
29+
],
30+
)
31+
def test_apply_index(cls, n):
32+
offset = cls(n=n)
33+
rng = pd.date_range(start="1/1/2000", periods=100000, freq="T")
34+
ser = pd.Series(rng)
35+
36+
res = rng + offset
37+
assert res.freq is None # not retained
38+
assert res[0] == rng[0] + offset
39+
assert res[-1] == rng[-1] + offset
40+
res2 = ser + offset
41+
# apply_index is only for indexes, not series, so no res2_v2
42+
assert res2.iloc[0] == ser.iloc[0] + offset
43+
assert res2.iloc[-1] == ser.iloc[-1] + offset
44+
45+
2246
def test_quarterly_dont_normalize():
2347
date = datetime(2012, 3, 31, 5, 30)
2448

pandas/tests/tseries/offsets/test_business_year.py

+24
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import pytest
99

10+
import pandas as pd
1011
from pandas.tests.tseries.offsets.common import (
1112
Base,
1213
assert_is_on_offset,
@@ -19,6 +20,29 @@
1920
)
2021

2122

23+
@pytest.mark.parametrize("n", [-2, 1])
24+
@pytest.mark.parametrize(
25+
"cls",
26+
[
27+
BYearBegin,
28+
BYearEnd,
29+
],
30+
)
31+
def test_apply_index(cls, n):
32+
offset = cls(n=n)
33+
rng = pd.date_range(start="1/1/2000", periods=100000, freq="T")
34+
ser = pd.Series(rng)
35+
36+
res = rng + offset
37+
assert res.freq is None # not retained
38+
assert res[0] == rng[0] + offset
39+
assert res[-1] == rng[-1] + offset
40+
res2 = ser + offset
41+
# apply_index is only for indexes, not series, so no res2_v2
42+
assert res2.iloc[0] == ser.iloc[0] + offset
43+
assert res2.iloc[-1] == ser.iloc[-1] + offset
44+
45+
2246
class TestBYearBegin(Base):
2347
_offset = BYearBegin
2448

pandas/tests/tseries/offsets/test_month.py

+24
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
SemiMonthEnd,
1818
)
1919

20+
import pandas as pd
2021
from pandas import (
2122
DatetimeIndex,
2223
Series,
@@ -30,6 +31,29 @@
3031
)
3132

3233

34+
@pytest.mark.parametrize("n", [-2, 1])
35+
@pytest.mark.parametrize(
36+
"cls",
37+
[
38+
MonthBegin,
39+
MonthEnd,
40+
],
41+
)
42+
def test_apply_index(cls, n):
43+
offset = cls(n=n)
44+
rng = pd.date_range(start="1/1/2000", periods=100000, freq="T")
45+
ser = pd.Series(rng)
46+
47+
res = rng + offset
48+
assert res.freq is None # not retained
49+
assert res[0] == rng[0] + offset
50+
assert res[-1] == rng[-1] + offset
51+
res2 = ser + offset
52+
# apply_index is only for indexes, not series, so no res2_v2
53+
assert res2.iloc[0] == ser.iloc[0] + offset
54+
assert res2.iloc[-1] == ser.iloc[-1] + offset
55+
56+
3357
class TestSemiMonthEnd(Base):
3458
_offset = SemiMonthEnd
3559
offset1 = _offset()

pandas/tests/tseries/offsets/test_quarter.py

+24
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import pytest
99

10+
import pandas as pd
1011
from pandas.tests.tseries.offsets.common import (
1112
Base,
1213
assert_is_on_offset,
@@ -19,6 +20,29 @@
1920
)
2021

2122

23+
@pytest.mark.parametrize("n", [-2, 1])
24+
@pytest.mark.parametrize(
25+
"cls",
26+
[
27+
QuarterBegin,
28+
QuarterEnd,
29+
],
30+
)
31+
def test_apply_index(cls, n):
32+
offset = cls(n=n)
33+
rng = pd.date_range(start="1/1/2000", periods=100000, freq="T")
34+
ser = pd.Series(rng)
35+
36+
res = rng + offset
37+
assert res.freq is None # not retained
38+
assert res[0] == rng[0] + offset
39+
assert res[-1] == rng[-1] + offset
40+
res2 = ser + offset
41+
# apply_index is only for indexes, not series, so no res2_v2
42+
assert res2.iloc[0] == ser.iloc[0] + offset
43+
assert res2.iloc[-1] == ser.iloc[-1] + offset
44+
45+
2246
def test_quarterly_dont_normalize():
2347
date = datetime(2012, 3, 31, 5, 30)
2448

pandas/tests/tseries/offsets/test_year.py

+24
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import pytest
99

10+
import pandas as pd
1011
from pandas.tests.tseries.offsets.common import (
1112
Base,
1213
assert_is_on_offset,
@@ -19,6 +20,29 @@
1920
)
2021

2122

23+
@pytest.mark.parametrize("n", [-2, 1])
24+
@pytest.mark.parametrize(
25+
"cls",
26+
[
27+
YearBegin,
28+
YearEnd,
29+
],
30+
)
31+
def test_apply_index(cls, n):
32+
offset = cls(n=n)
33+
rng = pd.date_range(start="1/1/2000", periods=100000, freq="T")
34+
ser = pd.Series(rng)
35+
36+
res = rng + offset
37+
assert res.freq is None # not retained
38+
assert res[0] == rng[0] + offset
39+
assert res[-1] == rng[-1] + offset
40+
res2 = ser + offset
41+
# apply_index is only for indexes, not series, so no res2_v2
42+
assert res2.iloc[0] == ser.iloc[0] + offset
43+
assert res2.iloc[-1] == ser.iloc[-1] + offset
44+
45+
2246
class TestYearBegin(Base):
2347
_offset = YearBegin
2448

0 commit comments

Comments
 (0)