Skip to content

CLN: use RangeIndex._range instead of RangeIndex._start etc. #26578

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 1 commit 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
21 changes: 11 additions & 10 deletions pandas/core/dtypes/concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,36 +541,37 @@ def _concat_rangeindex_same_dtype(indexes):
"""
from pandas import Int64Index, RangeIndex

start = step = next = None
start = step = next_ = None

# Filter the empty indexes
non_empty_indexes = [obj for obj in indexes if len(obj)]

for obj in non_empty_indexes:
rng = obj._range # type: range

if start is None:
# This is set by the first non-empty index
start = obj._start
if step is None and len(obj) > 1:
step = obj._step
start = rng.start
if step is None and len(rng) > 1:
step = rng.step
elif step is None:
# First non-empty index had only one element
if obj._start == start:
if rng.start == start:
return _concat_index_same_dtype(indexes, klass=Int64Index)
step = obj._start - start
step = rng.start - start

non_consecutive = ((step != obj._step and len(obj) > 1) or
(next is not None and obj._start != next))
non_consecutive = ((step != rng.step and len(rng) > 1) or
(next_ is not None and rng.start != next_))
if non_consecutive:
return _concat_index_same_dtype(indexes, klass=Int64Index)

if step is not None:
next = obj[-1] + step
next_ = rng[-1] + step

if non_empty_indexes:
# Get the stop value from "next" or alternatively
# from the last non-empty index
stop = non_empty_indexes[-1]._stop if next is None else next
stop = non_empty_indexes[-1].stop if next_ is None else next_
return RangeIndex(start, stop, step)

# Here all "indexes" had 0 length, i.e. were empty.
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2494,7 +2494,7 @@ def memory_usage(self, index=True, deep=False):
4 1 1.0 1.0+0.0j 1 True

>>> df.memory_usage()
Index 80
Index 192
int64 40000
float64 40000
complex128 80000
Expand Down
Loading