evaluate the block; return result block(s) from the result Parameters ---------- other : an ndarray/object cond : np.ndarray[bool], SparseArray[bool], or BooleanArray Returns ------- List[Block]
(self, other, cond)
| 1209 | return res_blocks |
| 1210 | |
| 1211 | def where(self, other, cond) -> list[Block]: |
| 1212 | """ |
| 1213 | evaluate the block; return result block(s) from the result |
| 1214 | |
| 1215 | Parameters |
| 1216 | ---------- |
| 1217 | other : an ndarray/object |
| 1218 | cond : np.ndarray[bool], SparseArray[bool], or BooleanArray |
| 1219 | |
| 1220 | Returns |
| 1221 | ------- |
| 1222 | List[Block] |
| 1223 | """ |
| 1224 | assert cond.ndim == self.ndim |
| 1225 | assert not isinstance(other, (ABCIndex, ABCSeries, ABCDataFrame)) |
| 1226 | |
| 1227 | transpose = self.ndim == 2 |
| 1228 | |
| 1229 | cond = extract_bool_array(cond) |
| 1230 | |
| 1231 | # EABlocks override where |
| 1232 | values = cast(np.ndarray, self.values) |
| 1233 | orig_other = other |
| 1234 | if transpose: |
| 1235 | values = values.T |
| 1236 | |
| 1237 | icond, noop = validate_putmask(values, ~cond) |
| 1238 | if noop: |
| 1239 | return [self.copy(deep=False)] |
| 1240 | |
| 1241 | if other is lib.no_default: |
| 1242 | other = self.fill_value |
| 1243 | |
| 1244 | other = self._standardize_fill_value(other) |
| 1245 | |
| 1246 | try: |
| 1247 | # try/except here is equivalent to a self._can_hold_element check, |
| 1248 | # but this gets us back 'casted' which we will reuse below; |
| 1249 | # without using 'casted', expressions.where may do unwanted upcasts. |
| 1250 | casted = np_can_hold_element(values.dtype, other) |
| 1251 | except (ValueError, TypeError, LossySetitemError): |
| 1252 | # we cannot coerce, return a compat dtype |
| 1253 | |
| 1254 | if self.ndim == 1 or self.shape[0] == 1: |
| 1255 | # no need to split columns |
| 1256 | |
| 1257 | block = self.coerce_to_target_dtype(other, raise_on_upcast=False) |
| 1258 | return block.where(orig_other, cond) |
| 1259 | |
| 1260 | else: |
| 1261 | is_array = isinstance(other, (np.ndarray, ExtensionArray)) |
| 1262 | |
| 1263 | res_blocks = [] |
| 1264 | for i, nb in enumerate(self._split()): |
| 1265 | oth = other |
| 1266 | if is_array: |
| 1267 | # we have a different value per-column |
| 1268 | oth = other[:, i : i + 1] |
no test coverage detected