Skip to content

CLN: avoid catching Exception in io.pytables #29810

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

Merged
merged 3 commits into from
Nov 25, 2019
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
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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So just nothing hitting these in the test cases right? If so, any insight from git blame as to why this was here in the first place?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty much, yah. The blame for these goes to back before we were using github AFAICT, so there arent associated PRs/threads.

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