Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLN GH22874 replace bare excepts in pandas/io/pytables.py #22919

Merged
merged 1 commit into from
Oct 2, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 25 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 @@ -1161,7 +1161,7 @@ def get_node(self, key):
if not key.startswith('/'):
key = '/' + key
return self._handle.get_node(self.root, key)
except:
except _table_mod.exceptions.NoSuchNodeError:
return None

def get_storer(self, key):
Expand Down Expand Up @@ -1270,7 +1270,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 +1307,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 +1318,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 +1354,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 +1624,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 @@ -1654,9 +1654,10 @@ def convert(self, values, nan_rep, encoding, errors):
kwargs['freq'] = _ensure_decoded(self.freq)
if self.index_name is not None:
kwargs['name'] = _ensure_decoded(self.index_name)
# making an Index instance could throw a number of different errors
try:
self.values = Index(values, **kwargs)
except:
except Exception: # noqa: E722

# 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 +1870,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 +2233,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 +2326,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 +2770,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 +2844,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 +2962,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 +3496,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 +3615,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 +3643,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 +4461,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 +4783,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