simonw / datasette-statistics

SQL statistics functions for Datasette
8 stars 1 forks source link

Figure out why 3.6 gives slightly different numbers #5

Closed simonw closed 3 years ago

simonw commented 3 years ago

Two surprising test failures on 3.6:

function = 'statistics_stdev'
E           assert 2.0062794503020767 == 2.003581 ± 2.0e-06
E            +  where 2.0062794503020767 = <bound method Results.single_value of <datasette.database.Results object at 0x1044cc240>>()
E            +    where <bound method Results.single_value of <datasette.database.Results object at 0x1044cc240>> = <datasette.database.Results object at 0x1044cc240>.single_value

And

function = 'statistics_variance'
E           assert 4.006259780907668 == 4.0 ± 4.0e-06
E            +  where 4.006259780907668 = <bound method Results.single_value of <datasette.database.Results object at 0x104521e48>>()
E            +    where <bound method Results.single_value of <datasette.database.Results object at 0x104521e48>> = <datasette.database.Results object at 0x104521e48>.single_value

I bodged a fix for these like so but I'd like to understand what went wrong here: https://github.com/simonw/datasette-statistics/blob/5889af033ec35a11fc9a989426a7938120256ea8/tests/test_statistics.py#L30

Originally posted by @simonw in https://github.com/simonw/datasette-statistics/issues/3#issuecomment-944514485

simonw commented 3 years ago

The test here is testing the Python standard library functionality - a better test might be to confirm that the module is being called, maybe with a mock?