Fix for #18178 and #18187 by changing the concat of empty RangeIndex 
State: closed

The `_concat_rangeindex_same_dtype` function 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.

- closes #18178 and closes #18187 
- 2 regression tests added
- Submission passes `git diff master -u -- "*.py" | flake8 --diff`
- 1 whatsnew entry


Labels:
name: Reshaping
description: Concat, Merge/Join, Stack/Unstack, Explode
name: Regression
description: Functionality that used to work in a prior pandas version

Comments:
As an alternative solution, instead of using
```python
if not len(obj):
    continue
```
and this new `last_non_empty` variable,
one could simply replace `continue` as follows:
```python
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 `RangeIndex` in `indexes`. Accordingly, some already existing tests would need to be changed as well.

i am ok with the soln
I made the code a bit nicer by first filtering the empty indexes with a list comprehension
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/18191?src=pr&el=h1) Report
> Merging [#18191](https://codecov.io/gh/pandas-dev/pandas/pull/18191?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/17e0b13095b23ade8e64434e88300b849bfadf01?src=pr&el=desc) will **increase** coverage by `<.01%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/18191/graphs/tree.svg?width=650&height=150&src=pr&token=eZ4WkYLtcO)](https://codecov.io/gh/pandas-dev/pandas/pull/18191?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #18191      +/-   ##
==========================================
+ Coverage    91.4%    91.4%   +<.01%     
==========================================
  Files         163      163              
  Lines       50064    50065       +1     
==========================================
+ Hits        45763    45764       +1     
  Misses       4301     4301
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `89.21% <100%> (ø)` | :arrow_up: |
| #single | `40.35% <33.33%> (-0.01%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/18191?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/dtypes/concat.py](https://codecov.io/gh/pandas-dev/pandas/pull/18191?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZHR5cGVzL2NvbmNhdC5weQ==) | `99.14% <100%> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/18191?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/18191?src=pr&el=footer). Last update [17e0b13...3082d0e](https://codecov.io/gh/pandas-dev/pandas/pull/18191?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

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