-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
BUG/API: _values_for_factorize/_from_factorized round-trip #32798
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.
Let's first discuss in the issue what we want
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.
lgtm.
@jorisvandenbossche objections? |
Yes, see my comment, we should first discuss further in the issue before simply changing |
pandas/core/arrays/boolean.py
Outdated
@@ -320,7 +320,8 @@ def _values_for_factorize(self) -> Tuple[np.ndarray, int]: | |||
|
|||
@classmethod | |||
def _from_factorized(cls, values, original: "BooleanArray") -> "BooleanArray": | |||
return cls._from_sequence(values, dtype=original.dtype) | |||
mask = values == -1 | |||
return cls(values.astype(bool), mask) |
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.
The astype
causes a copy, which I think wasn't present before. This could perhaps be a .view('bool')
to preserve the previous no-copy behavior.
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.
changed to .astype(bool, copy=False)
mothballing |
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff
having this round-trip-ability is necessary for implementing an efficient general-case broadcast_to/tile compat method.