Skip to content

Commit da22c0a

Browse files
committed
TST: verify we can add and subtract from indices (pandas-dev#8142)
1 parent 10c17d4 commit da22c0a

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

pandas/tests/indexes/test_base.py

+18
Original file line numberDiff line numberDiff line change
@@ -1800,6 +1800,24 @@ def test_string_index_repr(self):
18001800

18011801
assert coerce(idx) == expected
18021802

1803+
@pytest.mark.parametrize('dtype', [np.int64, np.float64])
1804+
@pytest.mark.parametrize('delta', [1, 0, -1])
1805+
def test_addsub_arithmetic(self, dtype, delta):
1806+
# GH 8142
1807+
idx = pd.Index([10, 11, 12], dtype=dtype)
1808+
result = idx + dtype(delta)
1809+
expected = pd.Index(idx.values + dtype(delta), dtype=dtype)
1810+
tm.assert_index_equal(result, expected)
1811+
1812+
# this subtraction used to fail
1813+
result = idx - dtype(delta)
1814+
expected = pd.Index(idx.values - dtype(delta), dtype=dtype)
1815+
tm.assert_index_equal(result, expected)
1816+
1817+
tm.assert_index_equal(idx + idx, 2 * idx)
1818+
tm.assert_index_equal(idx - idx, 0 * idx)
1819+
assert not (idx - idx).empty
1820+
18031821

18041822
class TestMixedIntIndex(Base):
18051823
# Mostly the tests from common.py for which the results differ

0 commit comments

Comments
 (0)