BUG: Fix using "inf"/"-inf" in na_values for csv with int index column
State: closed

- [x] closes #17128
- [x] tests added / passed
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [x] whatsnew entry

The issue happens when you try to use 'inf' or '-inf' as part of na_values in read_csv.

Code snippet to reproduce:
```
from StringIO import StringIO

import pandas as pd

dataset = StringIO('''index,col1,col2,col3
1,6,10,14
2,7,11,15
3,8,12,16
4,9,13,17
5,inf,-inf,bla
''')
na_values = ['inf', '-inf', 'bla']

df = pd.read_csv(dataset, na_values=na_values, index_col='index')
print df
print df.dtypes
```

Without fix:
```
Traceback (most recent call last):
  File "/home/modintsov/workspace/DataRobot/playground.py", line 39, in <module>
    df = pd.read_csv(dataset, na_values=na_values, index_col='index')
  File "/home/modintsov/.virtualenvs/dev/local/lib/python2.7/site-packages/pandas/io/parsers.py", line 678, in parser_f
    return _read(filepath_or_buffer, kwds)
  File "/home/modintsov/.virtualenvs/dev/local/lib/python2.7/site-packages/pandas/io/parsers.py", line 446, in _read
    data = parser.read(nrows)
  File "/home/modintsov/.virtualenvs/dev/local/lib/python2.7/site-packages/pandas/io/parsers.py", line 1036, in read
    ret = self._engine.read(nrows)
  File "/home/modintsov/.virtualenvs/dev/local/lib/python2.7/site-packages/pandas/io/parsers.py", line 1922, in read
    index, names = self._make_index(data, alldata, names)
  File "/home/modintsov/.virtualenvs/dev/local/lib/python2.7/site-packages/pandas/io/parsers.py", line 1426, in _make_index
    index = self._agg_index(index)
  File "/home/modintsov/.virtualenvs/dev/local/lib/python2.7/site-packages/pandas/io/parsers.py", line 1520, in _agg_index
    arr, _ = self._infer_types(arr, col_na_values | col_na_fvalues)
  File "/home/modintsov/.virtualenvs/dev/local/lib/python2.7/site-packages/pandas/io/parsers.py", line 1600, in _infer_types
    mask = algorithms.isin(values, list(na_values))
  File "/home/modintsov/.virtualenvs/dev/local/lib/python2.7/site-packages/pandas/core/algorithms.py", line 418, in isin
    values, _, _ = _ensure_data(values, dtype=dtype)
  File "/home/modintsov/.virtualenvs/dev/local/lib/python2.7/site-packages/pandas/core/algorithms.py", line 82, in _ensure_data
    return _ensure_int64(values), 'int64', 'int64'
  File "pandas/_libs/algos_common_helper.pxi", line 3227, in pandas._libs.algos.ensure_int64
  File "pandas/_libs/algos_common_helper.pxi", line 3232, in pandas._libs.algos.ensure_int64
OverflowError: cannot convert float infinity to integer
```

With fix (as expected):
```
       col1  col2  col3
index
1       6.0  10.0  14.0
2       7.0  11.0  15.0
3       8.0  12.0  16.0
4       9.0  13.0  17.0
5       NaN   NaN   NaN
col1    float64
col2    float64
col3    float64
dtype: object
```

Labels:
name: Numeric Operations
description: Arithmetic, Comparison, and Logical operations
name: IO CSV
description: read_csv, to_csv

Comments:
Hello @Templarrr! Thanks for updating the PR.





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

##### Comment last updated on August 09, 2018 at 08:44 Hours UTC
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/22169?src=pr&el=h1) Report
> Merging [#22169](https://codecov.io/gh/pandas-dev/pandas/pull/22169?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/3bcc2bb4e275efef6d4d4d87ac1d661aa4c2bdbc?src=pr&el=desc) will **decrease** coverage by `<.01%`.
> The diff coverage is `100%`.

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

```diff
@@            Coverage Diff             @@
##           master   #22169      +/-   ##
==========================================
- Coverage   92.07%   92.07%   -0.01%     
==========================================
  Files         169      169              
  Lines       50684    50683       -1     
==========================================
- Hits        46668    46666       -2     
- Misses       4016     4017       +1
```

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

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/22169?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/algorithms.py](https://codecov.io/gh/pandas-dev/pandas/pull/22169/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYWxnb3JpdGhtcy5weQ==) | `94.69% <100%> (ø)` | :arrow_up: |
| [pandas/core/indexes/multi.py](https://codecov.io/gh/pandas-dev/pandas/pull/22169/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9tdWx0aS5weQ==) | `95.25% <0%> (-0.09%)` | :arrow_down: |

------

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

xref #10065
closes #17128 
I believe this closes #17128 can you confirm and update the whatsnew to reflect
Oh, wow, it's actually my colleague :) 
Didn't know Liau Yung Siang reported that already.

Thanks for the review, it's already late In my timezone, but I'll update the PR tomorrow!
@jreback  I've confirmed that this solves the error that @YS-L reported in #17128 and addressed your PR review comments. Can you look again?

Also yesterday the 0.23.4 changelog got updated with today's date, but I don't see on pypi newer pandas version released yet, so I'm not entirely sure - will my bugfix be a part of 0.23.4 or should I move the comment to 0.24.0 changelog?
The failure in travis is some kind of network glitch, unrelated to these changes :( 
@jreback I see 0.23.4 was released, so this fix obviously didn't make it :) I've moved the changelog line to 0.24.0
@jreback I see you've moved the label to 0.23.5, didn't know there was 0.23.5 planned :) 
There is no 0.23.5 changelog currently, should I create a new one and move my changelog line there?
yeah we might do a 0.23.5. if you want to push a 0.23.5 whats (empty) pls do , but a new PR pls.
thanks @Templarrr 
You're welcome! Always glad to help :)