From a1b7b84cc41d39eb10a8d54c558abbce7851a233 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Mon, 21 Sep 2020 23:33:43 +0200 Subject: [PATCH 1/2] clean up blocks.py --- pandas/core/internals/blocks.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index eb5b887c8b0cb..2a1a3a502d2de 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -175,7 +175,7 @@ def _holder(self): @property def _consolidate_key(self): - return (self._can_consolidate, self.dtype.name) + return self._can_consolidate, self.dtype.name @property def is_view(self) -> bool: @@ -409,7 +409,7 @@ def fillna( return [self] if inplace else [self.copy()] # operate column-by-column - def f(mask, val, idx): + def f(idx): block = self.coerce_to_target_dtype(value) # slice out our block @@ -520,7 +520,7 @@ def downcast(self, dtypes=None): # operate column-by-column # this is expensive as it splits the blocks items-by-item - def f(mask, val, idx): + def f(val): val = maybe_downcast_to_dtype(val, dtype="infer") return val @@ -1363,6 +1363,7 @@ def where( errors : str, {'raise', 'ignore'}, default 'raise' - ``raise`` : allow exceptions to be raised - ``ignore`` : suppress exceptions. On error return original object + try_cast: bool, default False axis : int, default 0 Returns @@ -1633,8 +1634,8 @@ def __init__(self, values, placement, ndim=None): def shape(self): # TODO(EA2D): override unnecessary with 2D EAs if self.ndim == 1: - return ((len(self.values)),) - return (len(self.mgr_locs), len(self.values)) + return (len(self.values),) + return len(self.mgr_locs), len(self.values) def iget(self, col): @@ -2468,7 +2469,7 @@ def convert( can return multiple blocks! """ # operate column-by-column - def f(mask, val, idx): + def f(val): shape = val.shape values = soft_convert_objects( val.ravel(), From bcdaa65d0a2928fb2fd32953b610d4307b0135b8 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Tue, 22 Sep 2020 00:09:24 +0200 Subject: [PATCH 2/2] revert changes for tests --- pandas/core/internals/blocks.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index 2a1a3a502d2de..f18bc4d0bcf85 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -409,7 +409,7 @@ def fillna( return [self] if inplace else [self.copy()] # operate column-by-column - def f(idx): + def f(mask, val, idx): block = self.coerce_to_target_dtype(value) # slice out our block @@ -520,7 +520,7 @@ def downcast(self, dtypes=None): # operate column-by-column # this is expensive as it splits the blocks items-by-item - def f(val): + def f(mask, val, idx): val = maybe_downcast_to_dtype(val, dtype="infer") return val @@ -2469,7 +2469,7 @@ def convert( can return multiple blocks! """ # operate column-by-column - def f(val): + def f(mask, val, idx): shape = val.shape values = soft_convert_objects( val.ravel(),