Skip to content

ENH: RangeIndex redux #11892

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 6 commits into from
Jan 16, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
make floordiv return int64index always
  • Loading branch information
jreback committed Jan 16, 2016
commit fab291b306ebf8b89d094379c99bd1b2a2b601b9
5 changes: 5 additions & 0 deletions pandas/core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2199,6 +2199,11 @@ def is_integer_dtype(arr_or_dtype):
not issubclass(tipo, (np.datetime64, np.timedelta64)))


def is_int64_dtype(arr_or_dtype):
tipo = _get_dtype_type(arr_or_dtype)
return issubclass(tipo, np.int64)


def is_int_or_datetime_dtype(arr_or_dtype):
tipo = _get_dtype_type(arr_or_dtype)
return (issubclass(tipo, np.integer) or
Expand Down
15 changes: 3 additions & 12 deletions pandas/core/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -3995,8 +3995,8 @@ def from_range(cls, data, name=None, dtype=None, **kwargs):
stop = data.stop
start = data.start
else:
# seems we only have indexing ops to infer
# rather than direct accessors
# seems we only have indexing ops to infer
# rather than direct accessors
if len(data) > 1:
step = data[1] - data[0]
stop = data[-1] + step
Expand Down Expand Up @@ -4395,7 +4395,7 @@ def _evaluate_numeric_binop(self, other):

# we don't have a representable op
# so return a base index
if not is_integer(rstep):
if not is_integer(rstep) or not rstep:
raise ValueError

else:
Expand Down Expand Up @@ -4440,15 +4440,6 @@ def _evaluate_numeric_binop(self, other):
operator.mul,
'__mul__',
step=operator.mul)
cls.__floordiv__ = _make_evaluate_binop(
operator.floordiv,
'__floordiv__',
step=operator.floordiv)
cls.__rfloordiv__ = _make_evaluate_binop(
operator.floordiv,
'__floordiv__',
reversed=True,
step=operator.floordiv)
cls.__truediv__ = _make_evaluate_binop(
operator.truediv,
'__truediv__',
Expand Down
11 changes: 6 additions & 5 deletions pandas/tests/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from pandas import compat
from pandas.compat import (long, is_platform_windows, range,
lrange, lzip, u, zip, PY3)
from itertools import combinations
import operator
import re
import nose
Expand Down Expand Up @@ -3465,9 +3466,8 @@ def create_index(self):
return RangeIndex(5)

def test_binops(self):
import operator as op
from itertools import combinations
ops = [op.add, op.sub, op.mul, op.floordiv, op.truediv, pow]
ops = [operator.add, operator.sub, operator.mul,
operator.floordiv, operator.truediv, pow]
scalars = [-1, 1, 2]
idxs = [RangeIndex(0, 10, 1),
RangeIndex(0, 20, 2),
Expand Down Expand Up @@ -3611,7 +3611,8 @@ def test_numeric_compat2(self):
self.assertTrue(result.equals(expected))

result = idx // 1
tm.assert_index_equal(result, idx, exact=True)
expected = idx._int64index // 1
tm.assert_index_equal(result, expected, exact=True)

# __mul__
result = idx * idx
Expand All @@ -3627,7 +3628,7 @@ def test_numeric_compat2(self):
# __floordiv__
idx = RangeIndex(0, 1000, 2)
result = idx // 2
expected = RangeIndex(0, 500, 1)
expected = idx._int64index // 2
tm.assert_index_equal(result, expected, exact=True)

idx = RangeIndex(0, 1000, 1)
Expand Down