Skip to content

Commit

Permalink
CLN: avoid catching Exception in io.pytables (pandas-dev#29810)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockmendel authored and proost committed Dec 19, 2019
1 parent fc61a17 commit 4abbece
Showing 1 changed file with 22 additions and 28 deletions.
50 changes: 22 additions & 28 deletions pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,8 @@ def remove(self, key: str, where=None, start=None, stop=None):
# the key is not a valid store, re-raising KeyError
raise
except Exception:
# In tests we get here with ClosedFileError, TypeError, and
# _table_mod.NoSuchNodeError. TODO: Catch only these?

if where is not None:
raise ValueError(
Expand Down Expand Up @@ -1806,8 +1808,7 @@ def convert(
# making an Index instance could throw a number of different errors
try:
self.values = Index(values, **kwargs)
except Exception:

except ValueError:
# if the output freq is different that what we recorded,
# it should be None (see also 'doc example part 2')
if "freq" in kwargs:
Expand Down Expand Up @@ -4188,36 +4189,29 @@ def write_data_chunk(self, rows, indexes, mask, values):
if not np.prod(v.shape):
return

try:
nrows = indexes[0].shape[0]
if nrows != len(rows):
rows = np.empty(nrows, dtype=self.dtype)
names = self.dtype.names
nindexes = len(indexes)

# indexes
for i, idx in enumerate(indexes):
rows[names[i]] = idx
nrows = indexes[0].shape[0]
if nrows != len(rows):
rows = np.empty(nrows, dtype=self.dtype)
names = self.dtype.names
nindexes = len(indexes)

# values
for i, v in enumerate(values):
rows[names[i + nindexes]] = v
# indexes
for i, idx in enumerate(indexes):
rows[names[i]] = idx

# mask
if mask is not None:
m = ~mask.ravel().astype(bool, copy=False)
if not m.all():
rows = rows[m]
# values
for i, v in enumerate(values):
rows[names[i + nindexes]] = v

except Exception as detail:
raise Exception(f"cannot create row-data -> {detail}")
# mask
if mask is not None:
m = ~mask.ravel().astype(bool, copy=False)
if not m.all():
rows = rows[m]

try:
if len(rows):
self.table.append(rows)
self.table.flush()
except Exception as detail:
raise TypeError(f"tables cannot write this data -> {detail}")
if len(rows):
self.table.append(rows)
self.table.flush()

def delete(
self,
Expand Down

0 comments on commit 4abbece

Please sign in to comment.