Skip to content

CLN: catch specific exceptions in frame.py #29258

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
Oct 29, 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
20 changes: 11 additions & 9 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1666,11 +1666,12 @@ def from_records(
else:
try:
index_data = [arrays[arr_columns.get_loc(field)] for field in index]
except (KeyError, TypeError):
# raised by get_loc, see GH#29258
result_index = index
else:
result_index = ensure_index_from_sequences(index_data, names=index)

exclude.update(index)
except Exception:
result_index = index

if any(exclude):
arr_exclude = [x for x in exclude if x in arr_columns]
Expand Down Expand Up @@ -3625,11 +3626,11 @@ def reindexer(value):
# GH 4107
try:
value = value.reindex(self.index)._values
except Exception as e:

# duplicate axis
except ValueError as err:
# raised in MultiIndex.from_tuples, see test_insert_error_msmgs
if not value.index.is_unique:
raise e
# duplicate axis
raise err

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

# try by-column first
if filter_type is None and axis == 0:
Expand Down Expand Up @@ -7826,7 +7828,7 @@ def f(x):
raise NotImplementedError(
"Handling exception with filter_type {f} not"
"implemented.".format(f=filter_type)
) from e
) from err
with np.errstate(all="ignore"):
result = f(data.values)
labels = data._get_agg_axis(axis)
Expand Down