-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
PERF: DataFrame.clip / Series.clip #51472
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 11 commits
47dcdf7
74d94dc
cde3a95
c13fd1a
ff9467e
39c4477
6eb43d0
126ea51
70fbf81
c482024
1026357
3dfa04d
393e2ae
7dc0df4
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 |
---|---|---|
|
@@ -7995,24 +7995,29 @@ def _clip_with_scalar(self, lower, upper, inplace: bool_t = False): | |
): | ||
raise ValueError("Cannot use an NA value as a clip threshold") | ||
|
||
result = self | ||
mask = isna(self._values) | ||
mgr = self._mgr | ||
|
||
with np.errstate(all="ignore"): | ||
if inplace: | ||
if upper is not None: | ||
subset = self <= upper | ||
result = result.where(subset, upper, axis=None, inplace=False) | ||
cond = self > upper | ||
mgr = mgr.putmask(mask=cond, new=upper, align=False) | ||
if lower is not None: | ||
subset = self >= lower | ||
result = result.where(subset, lower, axis=None, inplace=False) | ||
|
||
if np.any(mask): | ||
result[mask] = np.nan | ||
cond = self < lower | ||
mgr = mgr.putmask(mask=cond, new=lower, align=False) | ||
else: | ||
mask = isna(self) | ||
if upper is not None: | ||
cond = mask | (self <= upper) | ||
mgr = mgr.where(other=upper, cond=cond, align=False) | ||
if lower is not None: | ||
cond = mask | (self >= lower) | ||
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 we use > or >= in both cases? Also why don’t we need a mask in the inplace case? 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. The condition in The condition in So I think the difference is consistent with the meaning of those different methods. Using <= and >= in putmask would actually turn no-ops at the boundary into unnecessary ops I think. 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. Thx, makes sense. Did not consider that, could you add a really short comment to that effect? |
||
mgr = mgr.where(other=lower, cond=cond, align=False) | ||
|
||
result = self._constructor(mgr) | ||
if inplace: | ||
return self._update_inplace(result) | ||
else: | ||
return result | ||
return result.__finalize__(self) | ||
|
||
@final | ||
def _clip_with_one_bound(self, threshold, method, axis, inplace): | ||
|
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.
One last comment. Can you move to 2.1?