Skip to content

test_round_trip_floating_point vector checks never assert #1046

Description

@nikagra

Problem

test_round_trip_floating_point in TypeTestsVector never asserts, so the float, double and decimal vector round trips pass even when the values read back are wrong.

The test passes partial(pytest.approx, abs=1e-5) as the comparison callback:

def test_round_trip_floating_point(self):
_almost_equal_test_fn = partial(pytest.approx, abs=1e-5)
def _random_decimal():
return Decimal(random.uniform(0.0, 100.0))
# Max value here isn't really connected to max value for floating point nums in IEEE 754... it's used here
# mainly as a convenient benchmark
self._round_trip_test("float", partial(random.uniform, 0.0, 100.0), _almost_equal_test_fn)
self._round_trip_test("double", partial(random.uniform, 0.0, 100.0), _almost_equal_test_fn)
self._round_trip_test("decimal", _random_decimal, _almost_equal_test_fn)

_round_trip_test calls that callback as test_fn(observed, expected) and discards its return value:

if use_positional_parameters:
observed1 = self._get_row_prepared(2, table_name)
for idx in range(0, 3):
test_fn(observed1[idx], expected1[idx])
observed2 = self._get_row_simple(5, table_name)
for idx in range(0, 3):
test_fn(observed2[idx], expected2[idx])

The call becomes pytest.approx(observed, expected, abs=1e-5): expected is taken as rel, and the returned matcher is never compared with anything.

#1043 fixed the same pattern for timestamp only, because pytest 9 started rejecting relative tolerance for datetimes:

def _assert_almost_equal(observed, expected):
# Datetimes support an absolute timedelta, not relative tolerance.
assert observed == pytest.approx(expected, abs=timedelta(seconds=1), rel=None)

Impact

A regression in float, double or decimal serialization inside a vector passes CI. This is the only integration test that round-trips these vector subtypes through a server.

Reproduction

With pytest 9.1.1:

from functools import partial
from decimal import Decimal
import pytest
f = partial(pytest.approx, abs=1e-5)
f(1.0, 50.0)                      # ApproxScalar, no AssertionError
f(Decimal("1"), Decimal("50"))    # ApproxDecimal, no AssertionError

Expected behavior

The floating-point vector round trips fail when a value read back differs from the one written by more than the 1e-5 absolute tolerance. That tolerance holds for vector<float, 3>: the worst float32 rounding error for values in [0, 100) was about 3.8e-6 over 200,000 samples.

Acceptance criteria

  • Replacing an expected value with a wrong one makes each of the float, double and decimal round trips fail.

Notes

Related

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions