Skip to content

_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

Merged
merged 4 commits into from
Nov 11, 2017

Conversation

SmokinCaterpillar
Copy link
Contributor

This is a follow up to PR #18191.

Overall the code is more readable by adding the constructors at the beginning and
explicitly calling RangeIndex constructor.

One range index test was changed to accommodate for the new behavior of the index concatenation function.

  • passes git diff upstream/master -u -- "*.py" | flake8 --diff
  • 1 test changed

… empty ranges;

Overall the code is more readable by adding the constructors at the beginning and
explicitly calling `RangeIndex` constructor.

One range index test needed to be changed, because concatenating empty range indexes leads to an empty integer index from now on;
stop = obj._stop

return indexes[0].__class__(start, stop, step)
# In this case return an empty integer index.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this should be RangeIndex(0, 1) to be consistent with our default indices, e.g. Series([]).index

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RangeIndex(0, 1) or rather RangeIndex(0, 0)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry yes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is changed to empty range

@jreback jreback added Clean Compat pandas objects compatability with Numpy or Python functions Reshaping Concat, Merge/Join, Stack/Unstack, Explode labels Nov 10, 2017
@pep8speaks
Copy link

pep8speaks commented Nov 10, 2017

Hello @SmokinCaterpillar! Thanks for updating the PR.

Cheers ! There are no PEP8 issues in this Pull Request. 🍻

Comment last updated on November 11, 2017 at 11:32 Hours UTC

@codecov
Copy link

codecov bot commented Nov 10, 2017

Codecov Report

Merging #18214 into master will decrease coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #18214      +/-   ##
==========================================
- Coverage   91.42%   91.41%   -0.02%     
==========================================
  Files         163      163              
  Lines       50068    50064       -4     
==========================================
- Hits        45777    45764      -13     
- Misses       4291     4300       +9
Flag Coverage Δ
#multiple 89.21% <100%> (-0.01%) ⬇️
#single 40.36% <33.33%> (-0.06%) ⬇️
Impacted Files Coverage Δ
pandas/core/dtypes/concat.py 99.13% <100%> (-0.02%) ⬇️
pandas/io/gbq.py 25% <0%> (-58.34%) ⬇️
pandas/core/frame.py 97.8% <0%> (-0.1%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 75c1fa0...3210504. Read the comment docs.

@jreback jreback changed the title _concat_rangeindex_... now returns an empty Int64Index for empty ranges _concat_rangeindex_... now returns an empty RangeIndex for empty ranges Nov 10, 2017
@jreback jreback added this to the 0.22.0 milestone Nov 10, 2017
Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this have any user visible effect?

@@ -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:
Copy link
Contributor

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)

Copy link
Contributor Author

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 :-)

@jreback jreback merged commit 3493aba into pandas-dev:master Nov 11, 2017
@jreback
Copy link
Contributor

jreback commented Nov 11, 2017

thanks!

No-Stream pushed a commit to No-Stream/pandas that referenced this pull request Nov 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Clean Compat pandas objects compatability with Numpy or Python functions Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants