-
-
Notifications
You must be signed in to change notification settings - Fork 18.8k
BUG: Avoid copying categorical codes if copy=False
#62000
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
@@ -575,7 +575,7 @@ def astype(self, dtype: AstypeArg, copy: bool = True) -> ArrayLike: | |||
# GH 10696/18593/18630 | |||
dtype = self.dtype.update_dtype(dtype) | |||
self = self.copy() if copy else self |
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.
Do we need this line if we pass self._set_dtype(dtype, copy=copy)
?
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.
I wasn't entirely sure. The self.copy
is also creating a new Categorical
object which is desired, I assume.
copy=False
Thanks @fjetter |
Categorical codes are always copied by
recode_for_categories
regardless of the copy argument. This fixes it by passing the copy argument down torecode_for_categories
[ ] closes #xxxx (Replace xxxx with the GitHub issue number)doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.