From b5f77da425f5f5406b793c9ace2fd0fccd02fe0b Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Thu, 11 Jan 2018 22:28:50 -0800 Subject: [PATCH 1/2] flake8 cleanup --- pandas/core/internals.py | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/pandas/core/internals.py b/pandas/core/internals.py index 5a4778ae4e629..e9f17385763f0 100644 --- a/pandas/core/internals.py +++ b/pandas/core/internals.py @@ -191,6 +191,13 @@ def fill_value(self): def mgr_locs(self): return self._mgr_locs + @mgr_locs.setter + def mgr_locs(self, new_mgr_locs): + if not isinstance(new_mgr_locs, BlockPlacement): + new_mgr_locs = BlockPlacement(new_mgr_locs) + + self._mgr_locs = new_mgr_locs + @property def array_dtype(self): """ the dtype to return if I want to construct this block as an @@ -224,13 +231,6 @@ def make_block_same_class(self, values, placement=None, fastpath=True, return make_block(values, placement=placement, klass=self.__class__, fastpath=fastpath, **kwargs) - @mgr_locs.setter - def mgr_locs(self, new_mgr_locs): - if not isinstance(new_mgr_locs, BlockPlacement): - new_mgr_locs = BlockPlacement(new_mgr_locs) - - self._mgr_locs = new_mgr_locs - def __unicode__(self): # don't want to print out all of the items here @@ -633,7 +633,7 @@ def _astype(self, dtype, copy=False, errors='raise', values=None, newb = make_block(values, placement=self.mgr_locs, dtype=dtype, klass=klass) - except: + except Exception: if errors == 'raise': raise newb = self.copy() if copy else self @@ -840,7 +840,7 @@ def setitem(self, indexer, value, mgr=None): transf = (lambda x: x.T) if self.ndim == 2 else (lambda x: x) values = transf(values) - l = len(values) + vlen = len(values) # length checking # boolean with truth values == len of the value is ok too @@ -855,7 +855,7 @@ def setitem(self, indexer, value, mgr=None): # slice elif isinstance(indexer, slice): - if is_list_like(value) and l: + if is_list_like(value) and vlen: if len(value) != length_of_indexer(indexer, values): raise ValueError("cannot set using a slice indexer with a " "different length than the value") @@ -1108,7 +1108,8 @@ def check_int_bool(self, inplace): # a fill na type method try: m = missing.clean_fill_method(method) - except: + except Exception: + # TODO: Catch something more specific? m = None if m is not None: @@ -1123,7 +1124,8 @@ def check_int_bool(self, inplace): # try an interp method try: m = missing.clean_interp_method(method, **kwargs) - except: + except Exception: + # TODO: Catch something more specific? m = None if m is not None: @@ -2166,7 +2168,7 @@ def set(self, locs, values, check=False): try: if (self.values[locs] == values).all(): return - except: + except Exception: pass try: self.values[locs] = values @@ -2807,7 +2809,8 @@ def _astype(self, dtype, copy=False, errors='raise', values=None, def __len__(self): try: return self.sp_index.length - except: + except Exception: + # TODO: Catch something more specific? return 0 def copy(self, deep=True, mgr=None): From 125827420da959cd9023d2b9c56eacebb5f496a0 Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Fri, 12 Jan 2018 17:49:57 -0800 Subject: [PATCH 2/2] Catch specifically ValueError --- pandas/core/internals.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/pandas/core/internals.py b/pandas/core/internals.py index e9f17385763f0..0eda1cf0c5f75 100644 --- a/pandas/core/internals.py +++ b/pandas/core/internals.py @@ -840,7 +840,6 @@ def setitem(self, indexer, value, mgr=None): transf = (lambda x: x.T) if self.ndim == 2 else (lambda x: x) values = transf(values) - vlen = len(values) # length checking # boolean with truth values == len of the value is ok too @@ -855,7 +854,7 @@ def setitem(self, indexer, value, mgr=None): # slice elif isinstance(indexer, slice): - if is_list_like(value) and vlen: + if is_list_like(value) and len(values): if len(value) != length_of_indexer(indexer, values): raise ValueError("cannot set using a slice indexer with a " "different length than the value") @@ -1108,8 +1107,7 @@ def check_int_bool(self, inplace): # a fill na type method try: m = missing.clean_fill_method(method) - except Exception: - # TODO: Catch something more specific? + except ValueError: m = None if m is not None: @@ -1124,8 +1122,7 @@ def check_int_bool(self, inplace): # try an interp method try: m = missing.clean_interp_method(method, **kwargs) - except Exception: - # TODO: Catch something more specific? + except ValueError: m = None if m is not None: