-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Fix for #18178 and #18187 by changing the concat of empty RangeIndex #18191
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
Conversation
…of empty RangeIndex The `_concat_rangeindex_same_dtype` now keeps track of the last non-empty RangeIndex to extract the new stop value. This fixes two issues with concatenating non-empty and empty DataFrames and Series. Two regression tests were added as well.
As an alternative solution, instead of using if not len(obj):
continue and this new if not len(obj):
from pandas import Int64Index
return _concat_index_same_dtype(indexes, klass=Int64Index) However, in this case, the returned new index would always be changed to an integer one in case of a single empty |
i am ok with the soln |
pandas/core/dtypes/concat.py
Outdated
|
||
for obj in indexes: | ||
if not len(obj): | ||
continue | ||
# Remember the last non-empty index for the stop value | ||
last_non_empty = obj |
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 filter out he non empties first? then i think this loop should be ok?
I made the code a bit nicer by first filtering the empty indexes with a list comprehension |
Codecov Report
@@ Coverage Diff @@
## master #18191 +/- ##
==========================================
+ Coverage 91.4% 91.4% +<.01%
==========================================
Files 163 163
Lines 50064 50065 +1
==========================================
+ Hits 45763 45764 +1
Misses 4301 4301
Continue to review full report at Codecov.
|
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.
Thanks!
Side note: the behaviour in case of all empties to take the start/stop/step feels a bit strange to me (why not the first? or convert to empty Int64Index?), but given that this is how it already was before, we can leave that for another PR (if we would want to change that)
@jorisvandenbossche yes, another pull request for these changes is probably a good idea, especially because IMO this involves changing existing RangeIndex tests. |
thanks @SmokinCaterpillar yeah I find this logic slightly strange. If you'd like to follow up with a PR to clarify would be great! |
Opened a follow up PR #18214 :-) |
… of empty RangeIndex (pandas-dev#18191)
… of empty RangeIndex (pandas-dev#18191) (cherry picked from commit 6b3641b)
The
_concat_rangeindex_same_dtype
function now keeps track of the last non-emptyRangeIndex
to extract the new stop value.This fixes two issues with concatenating non-empty and empty
DataFrames
andSeries
.Two regression tests were added as well.
git diff master -u -- "*.py" | flake8 --diff