-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG-26988 implement replace for categorical blocks #27026
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
Changes from 17 commits
770ad53
a2f2a7c
535ab5d
9482c2b
702e71d
da778e1
bec92d0
593e1e0
5f23dc9
74294e0
815fe50
f444347
44631bc
8667b0d
988ebc3
d8a8d1f
0154bba
c4d3f84
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2924,6 +2924,30 @@ def where( | |
) | ||
return result | ||
|
||
def replace( | ||
self, | ||
to_replace, | ||
value, | ||
inplace: bool = False, | ||
filter=None, | ||
regex: bool = False, | ||
convert: bool = True, | ||
): | ||
inplace = validate_bool_kwarg(inplace, "inplace") | ||
result = self if inplace else self.copy() | ||
TomAugspurger marked this conversation as resolved.
Show resolved
Hide resolved
jreback marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if filter is None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what case hits this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. filter is none when replace is called on a Series as opposed to a DataFrame There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still find this non-obvious. can you add a comment to this effect There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i added a comment |
||
result.values.replace(to_replace, value, inplace=True) | ||
if convert: | ||
return result.convert(numeric=False, copy=not inplace) | ||
else: | ||
return result | ||
else: | ||
if not isna(value): | ||
result.values.add_categories(value, inplace=True) | ||
return super(CategoricalBlock, result).replace( | ||
to_replace, value, inplace, filter, regex, convert | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can any of the logic in this method generalize to ExtensionBlock? (presumably we'd need to add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is a good point, but we can certainly do as a followup; can you open an issue for discussion. |
||
|
||
|
||
# ----------------------------------------------------------------- | ||
# Constructor Helpers | ||
|
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 type these more specifically (can be a followon PR)