TST(string dtype): Resolve xfail in groupby.test_size#60711
TST(string dtype): Resolve xfail in groupby.test_size#60711WillAyd merged 1 commit intopandas-dev:mainfrom
Conversation
| expected = Series( | ||
| [2, 1], | ||
| index=Index(["a", "b"], name="a", dtype=dtype), | ||
| index=Index(["a", "b"], name="a", dtype=exp_index_dtype), |
There was a problem hiding this comment.
Why doesn't it work if you just remove the dtype argument and let the constructor infer?
There was a problem hiding this comment.
@rhshadrach the Int64 is for exp_dtype on the line below, not for the dtype of the Index being constructed on this line, so I am not entirely understanding your comment/question ?
(the construction of exp_dtype is not being touched in this PR)
There was a problem hiding this comment.
Ah, thanks! When the grouping column is StringDtype, we preserve this even when infer_string is False. In the groupby code, the uniques that go into creating the index is a string array. When the input is object dtype and infer_string=True, we do inference on the values and coerce to dtype str.
So in the object case we're doing inference, whereas in the non-object case we are not. It seems reasonable to me, thoughts?
There was a problem hiding this comment.
Ah OK thanks for the explanation. I am not sure how I feel yet, but at first I wasn't expecting the action of grouping to perform any inference. Is that not a performance hit?
There was a problem hiding this comment.
FWIW, if this is not easy to "fix" (avoid the inference), then I am personally fine with the current behaviour for now
There was a problem hiding this comment.
Great - I think we are all leaning in that direction
There was a problem hiding this comment.
The line in question is
pandas/pandas/core/groupby/ops.py
Line 755 in e3b2de8
While it's been moved around recently, I believe that's long standing behavior. I can investigate what impact removing that (so just using standard Index init) would have, but seems independent.
|
Owee, I'm MrMeeseeks, Look at me. There seem to be a conflict, please backport manually. Here are approximate instructions:
And apply the correct labels and milestones. Congratulations — you did some good work! Hopefully your backport PR will be tested by the continuous integration and merged soon! Remember to remove the If these instructions are inaccurate, feel free to suggest an improvement. |
|
Manual backport in #60782 |
doc/source/whatsnew/vX.X.X.rstfile if fixing a bug or adding a new feature.groupby does inference on the group labels across the board.
While I agree long-term I'd prefer to preserve object dytpe, I do not think we should be changing this at this point.