Skip to content

Commit c6ed357

Browse files
update comments and docstrings
1 parent 81b1016 commit c6ed357

File tree

2 files changed

+45
-13
lines changed

2 files changed

+45
-13
lines changed

pandas/core/frame.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6103,15 +6103,15 @@ def _dispatch_frame_op(self, right, func, axis: Optional[int] = None):
61036103
# fails in cases with empty columns reached via
61046104
# _frame_arith_method_with_reindex
61056105

6106-
# TODO operate_blockwise expects a manager of the same type
6106+
# TODO operate_manager expects a manager of the same type
61076107
bm = self._mgr.operate_manager(right._mgr, func) # type: ignore[arg-type]
61086108

61096109
elif isinstance(right, Series):
61106110
if axis == 1:
61116111
# axis=1 means we want to operate row-by-row
61126112
assert right.index.equals(self.columns)
61136113
else:
6114-
assert right.index.equals(self.index) # Handle other cases later
6114+
assert right.index.equals(self.index)
61156115

61166116
right = right._values
61176117
bm = self._mgr.operate_array(right, func, axis)

pandas/core/internals/managers.py

+43-11
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import numpy as np
2121

2222
from pandas._libs import internals as libinternals, lib
23-
from pandas._typing import ArrayLike, Dtype, DtypeObj, Shape
23+
from pandas._typing import ArrayLike, Dtype, DtypeObj, Scalar, Shape
2424
from pandas.errors import PerformanceWarning
2525
from pandas.util._validators import validate_bool_kwarg
2626

@@ -367,24 +367,51 @@ def reduce(
367367
new_mgr = type(self).from_blocks(res_blocks, [self.items, index])
368368
return new_mgr, indexer
369369

370-
def operate_scalar(self, other, op) -> BlockManager:
370+
def operate_scalar(self, other: Scalar, op) -> BlockManager:
371371
"""
372-
TODO fill in
372+
Element-wise (arithmetic/comparison/logical) operation with other scalar.
373+
374+
Parameters
375+
----------
376+
other : scalar
377+
op : operator function (eg ``operator.add``)
378+
379+
Returns
380+
-------
381+
BlockManager
373382
"""
374383
# Get the appropriate array-op to apply to each column/block's values.
375384
array_op = ops.get_array_op(op)
376385
return self.apply(array_op, right=other)
377386

378387
def operate_array(self, other: ArrayLike, op, axis: int) -> BlockManager:
379388
"""
380-
TODO fill in
389+
Element-wise (arithmetic/comparison/logical) operation with other array.
390+
391+
The array is already checked to be of the correct length.
392+
393+
Parameters
394+
----------
395+
other : np.ndarray or ExtensionArray
396+
op : operator function (eg ``operator.add``)
397+
axis : int
398+
Whether to match the array on the index and broadcast along the
399+
columns (axis=0) or match the array on the columns and broadcast
400+
along the rows (axis=1).
401+
402+
Returns
403+
-------
404+
BlockManager
381405
"""
382406
array_op = ops.get_array_op(op)
383407
if axis == 1:
408+
# match on the columns -> operate on each column array with single
409+
# element from other array
384410
arrays = [
385411
array_op(self.iget_values(i), _right) for i, _right in enumerate(other)
386412
]
387413
else:
414+
# match on the rows -> operate for each column array with full other array
388415
arrays = [
389416
array_op(self.iget_values(i), other) for i in range(len(self.items))
390417
]
@@ -393,15 +420,20 @@ def operate_array(self, other: ArrayLike, op, axis: int) -> BlockManager:
393420

394421
def operate_manager(self, other: BlockManager, op) -> BlockManager:
395422
"""
396-
TODO fill in
397-
"""
398-
array_op = ops.get_array_op(op)
399-
return self.operate_blockwise(other, array_op)
423+
Element-wise (arithmetic/comparison/logical) operation with other BlockManager.
400424
401-
def operate_blockwise(self, other: BlockManager, array_op) -> BlockManager:
402-
"""
403-
Apply array_op blockwise with another (aligned) BlockManager.
425+
The other BlockManager is already aligned with `self`.
426+
427+
Parameters
428+
----------
429+
other : BlockManager
430+
op : operator function (eg ``operator.add``)
431+
432+
Returns
433+
-------
434+
BlockManager
404435
"""
436+
array_op = ops.get_array_op(op)
405437
return operate_blockwise(self, other, array_op)
406438

407439
def apply(

0 commit comments

Comments
 (0)