Skip to content

Commit 9b0e0dc

Browse files
dsm054stangirala
authored andcommitted
TST: verify we can add and subtract from indices (pandas-dev#8142) (pandas-dev#16629)
1 parent dd5d618 commit 9b0e0dc

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

pandas/tests/indexes/test_base.py

+19
Original file line numberDiff line numberDiff line change
@@ -1800,6 +1800,25 @@ 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+
delta = dtype(delta)
1808+
idx = pd.Index([10, 11, 12], dtype=dtype)
1809+
result = idx + delta
1810+
expected = pd.Index(idx.values + delta, dtype=dtype)
1811+
tm.assert_index_equal(result, expected)
1812+
1813+
# this subtraction used to fail
1814+
result = idx - delta
1815+
expected = pd.Index(idx.values - delta, dtype=dtype)
1816+
tm.assert_index_equal(result, expected)
1817+
1818+
tm.assert_index_equal(idx + idx, 2 * idx)
1819+
tm.assert_index_equal(idx - idx, 0 * idx)
1820+
assert not (idx - idx).empty
1821+
18031822

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

0 commit comments

Comments
 (0)