Skip to content

Commit 2fb91ed

Browse files
jbrockmendeljreback
authored andcommitted
CLN: Exception catching (#28361)
1 parent 96bf661 commit 2fb91ed

File tree

3 files changed

+5
-10
lines changed

3 files changed

+5
-10
lines changed

pandas/_libs/testing.pyx

+2-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ cpdef assert_almost_equal(a, b,
139139
obj, '{0} shapes are different'.format(obj),
140140
a.shape, b.shape)
141141

142-
if check_dtype and not is_dtype_equal(a, b):
142+
if check_dtype and not is_dtype_equal(a.dtype, b.dtype):
143143
from pandas.util.testing import assert_attr_equal
144144
assert_attr_equal('dtype', a, b, obj=obj)
145145

@@ -188,6 +188,7 @@ cpdef assert_almost_equal(a, b,
188188
# object comparison
189189
return True
190190
if isna(a) and isna(b):
191+
# TODO: Should require same-dtype NA?
191192
# nan / None comparison
192193
return True
193194
if is_comparable_as_number(a) and is_comparable_as_number(b):

pandas/core/construction.py

+1-8
Original file line numberDiff line numberDiff line change
@@ -413,14 +413,7 @@ def sanitize_array(data, index, dtype=None, copy=False, raise_cast_failure=False
413413

414414
elif isinstance(data, (list, tuple)) and len(data) > 0:
415415
if dtype is not None:
416-
try:
417-
subarr = _try_cast(data, dtype, copy, raise_cast_failure)
418-
except Exception:
419-
if raise_cast_failure: # pragma: no cover
420-
raise
421-
subarr = np.array(data, dtype=object, copy=copy)
422-
subarr = lib.maybe_convert_objects(subarr)
423-
416+
subarr = _try_cast(data, dtype, copy, raise_cast_failure)
424417
else:
425418
subarr = maybe_convert_platform(data)
426419

pandas/core/indexing.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@ def _get_setitem_indexer(self, key):
175175
if isinstance(ax, ABCMultiIndex) and self.name != "iloc":
176176
try:
177177
return ax.get_loc(key)
178-
except Exception:
178+
except (TypeError, KeyError):
179+
# TypeError e.g. passed a bool
179180
pass
180181

181182
if isinstance(key, tuple):

0 commit comments

Comments
 (0)