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
3 changes: 3 additions & 0 deletions pandas/_libs/parsers.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2132,6 +2132,9 @@ def sanitize_objects(ndarray[object] values, set na_values) -> int:
if val in na_values:
values[i] = onan
na_count += 1
elif val in [0, 1, True, False]:
# Skip memoization, since 1==True and 0==False
values[i] = val
elif val in memo:
values[i] = memo[val]
else:
Expand Down
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