|
6 | 6 |
|
7 | 7 | import numpy as np
|
8 | 8 | from pandas._libs import algos as libalgos, index as libindex, lib, Timestamp
|
| 9 | +from pandas._libs import tslibs |
9 | 10 |
|
10 | 11 | from pandas.compat import range, zip, lrange, lzip, map
|
11 | 12 | from pandas.compat.numpy import function as nv
|
@@ -1002,12 +1003,13 @@ def _try_mi(k):
|
1002 | 1003 | return _try_mi(key)
|
1003 | 1004 | except (KeyError):
|
1004 | 1005 | raise
|
1005 |
| - except: |
| 1006 | + except (IndexError, ValueError, TypeError): |
1006 | 1007 | pass
|
1007 | 1008 |
|
1008 | 1009 | try:
|
1009 | 1010 | return _try_mi(Timestamp(key))
|
1010 |
| - except: |
| 1011 | + except (KeyError, TypeError, |
| 1012 | + IndexError, ValueError, tslibs.OutOfBoundsDatetime): |
1011 | 1013 | pass
|
1012 | 1014 |
|
1013 | 1015 | raise InvalidIndexError(key)
|
@@ -1686,7 +1688,7 @@ def append(self, other):
|
1686 | 1688 | # if all(isinstance(x, MultiIndex) for x in other):
|
1687 | 1689 | try:
|
1688 | 1690 | return MultiIndex.from_tuples(new_tuples, names=self.names)
|
1689 |
| - except: |
| 1691 | + except (TypeError, IndexError): |
1690 | 1692 | return Index(new_tuples)
|
1691 | 1693 |
|
1692 | 1694 | def argsort(self, *args, **kwargs):
|
@@ -2315,7 +2317,7 @@ def maybe_droplevels(indexer, levels, drop_level):
|
2315 | 2317 | for i in sorted(levels, reverse=True):
|
2316 | 2318 | try:
|
2317 | 2319 | new_index = new_index.droplevel(i)
|
2318 |
| - except: |
| 2320 | + except ValueError: |
2319 | 2321 |
|
2320 | 2322 | # no dropping here
|
2321 | 2323 | return orig_index
|
@@ -2818,7 +2820,7 @@ def _convert_can_do_setop(self, other):
|
2818 | 2820 | msg = 'other must be a MultiIndex or a list of tuples'
|
2819 | 2821 | try:
|
2820 | 2822 | other = MultiIndex.from_tuples(other)
|
2821 |
| - except: |
| 2823 | + except TypeError: |
2822 | 2824 | raise TypeError(msg)
|
2823 | 2825 | else:
|
2824 | 2826 | result_names = self.names if self.names == other.names else None
|
|
0 commit comments