-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Allow cast from cat to extension dtype #28762
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
Getting this Should |
Hmm have we ever considered making the @TomAugspurger any thoughts? Would certainly help the type system |
I thought it was an instance of abc.Sequence, but apparently not. Apparently, ndarray's aren't Sequences either... I don't have a strong opinion here. |
@@ -520,6 +520,8 @@ def astype(self, dtype: Dtype, copy: bool = True) -> ArrayLike: | |||
if dtype == self.dtype: | |||
return self | |||
return self._set_dtype(dtype) | |||
if is_extension_array_dtype(dtype): | |||
return array(self, dtype=dtype, copy=copy) # type: ignore # GH 28770 |
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.
maybe the following an elif
Also fix typo in test
@@ -217,6 +217,7 @@ Categorical | |||
|
|||
- Added test to assert the :func:`fillna` raises the correct ValueError message when the value isn't a value from categories (:issue:`13628`) | |||
- Bug in :meth:`Categorical.astype` where ``NaN`` values were handled incorrectly when casting to int (:issue:`28406`) | |||
- Bug in :meth:`Categorical.astype` not allowing for casting to extension dtypes (:issue:`28668`) |
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.
can you add another note about the merge issue (which was the OP); IIRC its the same issue number. otherwise lgtm, ping on green.
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.
@jreback Included a note for the merge issue, let me know if it looks good and thanks for the review
thanks @dsaxton |
black pandas
Modifies
categorical.astype
to allow for casting to extension dtypes. Also fixes the merge issue identified in #28668.