-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Fix for convert_dtypes with mix of int and string #32126
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
Conversation
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.
Thanks! Small question
@@ -144,11 +156,23 @@ class TestSeriesConvertDtypes: | |||
[1, 2.0], |
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.
It's a bit hard to interpret below tests / diff, but does pd.Series([1, 2.0], dtype=object).convert_dtypes() still give Int64?
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.
Yes. Here's the interpretation of the tests for that case:
The code reads:
(
[1, 2.0],
object,
{
((True,), (True, False), (True,), (True, False)): "Int64",
((True,), (True, False), (False,), (True, False)): np.dtype(
"float"
),
((False,), (True, False), (True, False), (True, False)): np.dtype(
"object"
),
},
),
This means the following:
- Create a
Series
with[1, 2.0]
as the entries, with dtypeobject
- Consider the 16 possible combinations of the 4 arguments
infer_objects
,convert_string
,convert_integer
andconvert_boolean
- If
infer_objects==True
andconvert_integer==True
, result should beInt64
- If
infer_objects==True
andconvert_integer==False
, result should befloat
- If
infer_objects==False
, result is alwaysobject
Prior to this PR, the tests were as follows:
p3) If convert_integer==True
, result should be Int64
independent of value of infer_objects
p4) If infer_objects==True
and convert_integer==False
, result should be float
(same)
p5) If infer_objects==False
and convert_integer==False
, result is object
I think the new version is what we want the behavior to be, i.e., if you start with object
and you don't do the infer-objects step, it remains an object.
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.
OK, thanks
@Dr-Irv Thanks! |
… int and string
…tring (#32153) Co-authored-by: Irv Lustig <[email protected]>
test_convert_dtypes
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff