Skip to content

CLN: Exception catching #28361

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 1 commit into from
Sep 10, 2019
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion pandas/_libs/testing.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ cpdef assert_almost_equal(a, b,
obj, '{0} shapes are different'.format(obj),
a.shape, b.shape)

if check_dtype and not is_dtype_equal(a, b):
if check_dtype and not is_dtype_equal(a.dtype, b.dtype):
from pandas.util.testing import assert_attr_equal
assert_attr_equal('dtype', a, b, obj=obj)

Expand Down Expand Up @@ -188,6 +188,7 @@ cpdef assert_almost_equal(a, b,
# object comparison
return True
if isna(a) and isna(b):
# TODO: Should require same-dtype NA?
# nan / None comparison
return True
if is_comparable_as_number(a) and is_comparable_as_number(b):
Expand Down
9 changes: 1 addition & 8 deletions pandas/core/construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,14 +413,7 @@ def sanitize_array(data, index, dtype=None, copy=False, raise_cast_failure=False

elif isinstance(data, (list, tuple)) and len(data) > 0:
if dtype is not None:
try:
subarr = _try_cast(data, dtype, copy, raise_cast_failure)
except Exception:
if raise_cast_failure: # pragma: no cover
raise
subarr = np.array(data, dtype=object, copy=copy)
subarr = lib.maybe_convert_objects(subarr)

subarr = _try_cast(data, dtype, copy, raise_cast_failure)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How come we don't need this try anymore?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have any test cases that make it past here. I'm planning to put some more effort into trying to think up a case that would, but if I/we can't, then this is unnecessary.

else:
subarr = maybe_convert_platform(data)

Expand Down
3 changes: 2 additions & 1 deletion pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ def _get_setitem_indexer(self, key):
if isinstance(ax, ABCMultiIndex) and self.name != "iloc":
try:
return ax.get_loc(key)
except Exception:
except (TypeError, KeyError):
# TypeError e.g. passed a bool
pass

if isinstance(key, tuple):
Expand Down