Skip to content

Separate test_numeric_compat into method-specific tests #19321

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 3 commits into from
Jan 21, 2018
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
69 changes: 55 additions & 14 deletions pandas/tests/indexes/test_numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,21 @@ def full_like(array, value):
class Numeric(Base):

def test_numeric_compat(self):
pass # override Base method

def test_mul_int(self):
idx = self.create_index()
didx = idx * idx

result = idx * 1
tm.assert_index_equal(result, idx)

def test_rmul_int(self):
idx = self.create_index()

result = 1 * idx
tm.assert_index_equal(result, idx)

# in general not true for RangeIndex
if not isinstance(idx, RangeIndex):
result = idx * idx
tm.assert_index_equal(result, idx ** 2)
def test_div_int(self):
idx = self.create_index()

# truediv under PY3
result = idx / 1
Expand All @@ -57,29 +58,62 @@ def test_numeric_compat(self):
expected = Index(idx.values / 2)
tm.assert_index_equal(result, expected)

def test_floordiv_int(self):
idx = self.create_index()

result = idx // 1
tm.assert_index_equal(result, idx)

def test_mul_int_array(self):
idx = self.create_index()
didx = idx * idx

result = idx * np.array(5, dtype='int64')
tm.assert_index_equal(result, idx * 5)

arr_dtype = 'uint64' if isinstance(idx, UInt64Index) else 'int64'
result = idx * np.arange(5, dtype=arr_dtype)
tm.assert_index_equal(result, didx)

def test_mul_int_series(self):
idx = self.create_index()
didx = idx * idx

arr_dtype = 'uint64' if isinstance(idx, UInt64Index) else 'int64'
result = idx * Series(np.arange(5, dtype=arr_dtype))
tm.assert_series_equal(result, Series(didx))

def test_mul_float_series(self):
idx = self.create_index()
rng5 = np.arange(5, dtype='float64')

result = idx * Series(rng5 + 0.1)
expected = Series(rng5 * (rng5 + 0.1))
tm.assert_series_equal(result, expected)

# invalid
pytest.raises(TypeError,
lambda: idx * date_range('20130101', periods=5))
pytest.raises(ValueError, lambda: idx * idx[0:3])
pytest.raises(ValueError, lambda: idx * np.array([1, 2]))
def test_mul_index(self):
idx = self.create_index()

# in general not true for RangeIndex
if not isinstance(idx, RangeIndex):
result = idx * idx
tm.assert_index_equal(result, idx ** 2)

def test_mul_datelike_raises(self):
idx = self.create_index()
with pytest.raises(TypeError):
idx * date_range('20130101', periods=5)

def test_mul_size_mismatch_raises(self):
idx = self.create_index()

with pytest.raises(ValueError):
idx * idx[0:3]
with pytest.raises(ValueError):
idx * np.array([1, 2])

def test_divmod(self):
idx = self.create_index()

result = divmod(idx, 2)
with np.errstate(all='ignore'):
Expand All @@ -95,15 +129,22 @@ def test_numeric_compat(self):
for r, e in zip(result, expected):
tm.assert_index_equal(r, e)

def test_pow_float(self):
# test power calculations both ways, GH 14973
expected = pd.Float64Index(2.0**idx.values)
result = 2.0**idx
tm.assert_index_equal(result, expected)
idx = self.create_index()

expected = pd.Float64Index(idx.values**2.0)
result = idx**2.0
tm.assert_index_equal(result, expected)

def test_rpow_float(self):
# test power calculations both ways, GH 14973
idx = self.create_index()

expected = pd.Float64Index(2.0**idx.values)
result = 2.0**idx
tm.assert_index_equal(result, expected)

@pytest.mark.xfail(reason='GH#19252 Series has no __rdivmod__')
def test_divmod_series(self):
idx = self.create_index()
Expand Down