UCL / TLOmodel

Epidemiology modelling framework for the Thanzi la Onse project
https://www.tlomodel.org/
MIT License
12 stars 5 forks source link

Test failure in `test_two_loggers_in_healthsystem` when running on Pandas 2.0 #1127

Closed matt-graham closed 1 year ago

matt-graham commented 1 year ago

One test failure still when running with Pandas 2.0 / Python 3.11

____________ test_two_loggers_in_healthsystem[83563095832589325021] ____________
tests/test_healthsystem.py:841: in test_two_loggers_in_healthsystem
    assert summary_hsi_event['squeeze_factor'].apply(pd.Series) \
E   AssertionError: assert {('Dummy:HSI_Dummy', 2010): 113431310.40270479, ('Dummy:HSI_Dummy', 2011): 113431310.40270479, ('Inpatient_Care:Inpatient_Care', 2010): 0.0, ('Inpatient_Care:Inpatient_Care', 2011): 0.0} == {('Dummy:HSI_Dummy', 2010): 113431310.40270501, ('Dummy:HSI_Dummy', 2011): 113431310.40270501, ('Inpatient_Care:Inpatient_Care', 2010): 0.0, ('Inpatient_Care:Inpatient_Care', 2011): 0.0}
E     Common items:
E     {('Inpatient_Care:Inpatient_Care', 2010): 0.0,
E      ('Inpatient_Care:Inpatient_Care', 2011): 0.0}
E     Differing items:
E     {('Dummy:HSI_Dummy', 2010): 113431310.40270479} != {('Dummy:HSI_Dummy', 2010): 113431310.40270501}
E     {('Dummy:HSI_Dummy', 2011): 113431310.40270479} != {('Dummy:HSI_Dummy', 2011): 113431310.40270501}
E     Full diff:
E       {
E     -  ('Dummy:HSI_Dummy', 2010): 113431310.40270501,
E     ?                                            ^^^
E     +  ('Dummy:HSI_Dummy', 2010): 113431310.40270479,
E     ?                                            ^^^
E     -  ('Dummy:HSI_Dummy', 2011): 113431310.40270501,
E     ?                                            ^^^
E     +  ('Dummy:HSI_Dummy', 2011): 113431310.40270479,
E     ?                                            ^^^
E        ('Inpatient_Care:Inpatient_Care', 2010): 0.0,
E        ('Inpatient_Care:Inpatient_Care', 2011): 0.0,
E       }

Originally posted by @matt-graham in https://github.com/UCL/TLOmodel/issues/1114#issuecomment-1728951337

matt-graham commented 1 year ago

Looking at the actual numerical differences this could just be due to floating point errors arising from computation of summations in different orders. The relative difference (113431310.40270501 - 113431310.40270479) / (113431310.40270479) is of order 1e-15 which is close to machine epsilon for double precision floats. We may just need to slightly relax the assertion to use something like numpy.allclose.