Skip to content

Commit 7acb965

Browse files
authored
Fix/na_values_GH59303 (#59755)
* fixed GH#59303 * pre-commit done * updated v3.0.0.rst * sort my entry in v3.0.0.rst * changes based on comments on PR * reformat long lines * reformat test_na_values.py * reformat test_na_values.py again
1 parent 4444e52 commit 7acb965

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

doc/source/whatsnew/v3.0.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,7 @@ I/O
627627
- Bug in :meth:`read_csv` causing segmentation fault when ``encoding_errors`` is not a string. (:issue:`59059`)
628628
- Bug in :meth:`read_csv` raising ``TypeError`` when ``index_col`` is specified and ``na_values`` is a dict containing the key ``None``. (:issue:`57547`)
629629
- Bug in :meth:`read_csv` raising ``TypeError`` when ``nrows`` and ``iterator`` are specified without specifying a ``chunksize``. (:issue:`59079`)
630+
- Bug in :meth:`read_csv` where the order of the ``na_values`` makes an inconsistency when ``na_values`` is a list non-string values. (:issue:`59303`)
630631
- Bug in :meth:`read_excel` raising ``ValueError`` when passing array of boolean values when ``dtype="boolean"``. (:issue:`58159`)
631632
- Bug in :meth:`read_json` not validating the ``typ`` argument to not be exactly ``"frame"`` or ``"series"`` (:issue:`59124`)
632633
- Bug in :meth:`read_stata` raising ``KeyError`` when input file is stored in big-endian format and contains strL data. (:issue:`58638`)

pandas/io/parsers/readers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1648,7 +1648,7 @@ def _clean_na_values(na_values, keep_default_na: bool = True, floatify: bool = T
16481648
if keep_default_na:
16491649
v = set(v) | STR_NA_VALUES
16501650

1651-
na_values[k] = v
1651+
na_values[k] = _stringify_na_values(v, floatify)
16521652
na_fvalues = {k: _floatify_na_values(v) for k, v in na_values.items()}
16531653
else:
16541654
if not is_list_like(na_values):

pandas/tests/io/parser/test_na_values.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,3 +812,21 @@ def test_bool_and_nan_to_float(all_parsers):
812812
result = parser.read_csv(StringIO(data), dtype="float")
813813
expected = DataFrame.from_dict({"0": [np.nan, 1.0, 0.0]})
814814
tm.assert_frame_equal(result, expected)
815+
816+
817+
@xfail_pyarrow
818+
@pytest.mark.parametrize(
819+
"na_values",
820+
[[-99.0, -99], [-99, -99.0]],
821+
)
822+
def test_na_values_dict_without_dtype(all_parsers, na_values):
823+
parser = all_parsers
824+
data = """A
825+
-99
826+
-99
827+
-99.0
828+
-99.0"""
829+
830+
result = parser.read_csv(StringIO(data), na_values=na_values)
831+
expected = DataFrame({"A": [np.nan, np.nan, np.nan, np.nan]})
832+
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)