Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TST: consistent result in dropping NA from CSV #29424

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions pandas/tests/io/parser/test_na_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,3 +536,31 @@ def test_cast_NA_to_bool_raises_error(all_parsers, data, na_values):
dtype={"a": "bool"},
na_values=na_values,
)


def test_str_nan_dropped(all_parsers):
# see gh-21131
parser = all_parsers

data = """File: small.csv,,
10010010233,0123,654
foo,,bar
01001000155,4530,898"""

result = parser.read_csv(
StringIO(data),
header=None,
names=["col1", "col2", "col3"],
dtype={"col1": str, "col2": str, "col3": str},
).dropna()

expected = DataFrame(
{
"col1": ["10010010233", "01001000155"],
"col2": ["0123", "4530"],
"col3": ["654", "898"],
},
index=[1, 3],
)

tm.assert_frame_equal(result, expected)