Skip to content

Commit

Permalink
CLN GH22874 replace bare excepts in pandas/io/pytables.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Pamela Wu committed Oct 1, 2018
1 parent 2f1b842 commit d8eb6b0
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def _tables():
try:
_table_file_open_policy_is_strict = (
tables.file._FILE_OPEN_POLICY == 'strict')
except:
except AttributeError:
pass

return _table_mod
Expand Down Expand Up @@ -395,11 +395,11 @@ def read_hdf(path_or_buf, key=None, mode='r', **kwargs):
'contains multiple datasets.')
key = candidate_only_group._v_pathname
return store.select(key, auto_close=auto_close, **kwargs)
except:
except (ValueError, TypeError):
# if there is an error, close the store
try:
store.close()
except:
except AttributeError:
pass

raise
Expand Down Expand Up @@ -517,7 +517,7 @@ def __getattr__(self, name):
""" allow attribute access to get stores """
try:
return self.get(name)
except:
except (KeyError, ClosedFileError):
pass
raise AttributeError("'%s' object has no attribute '%s'" %
(type(self).__name__, name))
Expand Down Expand Up @@ -675,7 +675,7 @@ def flush(self, fsync=False):
if fsync:
try:
os.fsync(self._handle.fileno())
except:
except OSError:
pass

def get(self, key):
Expand Down Expand Up @@ -1156,12 +1156,13 @@ def walk(self, where="/"):

def get_node(self, key):
""" return the node with the key or None if it does not exist """
import tables
self._check_if_open()
try:
if not key.startswith('/'):
key = '/' + key
return self._handle.get_node(self.root, key)
except:
except tables.exceptions.NoSuchNodeError:
return None

def get_storer(self, key):
Expand Down Expand Up @@ -1270,7 +1271,7 @@ def _validate_format(self, format, kwargs):
# validate
try:
kwargs['format'] = _FORMAT_MAP[format.lower()]
except:
except KeyError:
raise TypeError("invalid HDFStore format specified [{0}]"
.format(format))

Expand Down Expand Up @@ -1307,7 +1308,7 @@ def error(t):

try:
pt = _TYPE_MAP[type(value)]
except:
except KeyError:
error('_TYPE_MAP')

# we are actually a table
Expand All @@ -1318,7 +1319,7 @@ def error(t):
if u('table') not in pt:
try:
return globals()[_STORER_MAP[pt]](self, group, **kwargs)
except:
except KeyError:
error('_STORER_MAP')

# existing node (and must be a table)
Expand Down Expand Up @@ -1354,12 +1355,12 @@ def error(t):
fields = group.table._v_attrs.fields
if len(fields) == 1 and fields[0] == u('value'):
tt = u('legacy_frame')
except:
except IndexError:
pass

try:
return globals()[_TABLE_MAP[tt]](self, group, **kwargs)
except:
except KeyError:
error('_TABLE_MAP')

def _write_to_group(self, key, value, format, index=True, append=False,
Expand Down Expand Up @@ -1624,7 +1625,7 @@ def is_indexed(self):
""" return whether I am an indexed column """
try:
return getattr(self.table.cols, self.cname).is_indexed
except:
except AttributeError:
False

def copy(self):
Expand Down Expand Up @@ -1656,7 +1657,8 @@ def convert(self, values, nan_rep, encoding, errors):
kwargs['name'] = _ensure_decoded(self.index_name)
try:
self.values = Index(values, **kwargs)
except:
except (AttributeError, OverflowError, KeyError, IndexError,
TypeError, ValueError):

# if the output freq is different that what we recorded,
# it should be None (see also 'doc example part 2')
Expand Down Expand Up @@ -1869,7 +1871,7 @@ def create_for_block(
m = re.search(r"values_block_(\d+)", name)
if m:
name = "values_%s" % m.groups()[0]
except:
except IndexError:
pass

return cls(name=name, cname=cname, **kwargs)
Expand Down Expand Up @@ -2232,7 +2234,7 @@ def convert(self, values, nan_rep, encoding, errors):

try:
self.data = self.data.astype(dtype, copy=False)
except:
except TypeError:
self.data = self.data.astype('O', copy=False)

# convert nans / decode
Expand Down Expand Up @@ -2325,7 +2327,7 @@ def set_version(self):
self.version = tuple(int(x) for x in version.split('.'))
if len(self.version) == 2:
self.version = self.version + (0,)
except:
except AttributeError:
self.version = (0, 0, 0)

@property
Expand Down Expand Up @@ -2769,7 +2771,7 @@ def write_array(self, key, value, items=None):
else:
try:
items = list(items)
except:
except TypeError:
pass
ws = performance_doc % (inferred_type, key, items)
warnings.warn(ws, PerformanceWarning, stacklevel=7)
Expand Down Expand Up @@ -2843,7 +2845,7 @@ class SeriesFixed(GenericFixed):
def shape(self):
try:
return len(getattr(self.group, 'values')),
except:
except (TypeError, AttributeError):
return None

def read(self, **kwargs):
Expand Down Expand Up @@ -2961,7 +2963,7 @@ def shape(self):
shape = shape[::-1]

return shape
except:
except AttributeError:
return None

def read(self, start=None, stop=None, **kwargs):
Expand Down Expand Up @@ -3495,7 +3497,7 @@ def create_axes(self, axes, obj, validate=True, nan_rep=None,
if axes is None:
try:
axes = _AXES_MAP[type(obj)]
except:
except KeyError:
raise TypeError("cannot properly create the storer for: "
"[group->%s,value->%s]"
% (self.group._v_name, type(obj)))
Expand Down Expand Up @@ -3614,7 +3616,7 @@ def get_blk_items(mgr, blocks):
b, b_items = by_items.pop(items)
new_blocks.append(b)
new_blk_items.append(b_items)
except:
except (IndexError, KeyError):
raise ValueError(
"cannot match existing table structure for [%s] on "
"appending data" % ','.join(pprint_thing(item) for
Expand Down Expand Up @@ -3642,7 +3644,7 @@ def get_blk_items(mgr, blocks):
if existing_table is not None and validate:
try:
existing_col = existing_table.values_axes[i]
except:
except (IndexError, KeyError):
raise ValueError("Incompatible appended table [%s] with "
"existing table [%s]"
% (blocks, existing_table.values_axes))
Expand Down Expand Up @@ -4460,7 +4462,7 @@ def _get_info(info, name):
""" get/create the info for this name """
try:
idx = info[name]
except:
except KeyError:
idx = info[name] = dict()
return idx

Expand Down Expand Up @@ -4782,7 +4784,7 @@ def __init__(self, table, where=None, start=None, stop=None, **kwargs):
)
self.coordinates = where

except:
except ValueError:
pass

if self.coordinates is None:
Expand Down

0 comments on commit d8eb6b0

Please sign in to comment.