|
38 | 38 | from pandas.core import ops
|
39 | 39 | import pandas.core.algorithms as algos
|
40 | 40 | from pandas.core.arrays.sparse import SparseDtype
|
41 |
| -from pandas.core.construction import extract_array |
| 41 | +from pandas.core.construction import ensure_wrapped_if_datetimelike, extract_array |
42 | 42 | from pandas.core.indexers import maybe_convert_indices
|
43 | 43 | from pandas.core.indexes.api import Float64Index, Index, ensure_index
|
44 | 44 | from pandas.core.internals.base import DataManager
|
@@ -382,7 +382,20 @@ def operate_scalar(self, other: Scalar, op) -> BlockManager:
|
382 | 382 | """
|
383 | 383 | # Get the appropriate array-op to apply to each column/block's values.
|
384 | 384 | array_op = ops.get_array_op(op)
|
385 |
| - return self.apply(array_op, right=other) |
| 385 | + result_blocks: List[Block] = [] |
| 386 | + |
| 387 | + for b in self.blocks: |
| 388 | + left = ensure_wrapped_if_datetimelike(b.values) |
| 389 | + with np.errstate(all="ignore"): |
| 390 | + result = array_op(left, right=other) |
| 391 | + |
| 392 | + applied = b._split_op_result(result) |
| 393 | + result_blocks = extend_blocks(applied, result_blocks) |
| 394 | + |
| 395 | + if len(result_blocks) == 0: |
| 396 | + return self.make_empty(self.axes) |
| 397 | + |
| 398 | + return type(self).from_blocks(result_blocks, self.axes) |
386 | 399 |
|
387 | 400 | def operate_array(self, other: ArrayLike, op, axis: int) -> BlockManager:
|
388 | 401 | """
|
|
0 commit comments