Skip to content

Commit ff7eb61

Browse files
committed
BUG: Patch handling no NA values in TextFileReader
Closes gh-15835
1 parent ed07df1 commit ff7eb61

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

doc/source/whatsnew/v0.20.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,7 @@ I/O
10111011
- Bug in ``DataFrame.to_stata()`` and ``StataWriter`` which produces incorrectly formatted files to be produced for some locales (:issue:`13856`)
10121012
- Bug in ``StataReader`` and ``StataWriter`` which allows invalid encodings (:issue:`15723`)
10131013
- Bug in ``pd.to_json()`` for the C engine where rollover was not correctly handled for case where frac is odd and diff is exactly 0.5 (:issue:`15716`, :issue:`15864`)
1014+
- Bug in ``pd.read_csv()`` when an index was specified and no values were specified as null values (:issue:`15835`)
10141015

10151016
Plotting
10161017
^^^^^^^^

pandas/io/parsers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2890,7 +2890,7 @@ def _clean_na_values(na_values, keep_default_na=True):
28902890
if keep_default_na:
28912891
na_values = _NA_VALUES
28922892
else:
2893-
na_values = []
2893+
na_values = set()
28942894
na_fvalues = set()
28952895
elif isinstance(na_values, dict):
28962896
na_values = na_values.copy() # Prevent aliasing.

pandas/tests/io/parser/na_values.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import pandas.io.parsers as parsers
1212
import pandas.util.testing as tm
1313

14-
from pandas import DataFrame, MultiIndex
14+
from pandas import DataFrame, Index, MultiIndex
1515
from pandas.compat import StringIO, range
1616

1717

@@ -303,3 +303,12 @@ def test_na_values_uint64(self):
303303
expected = DataFrame([[str(2**63), 1], ['', 2]])
304304
out = self.read_csv(StringIO(data), header=None)
305305
tm.assert_frame_equal(out, expected)
306+
307+
def test_empty_na_values_no_default_with_index(self):
308+
# see gh-15835
309+
data = "a,1\nb,2"
310+
311+
expected = DataFrame({1: [2]}, index=Index(["b"], name="a"))
312+
out = self.read_csv(StringIO(data), keep_default_na=False, index_col=0)
313+
314+
tm.assert_frame_equal(out, expected)

0 commit comments

Comments
 (0)