@@ -1274,22 +1274,6 @@ def shift(self, periods: int, axis: int = 0, fill_value=None):
1274
1274
1275
1275
return [self .make_block (new_values )]
1276
1276
1277
- def _maybe_reshape_where_args (self , values , other , cond , axis ):
1278
- transpose = self .ndim == 2
1279
-
1280
- cond = _extract_bool_array (cond )
1281
-
1282
- # If the default broadcasting would go in the wrong direction, then
1283
- # explicitly reshape other instead
1284
- if getattr (other , "ndim" , 0 ) >= 1 :
1285
- if values .ndim - 1 == other .ndim and axis == 1 :
1286
- other = other .reshape (tuple (other .shape + (1 ,)))
1287
- elif transpose and values .ndim == self .ndim - 1 :
1288
- # TODO(EA2D): not neceesssary with 2D EAs
1289
- cond = cond .T
1290
-
1291
- return other , cond
1292
-
1293
1277
def where (self , other , cond , errors = "raise" , axis : int = 0 ) -> List ["Block" ]:
1294
1278
"""
1295
1279
evaluate the block; return result block(s) from the result
@@ -1319,7 +1303,7 @@ def where(self, other, cond, errors="raise", axis: int = 0) -> List["Block"]:
1319
1303
if transpose :
1320
1304
values = values .T
1321
1305
1322
- other , cond = self . _maybe_reshape_where_args ( values , other , cond , axis )
1306
+ cond = _extract_bool_array ( cond )
1323
1307
1324
1308
if cond .ravel ("K" ).all ():
1325
1309
result = values
@@ -2072,7 +2056,7 @@ def where(self, other, cond, errors="raise", axis: int = 0) -> List["Block"]:
2072
2056
# TODO(EA2D): reshape unnecessary with 2D EAs
2073
2057
arr = self .array_values ().reshape (self .shape )
2074
2058
2075
- other , cond = self . _maybe_reshape_where_args ( arr , other , cond , axis )
2059
+ cond = _extract_bool_array ( cond )
2076
2060
2077
2061
try :
2078
2062
res_values = arr .T .where (cond , other ).T
@@ -2572,23 +2556,20 @@ def _block_shape(values: ArrayLike, ndim: int = 1) -> ArrayLike:
2572
2556
return values
2573
2557
2574
2558
2575
- def safe_reshape (arr , new_shape : Shape ):
2559
+ def safe_reshape (arr : ArrayLike , new_shape : Shape ) -> ArrayLike :
2576
2560
"""
2577
- If possible, reshape `arr` to have shape `new_shape`,
2578
- with a couple of exceptions (see gh-13012):
2579
-
2580
- 1) If `arr` is a ExtensionArray or Index, `arr` will be
2581
- returned as is.
2582
- 2) If `arr` is a Series, the `_values` attribute will
2583
- be reshaped and returned.
2561
+ Reshape `arr` to have shape `new_shape`, unless it is an ExtensionArray,
2562
+ in which case it will be returned unchanged (see gh-13012).
2584
2563
2585
2564
Parameters
2586
2565
----------
2587
- arr : array-like, object to be reshaped
2588
- new_shape : int or tuple of ints, the new shape
2566
+ arr : np.ndarray or ExtensionArray
2567
+ new_shape : Tuple[int]
2568
+
2569
+ Returns
2570
+ -------
2571
+ np.ndarray or ExtensionArray
2589
2572
"""
2590
- if isinstance (arr , ABCSeries ):
2591
- arr = arr ._values
2592
2573
if not is_extension_array_dtype (arr .dtype ):
2593
2574
# Note: this will include TimedeltaArray and tz-naive DatetimeArray
2594
2575
# TODO(EA2D): special case will be unnecessary with 2D EAs
0 commit comments