BUG: Creating Index with the `names` argument
State: closed

- [x] closes #19082 
- [x] tests added / passed
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`


Labels:
name: Bug
name: Indexing
description: Related to indexing on series/frames, not to indexes themselves

Comments:
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/19168?src=pr&el=h1) Report
> Merging [#19168](https://codecov.io/gh/pandas-dev/pandas/pull/19168?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/4ebdc50f250ab2fd4312f82d119e5370a5128810?src=pr&el=desc) will **decrease** coverage by `0.03%`.
> The diff coverage is `100%`.

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

```diff
@@            Coverage Diff             @@
##           master   #19168      +/-   ##
==========================================
- Coverage   91.56%   91.53%   -0.04%     
==========================================
  Files         148      147       -1     
  Lines       48856    48834      -22     
==========================================
- Hits        44733    44698      -35     
- Misses       4123     4136      +13
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `89.9% <100%> (-0.04%)` | :arrow_down: |
| #single | `41.69% <70%> (ø)` | :arrow_up: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/19168?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/indexes/base.py](https://codecov.io/gh/pandas-dev/pandas/pull/19168/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9iYXNlLnB5) | `96.47% <100%> (+0.01%)` | :arrow_up: |
| [pandas/core/accessor.py](https://codecov.io/gh/pandas-dev/pandas/pull/19168/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYWNjZXNzb3IucHk=) | `93.75% <0%> (-4.96%)` | :arrow_down: |
| [pandas/plotting/\_converter.py](https://codecov.io/gh/pandas-dev/pandas/pull/19168/diff?src=pr&el=tree#diff-cGFuZGFzL3Bsb3R0aW5nL19jb252ZXJ0ZXIucHk=) | `65.22% <0%> (-1.74%)` | :arrow_down: |
| [pandas/core/indexes/accessors.py](https://codecov.io/gh/pandas-dev/pandas/pull/19168/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9hY2Nlc3NvcnMucHk=) | `89.36% <0%> (-0.64%)` | :arrow_down: |
| [pandas/io/json/table\_schema.py](https://codecov.io/gh/pandas-dev/pandas/pull/19168/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2pzb24vdGFibGVfc2NoZW1hLnB5) | `98.19% <0%> (-0.1%)` | :arrow_down: |
| [pandas/core/series.py](https://codecov.io/gh/pandas-dev/pandas/pull/19168/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvc2VyaWVzLnB5) | `94.61% <0%> (ø)` | :arrow_up: |
| [pandas/errors/\_\_init\_\_.py](https://codecov.io/gh/pandas-dev/pandas/pull/19168/diff?src=pr&el=tree#diff-cGFuZGFzL2Vycm9ycy9fX2luaXRfXy5weQ==) | `100% <0%> (ø)` | :arrow_up: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/19168/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.62% <0%> (ø)` | :arrow_up: |
| [pandas/core/categorical.py](https://codecov.io/gh/pandas-dev/pandas/pull/19168/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY2F0ZWdvcmljYWwucHk=) | `95.78% <0%> (ø)` | :arrow_up: |
| ... and [6 more](https://codecov.io/gh/pandas-dev/pandas/pull/19168/diff?src=pr&el=tree-more) | |

------

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

> One more question then: should we remove it from MultiIndex too and not accept name as a parameter for MultiIndex?

Oh right. I hate that line. But you are right that removing it could break code. Maybe we should just leave the list-like behavior of ``names`` (undo my suggestion), and then open a new issue for its deprecation (both in ``Index`` and in ``MultiIndex``).
@jreback In general this PR and https://github.com/pandas-dev/pandas/pull/19246 are independent. But cleaning validation can make this one better too. So, I think https://github.com/pandas-dev/pandas/pull/19246 is prior.
OK, so in light of https://github.com/pandas-dev/pandas/issues/19295#issuecomment-358619227 I guess here we want ``pd.Index(names=)`` to 1) raise an error if resulting in a non-multi index, 2) raise a ``DeprecationWarning`` if resulting in a ``MultiIndex``.

We also want (in other PRs) 1) all non-multi subclasses to raise an error if passed ``names``, 2) ``pd.MultiIndex`` to raise a ``DeprecationWarning`` if passed ``names``.
no do not change this PR for deprecation
that is orthogonal 
> no do not change this PR for deprecation
> that is orthogonal

How that? This PR is enabling a feature which was never supported and which we want to deprecate in all cases in which it is supported.
@toobaz well if you want to do a deprecation PR first then we can close this one. 
> OK, so in light of #19295 (comment) I guess here we want pd.Index(names=) to 1) raise an error if resulting in a non-multi index, 2) raise a DeprecationWarning if resulting in a MultiIndex.

> We also want (in other PRs) 1) all non-multi subclasses to raise an error if passed names, 2) pd.MultiIndex to raise a DeprecationWarning if passed names.

let's do this, so closing this PR. @PoppyBagel if you'd like to submit one to do this would be great.