diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 2208a0b878144..620e565aa55c8 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -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] @@ -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( @@ -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: @@ -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)