You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've seen a couple test failures where pytest detects a relative tolerance < 0.
In the case I have a record of it was invoked like so:
def test_transform_base_case(transform_inputs):
# assert that TransformComponent behaves in the same manner as Transform.
regular = transforms.Transform(*transform_inputs)
component = transforms.TransformComponent(*transform_inputs)
vertex1 = np.array((1, 1, 1))
vertex2 = np.array((1, 1, 1))
regular.apply(vertex1)
component.apply(vertex2)
assert_approx(vertex1, vertex2)
Where assert_approx is defined as:
def assert_approx(iter1, iter2, rel=1e-6):
for v1, v2 in zip(iter1, iter2):
assert v1 == pytest.approx(v2, rel=rel)
Resulting in:
self = -9223372036854775808 ± ???
@property
def tolerance(self):
"""Return the tolerance for the comparison.
This could be either an absolute tolerance or a relative tolerance,
depending on what the user specified or which would be larger.
"""
def set_default(x, default):
return x if x is not None else default
# Figure out what the absolute tolerance should be. ``self.abs`` is
# either None or a value specified by the user.
absolute_tolerance = set_default(self.abs, self.DEFAULT_ABSOLUTE_TOLERANCE)
if absolute_tolerance < 0:
raise ValueError(
f"absolute tolerance can't be negative: {absolute_tolerance}"
)
if math.isnan(absolute_tolerance):
raise ValueError("absolute tolerance can't be NaN.")
# If the user specified an absolute tolerance but not a relative one,
# just return the absolute tolerance.
if self.rel is None:
if self.abs is not None:
return absolute_tolerance
# Figure out what the relative tolerance should be. ``self.rel`` is
# either None or a value specified by the user. This is done after
# we've made sure the user didn't ask for an absolute tolerance only,
# because we don't want to raise errors about the relative tolerance if
# we aren't even going to use it.
relative_tolerance = set_default(
self.rel, self.DEFAULT_RELATIVE_TOLERANCE
) * abs(self.expected)
if relative_tolerance < 0:
> raise ValueError(
f"relative tolerance can't be negative: {absolute_tolerance}"
)
E ValueError: relative tolerance can't be negative: 1e-12
I'm not familiar with the rest of the source for the class and can't reproduce the error with any consistency, but at the least it seems that
if relative_tolerance < 0:
raise ValueError(
f"relative tolerance can't be negative: {absolute_tolerance}"
)
Should probably be:
if relative_tolerance < 0:
raise ValueError(
f"relative tolerance can't be negative: {relative_tolerance}"
)
The text was updated successfully, but these errors were encountered:
I've seen a couple test failures where pytest detects a relative tolerance < 0.
In the case I have a record of it was invoked like so:
Where assert_approx is defined as:
Resulting in:
I'm not familiar with the rest of the source for the class and can't reproduce the error with any consistency, but at the least it seems that
Should probably be:
The text was updated successfully, but these errors were encountered: