-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
REF: standardize usage in DataFrame vs SparseDataFrame ops #28027
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 all commits
8e1ad04
bdc0d72
7a4b8c2
3505e6a
63c5f80
bf0d2bf
c235b6a
6cf996d
d867034
ec3b4f5
94b5dbd
ca76be4
2620ef4
4c836d3
45f5419
ceeb1d2
ad53e94
cffa624
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 |
---|---|---|
|
@@ -5306,7 +5306,6 @@ def reorder_levels(self, order, axis=0): | |
|
||
def _combine_frame(self, other, func, fill_value=None, level=None): | ||
this, other = self.align(other, join="outer", level=level, copy=False) | ||
new_index, new_columns = this.index, this.columns | ||
|
||
if fill_value is None: | ||
# since _arith_op may be called in a loop, avoid function call | ||
|
@@ -5324,38 +5323,62 @@ def _arith_op(left, right): | |
|
||
if ops.should_series_dispatch(this, other, func): | ||
# iterate over columns | ||
return ops.dispatch_to_series(this, other, _arith_op) | ||
new_data = ops.dispatch_to_series(this, other, _arith_op) | ||
else: | ||
with np.errstate(all="ignore"): | ||
result = _arith_op(this.values, other.values) | ||
result = dispatch_fill_zeros(func, this.values, other.values, result) | ||
return self._constructor( | ||
result, index=new_index, columns=new_columns, copy=False | ||
) | ||
res_values = _arith_op(this.values, other.values) | ||
new_data = dispatch_fill_zeros(func, this.values, other.values, res_values) | ||
return this._construct_result(other, new_data, _arith_op) | ||
|
||
def _combine_match_index(self, other, func, level=None): | ||
left, right = self.align(other, join="outer", axis=0, level=level, copy=False) | ||
# at this point we have `left.index.equals(right.index)` | ||
|
||
if left._is_mixed_type or right._is_mixed_type: | ||
# operate column-wise; avoid costly object-casting in `.values` | ||
return ops.dispatch_to_series(left, right, func) | ||
new_data = ops.dispatch_to_series(left, right, func) | ||
else: | ||
# fastpath --> operate directly on values | ||
with np.errstate(all="ignore"): | ||
new_data = func(left.values.T, right.values).T | ||
return self._constructor( | ||
new_data, index=left.index, columns=self.columns, copy=False | ||
) | ||
return left._construct_result(other, new_data, func) | ||
|
||
def _combine_match_columns(self, other: Series, func, level=None): | ||
left, right = self.align(other, join="outer", axis=1, level=level, copy=False) | ||
# at this point we have `left.columns.equals(right.index)` | ||
return ops.dispatch_to_series(left, right, func, axis="columns") | ||
new_data = ops.dispatch_to_series(left, right, func, axis="columns") | ||
return left._construct_result(right, new_data, func) | ||
|
||
def _combine_const(self, other, func): | ||
# scalar other or np.ndim(other) == 0 | ||
return ops.dispatch_to_series(self, other, func) | ||
new_data = ops.dispatch_to_series(self, other, func) | ||
return self._construct_result(other, new_data, func) | ||
|
||
def _construct_result(self, other, result, func): | ||
""" | ||
Wrap the result of an arithmetic, comparison, or logical operation. | ||
|
||
Parameters | ||
---------- | ||
other : object | ||
result : DataFrame | ||
func : binary operator | ||
|
||
Returns | ||
------- | ||
DataFrame | ||
|
||
Notes | ||
----- | ||
`func` is included for compat with SparseDataFrame signature, is not | ||
needed here. | ||
""" | ||
out = self._constructor(result, index=self.index, copy=False) | ||
# Pin columns instead of passing to constructor for compat with | ||
# non-unique columns case | ||
out.columns = self.columns | ||
return out | ||
# TODO: finalize? we do for SparseDataFrame | ||
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. finalize doesn't do really anything for frames, prob can't hurt though 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. especially in the frame+frame case it isn't obvious that is correct; I'd prefer to revisit 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. In principle we should finalize I think, but since it was not done right now, fine to leave it for later? |
||
|
||
def combine(self, other, func, fill_value=None, overwrite=True): | ||
""" | ||
|
Uh oh!
There was an error while loading. Please reload this page.