Skip to content

Introduction of RangeIndex #9977

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

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion pandas/core/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from pandas.core.categorical import Categorical
from pandas.core.groupby import Grouper
from pandas.core.format import set_eng_float_format
from pandas.core.index import Index, CategoricalIndex, Int64Index, Float64Index, MultiIndex
from pandas.core.index import Index, CategoricalIndex, Int64Index, RangeIndex, Float64Index, MultiIndex

from pandas.core.series import Series, TimeSeries
from pandas.core.frame import DataFrame
Expand Down
12 changes: 8 additions & 4 deletions pandas/core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def _check(cls, inst):
ABCCategoricalIndex = create_pandas_abc_type("ABCCategoricalIndex", "_typ", ("categoricalindex",))
ABCIndexClass = create_pandas_abc_type("ABCIndexClass", "_typ", ("index",
"int64index",
"rangeindex",
"float64index",
"multiindex",
"datetimeindex",
Expand Down Expand Up @@ -2142,10 +2143,8 @@ def is_bool_indexer(key):


def _default_index(n):
from pandas.core.index import Int64Index
values = np.arange(n, dtype=np.int64)
result = Int64Index(values,name=None)
result.is_unique = True
from pandas.core.index import RangeIndex
result = RangeIndex(0, int(n), name=None)
return result


Expand Down Expand Up @@ -2498,6 +2497,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
6 changes: 3 additions & 3 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -4826,7 +4826,7 @@ def extract_index(data):
% (lengths[0], len(index)))
raise ValueError(msg)
else:
index = Index(np.arange(lengths[0]))
index = _default_index(lengths[0])

return _ensure_index(index)

Expand Down Expand Up @@ -5043,11 +5043,11 @@ def convert(arr):


def _get_names_from_index(data):
index = lrange(len(data))
has_some_name = any([getattr(s, 'name', None) is not None for s in data])
if not has_some_name:
return index
return _default_index(len(data))

index = lrange(len(data))
count = 0
for i, s in enumerate(data):
n = getattr(s, 'name', None)
Expand Down
Loading