Skip to content
Open
Show file tree
Hide file tree
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
7 changes: 4 additions & 3 deletions pandas/_libs/parsers.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2129,12 +2129,13 @@ def sanitize_objects(ndarray[object] values, set na_values) -> int:

for i in range(n):
val = values[i]
memo_key = (val, type(val))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perf impact? I suspect this hashing is slower

if val in na_values:
values[i] = onan
na_count += 1
elif val in memo:
values[i] = memo[val]
elif memo_key in memo:
values[i] = memo[memo_key]
else:
memo[val] = val
memo[memo_key] = val

return na_count
11 changes: 11 additions & 0 deletions pandas/tests/io/parser/common/test_common_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from pandas._config import using_string_dtype

from pandas._libs import parsers as libparsers
from pandas.compat import HAS_PYARROW
from pandas.errors import (
EmptyDataError,
Expand Down Expand Up @@ -830,3 +831,13 @@ def test_read_seek(all_parsers):
actual = parser.read_csv(file)
expected = parser.read_csv(StringIO(content))
tm.assert_frame_equal(actual, expected)


def test_dtype_conversion_in_sanitization():
# GH60088
values = np.array([1, True], dtype=object)
expected = np.array([1, True], dtype=object)
libparsers.sanitize_objects(values, na_values=set())
for v, e in zip(values, expected):
assert v == e
assert type(v) == type(e)
Loading