BUG: Index.difference of itself doesn't preserve type
State: closed

- [x] closes #20040
- [x] tests added / passed
   - tests/indexes/test_base.py:test_difference_type
   - tests/indexes/test_base.py:test_intersection_difference
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [x] whatsnew entry

Uses `Index._shallow_copy([])`, which means fixes are related to getting that to work right.

Fundamental concept is that if the result of  `Index.difference` is an empty index, then result should preserve type and attributes of the object.  In addition, for `MultiIndex`, if result of intersection is an empty index, then the levels are preserved.

Labels:
name: Indexing
description: Related to indexing on series/frames, not to indexes themselves
name: Dtype Conversions
description: Unexpected or buggy dtype conversions

Comments:
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/20062?src=pr&el=h1) Report
> :exclamation: No coverage uploaded for pull request base (`master@8d82cce`). [Click here to learn what that means](https://docs.codecov.io/docs/error-reference#section-missing-base-commit).
> The diff coverage is `100%`.

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

```diff
@@            Coverage Diff            @@
##             master   #20062   +/-   ##
=========================================
  Coverage          ?   91.78%           
=========================================
  Files             ?      152           
  Lines             ?    49179           
  Branches          ?        0           
=========================================
  Hits              ?    45138           
  Misses            ?     4041           
  Partials          ?        0
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.16% <100%> (?)` | |
| #single | `41.87% <75%> (?)` | |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/20062?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/indexes/base.py](https://codecov.io/gh/pandas-dev/pandas/pull/20062/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9iYXNlLnB5) | `96.67% <100%> (ø)` | |
| [pandas/core/indexes/multi.py](https://codecov.io/gh/pandas-dev/pandas/pull/20062/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9tdWx0aS5weQ==) | `95.05% <100%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/20062?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/20062?src=pr&el=footer). Last update [8d82cce...3df7ce6](https://codecov.io/gh/pandas-dev/pandas/pull/20062?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

@jreback latest push (https://github.com/pandas-dev/pandas/pull/20062/commits/20b8d47ab3e39fb19b86ffe652dc11500ff88efa) has rebase with master, added a test for constructing empty indexes, and did the yield idea for looping through the index types, as well as the other change you asked for.
thanks @Dr-Irv 

not very happy with ``pandas/tests/indexes/test_base.py`` but that's another issue.