Skip to content

Commit f585730

Browse files
jbrockmendelproost
authored andcommitted
CLN: catch specific exceptions in frame.py (pandas-dev#29258)
1 parent a0cd35e commit f585730

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

pandas/core/frame.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -1666,11 +1666,12 @@ def from_records(
16661666
else:
16671667
try:
16681668
index_data = [arrays[arr_columns.get_loc(field)] for field in index]
1669+
except (KeyError, TypeError):
1670+
# raised by get_loc, see GH#29258
1671+
result_index = index
1672+
else:
16691673
result_index = ensure_index_from_sequences(index_data, names=index)
1670-
16711674
exclude.update(index)
1672-
except Exception:
1673-
result_index = index
16741675

16751676
if any(exclude):
16761677
arr_exclude = [x for x in exclude if x in arr_columns]
@@ -3625,11 +3626,11 @@ def reindexer(value):
36253626
# GH 4107
36263627
try:
36273628
value = value.reindex(self.index)._values
3628-
except Exception as e:
3629-
3630-
# duplicate axis
3629+
except ValueError as err:
3630+
# raised in MultiIndex.from_tuples, see test_insert_error_msmgs
36313631
if not value.index.is_unique:
3632-
raise e
3632+
# duplicate axis
3633+
raise err
36333634

36343635
# other
36353636
raise TypeError(
@@ -7796,7 +7797,8 @@ def f(x):
77967797
# TODO: combine with hasattr(result, 'dtype') further down
77977798
# hard since we don't have `values` down there.
77987799
result = np.bool_(result)
7799-
except Exception as e:
7800+
except TypeError as err:
7801+
# e.g. in nanops trying to convert strs to float
78007802

78017803
# try by-column first
78027804
if filter_type is None and axis == 0:
@@ -7826,7 +7828,7 @@ def f(x):
78267828
raise NotImplementedError(
78277829
"Handling exception with filter_type {f} not"
78287830
"implemented.".format(f=filter_type)
7829-
) from e
7831+
) from err
78307832
with np.errstate(all="ignore"):
78317833
result = f(data.values)
78327834
labels = data._get_agg_axis(axis)

0 commit comments

Comments
 (0)