-
-
Notifications
You must be signed in to change notification settings - Fork 19.3k
fix : skip memoizing 0,1,True,False in sanitization function #62226
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
base: main
Are you sure you want to change the base?
Changes from 4 commits
6047584
6eb738a
3078807
2aa4a01
c01d4d5
4cffc67
b863616
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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, | ||
|
|
@@ -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(): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there a user-facing behavior we can test?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, added the same test mentioned in the issue under |
||
| # 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) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it possible to get np.True_ or np.False_? do we want int 0. or 1.0 do get caught here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested with them, works as expected