BUG: Fix of handle missing CSV MI column names
State: closed

De-hackifies this hack:

https://github.com/pandas-dev/pandas/blob/d78bd7a65f87022bae5021d36c8656c0ea5a7b76/pandas/io/parsers.py#L3206-L3211

Setup:

~~~python
from pandas.compat import StringIO
from pandas import read_csv

data = ",,col\na,c,1\na,d,2\nb,c,3\nb,d,4"
print(read_csv(StringIO(data), index_col=[0, 1]))

data = "NotReallyUnnamed,Unnamed: 0,col\na,c,1\na,d,2\nb,c,3\nb,d,4"
print(read_csv(StringIO(data), index_col=[0, 1]))
~~~

Before:

~~~python
# Why is only `index_names[0]` replaced with `None`?
              col
  Unnamed: 1
a c             1
  d             2
b c             3
  d             4

# Having "Unnamed" in the name doesn't make it replace-able ?
# (this is also surfacing the `index_names[0]` bug too)
              col
  Unnamed: 0
a c             1
  d             2
b c             3
  d             4
~~~

After:

~~~python
# All placeholder names get dropped.
              col
a c             1
  d             2
b c             3
  d             4

# Non-placeholder names never get dropped.
                             col
NotReallyUnnamed Unnamed: 0
a                c             1
                 d             2
b                c             3
                 d             4
~~~

Labels:
name: Bug
name: IO CSV
description: read_csv, to_csv
name: MultiIndex

Comments:
Hello @gfyoung! Thanks for submitting the PR.

 - There are no PEP8 issues in the file [`pandas/io/parsers.py`](https://github.com/gfyoung/pandas/blob/41ef255c8559febda7b815e37316dd7061dc550a/pandas/io/parsers.py) !

 - There are no PEP8 issues in the file [`pandas/tests/io/parser/index_col.py`](https://github.com/gfyoung/pandas/blob/41ef255c8559febda7b815e37316dd7061dc550a/pandas/tests/io/parser/index_col.py) !


# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/23484?src=pr&el=h1) Report
> Merging [#23484](https://codecov.io/gh/pandas-dev/pandas/pull/23484?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/24ab22f75aae1c9b9491c26e6f753814b7d6fd8e?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/23484/graphs/tree.svg?width=650&token=eZ4WkYLtcO&height=150&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/23484?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #23484      +/-   ##
==========================================
+ Coverage   92.23%   92.23%   +<.01%     
==========================================
  Files         161      161              
  Lines       51197    51204       +7     
==========================================
+ Hits        47220    47227       +7     
  Misses       3977     3977
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.61% <100%> (ø)` | :arrow_up: |
| #single | `42.27% <64.7%> (ø)` | :arrow_up: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/23484?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/io/parsers.py](https://codecov.io/gh/pandas-dev/pandas/pull/23484/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL3BhcnNlcnMucHk=) | `95.62% <100%> (+0.01%)` | :arrow_up: |

------

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

@jreback : I simplified the logic a little bit, but I still needed `unnamed_count` in some cases because it's computed on a per-iteration basis of a for-loop, whereas `unnamed_cols` is a global collection.  Everything is still green though.  PTAL.
thanks!