8000 BUG: Fix bugs found by testing in release mode. by charris · Pull Request #10193 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

BUG: Fix bugs found by testing in release mode. #10193

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 2 commits into from
Dec 11, 2017
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
23 changes: 8 additions & 15 deletions numpy/core/tests/test_multiarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -7086,21 +7086,14 @@ def test_1d_no_format(self):
def test_1d_format(self):
# until gh-5543, ensure that the behaviour matches what it used to be
a = np.array([np.pi])

def ret_and_exc(f, *args, **kwargs):
try:
return f(*args, **kwargs), None
except Exception as e:
# exceptions don't compare equal, so return type and args
# which do
return None, (type(e), e.args)

# Could switch on python version here, but all we care about is
# that the behaviour hasn't changed
assert_equal(
ret_and_exc(object.__format__, a, '30'),
ret_and_exc('{:30}'.format, a)
)
if sys.version_info[:2] >= (3, 4):
assert_raises(TypeError, '{:30}'.format, a)
else:
with suppress_warnings() as sup:
sup.filter(PendingDeprecationWarning)
res = '{:30}'.format(a)
dst = object.__format__(a, '30')
assert_equal(res, dst)


class TestCTypes(object):
Expand Down
9 changes: 6 additions & 3 deletions numpy/testing/nose_tools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,14 +394,17 @@ def assert_equal(actual, desired, err_msg='', verbose=True):
isdesnat = isnat(desired)
isactnat = isnat(actual)
dtypes_match = array(desired).dtype.type == array(actual).dtype.type
if isdesnat and isactnat and dtypes_match:
if isdesnat and isactnat:
# If both are NaT (and have the same dtype -- datetime or
# timedelta) they are considered equal.
return
if dtypes_match:
return
else:
raise AssertionError(msg)
Copy link
Member

Choose a reason for hiding this comment

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

This is at best a workaround. It doesn't solve the underlying problem, so the following still has the warning-swallowing problems:

assert_equal(np.void(b'test'), np.datetime64('2017'))

Copy link
Member Author

Choose a reason for hiding this comment

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

It may be incomplete, but I don't think it is a workaround, differing types should be handled with the NaT stuff, not passed on to "==". For the rest, I'm thinking that we should not intercept any of the warning exceptions, just raise all of them. It is only in development mode that they are raised, and those errors should also be fixed in development mode.

Copy link
Member Author

Choose a reason for hiding this comment

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

I see two approaches here for the == fallback,

  • Suppress deprecation warnings, assert_equal should do its thing regardless.
  • Let deprecation warnings raise without conversion to AssertionError

The first can lead to unexpected changes when deprecations expire, the second will generally require fixes or rewrites that could conceivably be difficult before the deprecation expires.


except (TypeError, ValueError, NotImplementedError):
pass


try:
# Explicitly use __eq__ for comparison, gh-2552
if not (desired == actual):
Expand Down
0