-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
_concat_rangeindex_... now returns an empty RangeIndex for empty ranges #18214
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -571,6 +571,7 @@ def _concat_rangeindex_same_dtype(indexes): | |
indexes = [RangeIndex(3), RangeIndex(3, 6)] -> RangeIndex(6) | ||
indexes = [RangeIndex(3), RangeIndex(4, 6)] -> Int64Index([0,1,2,4,5]) | ||
""" | ||
from pandas import Int64Index, RangeIndex | ||
|
||
start = step = next = None | ||
|
||
|
@@ -587,14 +588,12 @@ def _concat_rangeindex_same_dtype(indexes): | |
elif step is None: | ||
# First non-empty index had only one element | ||
if obj._start == start: | ||
from pandas import Int64Index | ||
return _concat_index_same_dtype(indexes, klass=Int64Index) | ||
step = obj._start - start | ||
|
||
non_consecutive = ((step != obj._step and len(obj) > 1) or | ||
(next is not None and obj._start != next)) | ||
if non_consecutive: | ||
from pandas import Int64Index | ||
return _concat_index_same_dtype(indexes, klass=Int64Index) | ||
|
||
if step is not None: | ||
|
@@ -604,12 +603,8 @@ def _concat_rangeindex_same_dtype(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 | ||
return RangeIndex(start, stop, step) | ||
else: | ||
# Here all "indexes" had 0 length, i.e. were empty. | ||
# Simply take start, stop, and step from the last empty index. | ||
obj = indexes[-1] | ||
start = obj._start | ||
step = obj._step | ||
stop = obj._stop | ||
|
||
return indexes[0].__class__(start, stop, step) | ||
# In this case return an empty integer index. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that this should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry yes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it is changed to empty range |
||
return Int64Index([]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe remove the else here (and just return the RangeIndex)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, I personally like the else in such situations, it's more explicit to me, I guess it's a matter of taste. I'll remove it :-)