Skip to content

Commit 65a7532

Browse files
jbrockmendelproost
authored andcommitted
CLN: avoid catching Exception in io.pytables (pandas-dev#29810)
1 parent 90ca876 commit 65a7532

File tree

1 file changed

+22
-28
lines changed

1 file changed

+22
-28
lines changed

pandas/io/pytables.py

+22-28
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,8 @@ def remove(self, key: str, where=None, start=None, stop=None):
996996
# the key is not a valid store, re-raising KeyError
997997
raise
998998
except Exception:
999+
# In tests we get here with ClosedFileError, TypeError, and
1000+
# _table_mod.NoSuchNodeError. TODO: Catch only these?
9991001

10001002
if where is not None:
10011003
raise ValueError(
@@ -1806,8 +1808,7 @@ def convert(
18061808
# making an Index instance could throw a number of different errors
18071809
try:
18081810
self.values = Index(values, **kwargs)
1809-
except Exception:
1810-
1811+
except ValueError:
18111812
# if the output freq is different that what we recorded,
18121813
# it should be None (see also 'doc example part 2')
18131814
if "freq" in kwargs:
@@ -4188,36 +4189,29 @@ def write_data_chunk(self, rows, indexes, mask, values):
41884189
if not np.prod(v.shape):
41894190
return
41904191

4191-
try:
4192-
nrows = indexes[0].shape[0]
4193-
if nrows != len(rows):
4194-
rows = np.empty(nrows, dtype=self.dtype)
4195-
names = self.dtype.names
4196-
nindexes = len(indexes)
4197-
4198-
# indexes
4199-
for i, idx in enumerate(indexes):
4200-
rows[names[i]] = idx
4192+
nrows = indexes[0].shape[0]
4193+
if nrows != len(rows):
4194+
rows = np.empty(nrows, dtype=self.dtype)
4195+
names = self.dtype.names
4196+
nindexes = len(indexes)
42014197

4202-
# values
4203-
for i, v in enumerate(values):
4204-
rows[names[i + nindexes]] = v
4198+
# indexes
4199+
for i, idx in enumerate(indexes):
4200+
rows[names[i]] = idx
42054201

4206-
# mask
4207-
if mask is not None:
4208-
m = ~mask.ravel().astype(bool, copy=False)
4209-
if not m.all():
4210-
rows = rows[m]
4202+
# values
4203+
for i, v in enumerate(values):
4204+
rows[names[i + nindexes]] = v
42114205

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

4215-
try:
4216-
if len(rows):
4217-
self.table.append(rows)
4218-
self.table.flush()
4219-
except Exception as detail:
4220-
raise TypeError(f"tables cannot write this data -> {detail}")
4212+
if len(rows):
4213+
self.table.append(rows)
4214+
self.table.flush()
42214215

42224216
def delete(
42234217
self,

0 commit comments

Comments
 (0)