Skip to content

TST: verify we can add and subtract from indices (#8142) #16629

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 1 commit into from
Jun 8, 2017
Merged
Changes from all commits
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
19 changes: 19 additions & 0 deletions pandas/tests/indexes/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1800,6 +1800,25 @@ 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
delta = dtype(delta)
idx = pd.Index([10, 11, 12], dtype=dtype)
result = idx + delta
expected = pd.Index(idx.values + delta, dtype=dtype)
tm.assert_index_equal(result, expected)

# this subtraction used to fail
result = idx - delta
expected = pd.Index(idx.values - 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