-
-
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
PERF: implement scalar ops blockwise #29853
Changes from all commits
15f0caa
08a43f0
a765069
c81ea13
c2f6129
016ae64
4536097
798ce75
1fc1e3e
657d1bb
66d34c2
0f26775
a0e4adc
23d5c48
2228f5e
e230cea
2f80502
31607c0
0ec7e74
cf94d13
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 |
---|---|---|
|
@@ -340,13 +340,13 @@ def _verify_integrity(self): | |
f"tot_items: {tot_items}" | ||
) | ||
|
||
def apply(self, f: str, filter=None, **kwargs): | ||
def apply(self, f, filter=None, **kwargs): | ||
""" | ||
Iterate over the blocks, collect and create a new BlockManager. | ||
|
||
Parameters | ||
---------- | ||
f : str | ||
f : str or callable | ||
Name of the Block method to apply. | ||
filter : list, if supplied, only call the block if the filter is in | ||
the block | ||
|
@@ -411,7 +411,10 @@ def apply(self, f: str, filter=None, **kwargs): | |
axis = obj._info_axis_number | ||
kwargs[k] = obj.reindex(b_items, axis=axis, copy=align_copy) | ||
|
||
applied = getattr(b, f)(**kwargs) | ||
if callable(f): | ||
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. is this strictly necessary? meaning happy to require only callables here (would require some changing) 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. all of our existing usages pass strings here to get at Block methods. i think @WillAyd had a suggestion about re-working Block.apply to do str vs callable handling there; that should be its own PR 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. k, yeah this whole section could use some TLC |
||
applied = b.apply(f, **kwargs) | ||
else: | ||
applied = getattr(b, f)(**kwargs) | ||
result_blocks = _extend_blocks(applied, result_blocks) | ||
|
||
if len(result_blocks) == 0: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ | |
arithmetic_op, | ||
comparison_op, | ||
define_na_arithmetic_op, | ||
get_array_op, | ||
logical_op, | ||
) | ||
from pandas.core.ops.array_ops import comp_method_OBJECT_ARRAY # noqa:F401 | ||
|
@@ -372,8 +373,10 @@ def dispatch_to_series(left, right, func, str_rep=None, axis=None): | |
right = lib.item_from_zerodim(right) | ||
if lib.is_scalar(right) or np.ndim(right) == 0: | ||
|
||
def column_op(a, b): | ||
return {i: func(a.iloc[:, i], b) for i in range(len(a.columns))} | ||
# Get the appropriate array-op to apply to each block's values. | ||
array_op = get_array_op(func, str_rep=str_rep) | ||
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 you add a comment here on what is going on |
||
bm = left._data.apply(array_op, right=right) | ||
return type(left)(bm) | ||
|
||
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 could just be an if (as you are returning), e.g. change the following elif to an if, but NBD |
||
elif isinstance(right, ABCDataFrame): | ||
assert right._indexed_same(left) | ||
|
@@ -713,7 +716,7 @@ def f(self, other, axis=default_axis, level=None, fill_value=None): | |
if fill_value is not None: | ||
self = self.fillna(fill_value) | ||
|
||
new_data = dispatch_to_series(self, other, op) | ||
new_data = dispatch_to_series(self, other, op, str_rep) | ||
return self._construct_result(new_data) | ||
|
||
f.__name__ = op_name | ||
|
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.
could be an elif here and re-assign to result, just to make the flow more natural. alt could make this into a method on BM. but for followon's