Skip to content

Commit

Permalink
TST: verify we can add and subtract from indices (pandas-dev#8142)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsm054 committed Jun 8, 2017
1 parent 10c17d4 commit da22c0a
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions pandas/tests/indexes/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1800,6 +1800,24 @@ def test_string_index_repr(self):

assert coerce(idx) == expected

@pytest.mark.parametrize('dtype', [np.int64, np.float64])
@pytest.mark.parametrize('delta', [1, 0, -1])
def test_addsub_arithmetic(self, dtype, delta):
# GH 8142
idx = pd.Index([10, 11, 12], dtype=dtype)
result = idx + dtype(delta)
expected = pd.Index(idx.values + dtype(delta), dtype=dtype)
tm.assert_index_equal(result, expected)

# this subtraction used to fail
result = idx - dtype(delta)
expected = pd.Index(idx.values - dtype(delta), dtype=dtype)
tm.assert_index_equal(result, expected)

tm.assert_index_equal(idx + idx, 2 * idx)
tm.assert_index_equal(idx - idx, 0 * idx)
assert not (idx - idx).empty


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

0 comments on commit da22c0a

Please sign in to comment.