Skip to content
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

Update Python and packages #763

Open
tamuri opened this issue Nov 22, 2022 · 35 comments
Open

Update Python and packages #763

tamuri opened this issue Nov 22, 2022 · 35 comments

Comments

@tamuri
Copy link
Collaborator

tamuri commented Nov 22, 2022

WARNING: Don't do this until it's confirmed everything works!

We need to:

  1. Update to a recent version of Python (3.11? 3.10?)
  2. Update the package dependencies.

We've done this before in #144.

@tamuri tamuri self-assigned this Nov 22, 2022
@tamuri tamuri added this to Issues in Issue management via automation Nov 22, 2022
@tamuri
Copy link
Collaborator Author

tamuri commented Nov 22, 2022

Steps :

  1. Create a new conda environment, specifying version of Python: conda create -n tlo310 python=3.10
  2. Activate: conda activate tlo310
  3. Install requirements (note: not the file with pinned versions). In TLOmodel directory: pip install -r requirements/dev.in
  4. Install TLOmodel: pip install -e .
  5. Test:pytest

@tamuri
Copy link
Collaborator Author

tamuri commented Nov 22, 2022

Lots of errors because the old way of slicing dataframe to set categorical columns doesn't work. Column dtypes gets coerced to object. e.g. district_of_residence in demography module.

This demonstrates the problem (and possible solution):

df = pd.DataFrame(data={'is_alive':[True, True, True], 'catcol': pd.Categorical([np.nan, np.nan, np.nan], categories=['A', 'B', 'C'])})

# In [54]: df.dtypes
# Out[54]:
# is_alive        bool
# catcol      category
# dtype: object

s = pd.Series(['A', 'A', 'B'])

# this works on current version, but breaks when dependencies are updated:
df.loc[df.is_alive, 'catcol'] = s.values[:]

# gives this warning:
# <ipython-input-51-f84c3c1188d6>:1: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`

# and breaks dtypes of columns
# In [52]: df.dtypes
# Out[52]:
# is_alive      bool
# catcol      object
# dtype: object

# this way works:
df = pd.DataFrame(data={'is_alive':[True, True, True], 'catcol': pd.Categorical([np.nan, np.nan, np.nan], categories=['A', 'B', 'C'])})
df.loc[df.is_alive, 'catcol'] = s.to_list()
df.dtypes

is_alive        bool
catcol      category
dtype: object

In [56]: df.catcol.cat.categories
Out[56]: Index(['A', 'B', 'C'], dtype='object')

@matt-graham
Copy link
Collaborator

  1. Update to a recent version of Python (3.11? 3.10?)

I would vote for updating to Python 3.11 if we taking the pain of getting everything working with updated dependencies anyway as Python 3.11 has some performance improvements that can give significant speedups over 3.10 (10-60% depending on task).

@tamuri
Copy link
Collaborator Author

tamuri commented Mar 12, 2023

I think we're leaning toward using Anaconda packages. [Once we have this sorted...] I thought we could set up Dependabot to keep us up to date. There is some discussion about how to support conda envs, so might need to think of some alternative (to dependabot).

@matt-graham
Copy link
Collaborator

df = pd.DataFrame(data={'is_alive':[True, True, True], 'catcol': pd.Categorical([np.nan, np.nan, np.nan], categories=['A', 'B', 'C'])})

# In [54]: df.dtypes
# Out[54]:
# is_alive        bool
# catcol      category
# dtype: object

s = pd.Series(['A', 'A', 'B'])

# this works on current version, but breaks when dependencies are updated:
df.loc[df.is_alive, 'catcol'] = s.values[:]

# gives this warning:
# <ipython-input-51-f84c3c1188d6>:1: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`

@tamuri Can you remember which version of Pandas this breaks on? Running this example with Python 3.11 with Pandas 1.5.3 (current latest stable release) I get a deprecation warning (was previously a FutureWarning but was updated in pandas-dev/pandas#50044, see also related discussion in pandas-dev/pandas#48673), but running on Python 3.11 with Pandas 2.0.0rc1 the example runs without a warning or error (and with the dataframe updated as expected and with column datatype retained).

@matt-graham
Copy link
Collaborator

matt-graham commented Mar 27, 2023

Running the non-slow tests on Python 3.11 with Pandas 2.0.0rc1 overall test summary is

273 failed, 487 passed, 149 skipped, 20 warnings, 34 errors in 106.12s

with the main error types causing test failures are

AttributeError: 'Series' object has no attribute 'iteritems'
AttributeError: 'DataFrame' object has no attribute 'append'
TypeError: Categorical input must be list-like
TypeError: Cannot setitem on a Categorical with a new category (A), set the categories first
TypeError: Casting to unit-less dtype 'datetime64' is not supported. Pass e.g. 'datetime64[ns]' instead.
Package versions in conda environment conda list
# Name                    Version                   Build  Channel
_libgcc_mutex             0.1                 conda_forge    conda-forge
_openmp_mutex             4.5                       2_gnu    conda-forge
adal                      1.2.7                    pypi_0    pypi
asttokens                 2.2.1                    pypi_0    pypi
attrs                     22.2.0                   pypi_0    pypi
azure-batch               13.0.0                   pypi_0    pypi
azure-common              1.1.28                   pypi_0    pypi
azure-core                1.26.3                   pypi_0    pypi
azure-identity            1.12.0                   pypi_0    pypi
azure-keyvault            4.2.0                    pypi_0    pypi
azure-keyvault-certificates 4.7.0                    pypi_0    pypi
azure-keyvault-keys       4.8.0                    pypi_0    pypi
azure-keyvault-secrets    4.7.0                    pypi_0    pypi
azure-storage-file-share  12.11.1                  pypi_0    pypi
backcall                  0.2.0                    pypi_0    pypi
build                     0.10.0                   pypi_0    pypi
bzip2                     1.0.8                h7f98852_4    conda-forge
ca-certificates           2022.12.7            ha878542_0    conda-forge
cachetools                5.3.0                    pypi_0    pypi
certifi                   2022.12.7                pypi_0    pypi
cffi                      1.15.1                   pypi_0    pypi
chardet                   5.1.0                    pypi_0    pypi
charset-normalizer        3.1.0                    pypi_0    pypi
click                     8.1.3                    pypi_0    pypi
colorama                  0.4.6                    pypi_0    pypi
contourpy                 1.0.7                    pypi_0    pypi
cryptography              40.0.1                   pypi_0    pypi
cycler                    0.11.0                   pypi_0    pypi
decorator                 5.1.1                    pypi_0    pypi
distlib                   0.3.6                    pypi_0    pypi
et-xmlfile                1.1.0                    pypi_0    pypi
execnet                   1.9.0                    pypi_0    pypi
executing                 1.2.0                    pypi_0    pypi
filelock                  3.10.6                   pypi_0    pypi
fonttools                 4.39.2                   pypi_0    pypi
gitdb                     4.0.10                   pypi_0    pypi
gitpython                 3.1.31                   pypi_0    pypi
idna                      3.4                      pypi_0    pypi
iniconfig                 2.0.0                    pypi_0    pypi
ipython                   8.11.0                   pypi_0    pypi
isodate                   0.6.1                    pypi_0    pypi
jedi                      0.18.2                   pypi_0    pypi
kiwisolver                1.4.4                    pypi_0    pypi
ld_impl_linux-64          2.40                 h41732ed_0    conda-forge
libffi                    3.4.2                h7f98852_5    conda-forge
libgcc-ng                 12.2.0              h65d4601_19    conda-forge
libgomp                   12.2.0              h65d4601_19    conda-forge
libnsl                    2.0.0                h7f98852_0    conda-forge
libsqlite                 3.40.0               h753d276_0    conda-forge
libuuid                   2.32.1            h7f98852_1000    conda-forge
libzlib                   1.2.13               h166bdaf_4    conda-forge
matplotlib                3.7.1                    pypi_0    pypi
matplotlib-inline         0.1.6                    pypi_0    pypi
msal                      1.21.0                   pypi_0    pypi
msal-extensions           1.0.0                    pypi_0    pypi
msrest                    0.7.1                    pypi_0    pypi
msrestazure               0.6.4                    pypi_0    pypi
ncurses                   6.3                  h27087fc_1    conda-forge
numpy                     1.24.2                   pypi_0    pypi
oauthlib                  3.2.2                    pypi_0    pypi
openpyxl                  3.1.2                    pypi_0    pypi
openssl                   3.1.0                h0b41bf4_0    conda-forge
packaging                 23.0                     pypi_0    pypi
pandas                    2.0.0rc1                 pypi_0    pypi
parso                     0.8.3                    pypi_0    pypi
pexpect                   4.8.0                    pypi_0    pypi
pickleshare               0.7.5                    pypi_0    pypi
pillow                    9.4.0                    pypi_0    pypi
pip                       23.0.1             pyhd8ed1ab_0    conda-forge
pip-tools                 6.12.3                   pypi_0    pypi
platformdirs              3.2.0                    pypi_0    pypi
pluggy                    1.0.0                    pypi_0    pypi
portalocker               2.7.0                    pypi_0    pypi
prompt-toolkit            3.0.38                   pypi_0    pypi
ptyprocess                0.7.0                    pypi_0    pypi
pure-eval                 0.2.2                    pypi_0    pypi
pycparser                 2.21                     pypi_0    pypi
pygments                  2.14.0                   pypi_0    pypi
pyjwt                     2.6.0                    pypi_0    pypi
pyparsing                 3.0.9                    pypi_0    pypi
pyproject-api             1.5.1                    pypi_0    pypi
pyproject-hooks           1.0.0                    pypi_0    pypi
pyshp                     2.3.1                    pypi_0    pypi
pytest                    7.2.2                    pypi_0    pypi
pytest-xdist              3.2.1                    pypi_0    pypi
python                    3.11.0          he550d4f_1_cpython    conda-forge
python-dateutil           2.8.2                    pypi_0    pypi
pytz                      2023.2                   pypi_0    pypi
readline                  8.2                  h8228510_1    conda-forge
requests                  2.28.2                   pypi_0    pypi
requests-oauthlib         1.3.1                    pypi_0    pypi
scipy                     1.10.1                   pypi_0    pypi
setuptools                67.6.0             pyhd8ed1ab_0    conda-forge
six                       1.16.0                   pypi_0    pypi
smmap                     5.0.0                    pypi_0    pypi
squarify                  0.4.3                    pypi_0    pypi
stack-data                0.6.2                    pypi_0    pypi
tk                        8.6.12               h27826a3_0    conda-forge
tlo                       0.1.0                     dev_0    <develop>
tox                       4.4.8                    pypi_0    pypi
traitlets                 5.9.0                    pypi_0    pypi
typing-extensions         4.5.0                    pypi_0    pypi
tzdata                    2023b                h71feb2d_0    conda-forge
urllib3                   1.26.15                  pypi_0    pypi
virtualenv                20.21.0                  pypi_0    pypi
wcwidth                   0.2.6                    pypi_0    pypi
wheel                     0.40.0             pyhd8ed1ab_0    conda-forge
xz                        5.2.6                h166bdaf_0    conda-forge
Failed tests for pytest tests --skip-slow
ERROR tests/test_alri.py::test_integrity_of_linear_models[83563095832589325021] - TypeError: Categorical input must be list-like
ERROR tests/test_alri.py::test_basic_run[83563095832589325021] - TypeError: Categorical input must be list-like
ERROR tests/test_alri.py::test_alri_polling[83563095832589325021] - TypeError: Categorical input must be list-like
ERROR tests/test_alri.py::test_nat_hist_recovery[83563095832589325021] - TypeError: Categorical input must be list-like
ERROR tests/test_alri.py::test_nat_hist_death[83563095832589325021] - TypeError: Categorical input must be list-like
ERROR tests/test_alri.py::test_nat_hist_cure_if_recovery_scheduled[83563095832589325021] - TypeError: Categorical input must be list-like
ERROR tests/test_alri.py::test_nat_hist_cure_if_death_scheduled[83563095832589325021] - TypeError: Categorical input must be list-like
ERROR tests/test_alri.py::test_immediate_onset_complications[83563095832589325021] - TypeError: Categorical input must be list-like
ERROR tests/test_alri.py::test_no_immediate_onset_complications[83563095832589325021] - TypeError: Categorical input must be list-like
ERROR tests/test_alri.py::test_classification_based_on_symptoms_and_imci[83563095832589325021] - TypeError: Categorical input must be list-like
ERROR tests/test_alri.py::test_do_effects_of_alri_treatment[83563095832589325021] - TypeError: Categorical input must be list-like
ERROR tests/test_dxmanager.py::test_create_dx_test_and_register[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
ERROR tests/test_alri.py::test_severe_pneumonia_referral_from_hsi_first_appts[83563095832589325021] - TypeError: Categorical input must be list-like
ERROR tests/test_dxmanager.py::test_create_duplicate_test_that_should_be_allowed[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
ERROR tests/test_dxmanager.py::test_create_dx_test_and_run[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
ERROR tests/test_dxmanager.py::test_create_dx_tests_with_consumable_useage_given_by_item_code_only[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
ERROR tests/test_dxmanager.py::test_dx_tests_with_optional_consumable[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
ERROR tests/test_dxmanager.py::test_run_batch_of_dx_test_in_one_call[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
ERROR tests/test_dxmanager.py::test_create_tuple_of_dx_tests_which_fail_and_require_chain_execution[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
ERROR tests/test_dxmanager.py::test_create_dx_test_and_run_with_imperfect_sensitivity[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
ERROR tests/test_dxmanager.py::test_create_dx_test_and_run_with_bool_dx_and_imperfect_specificity[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
ERROR tests/test_dxmanager.py::test_create_dx_test_and_run_with_cont_value_and_cutoff[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
ERROR tests/test_dxmanager.py::test_create_dx_test_and_run_with_cont_dx_and_error[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
ERROR tests/test_dxmanager.py::test_dx_with_categorial[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
ERROR tests/test_dxmanager.py::test_dx_with_categorial_multiple_levels_accepted[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
ERROR tests/test_logging_end_to_end.py::TestWriteAndReadLog::test_rows_as_dicts - TypeError: Casting to unit-less dtype 'datetime64' is not supported. Pass e.g. 'datetime64[ns]' instead.
ERROR tests/test_logging_end_to_end.py::TestWriteAndReadLog::test_rows_as_individuals - TypeError: Casting to unit-less dtype 'datetime64' is not supported. Pass e.g. 'datetime64[ns]' instead.
ERROR tests/test_logging_end_to_end.py::TestWriteAndReadLog::test_log_entire_df - TypeError: Casting to unit-less dtype 'datetime64' is not supported. Pass e.g. 'datetime64[ns]' instead.
ERROR tests/test_logging_end_to_end.py::TestWriteAndReadLog::test_fixed_length_list - TypeError: Casting to unit-less dtype 'datetime64' is not supported. Pass e.g. 'datetime64[ns]' instead.
ERROR tests/test_logging_end_to_end.py::TestWriteAndReadLog::test_variable_length_list - TypeError: Casting to unit-less dtype 'datetime64' is not supported. Pass e.g. 'datetime64[ns]' instead.
ERROR tests/test_logging_end_to_end.py::TestWriteAndReadLog::test_string - TypeError: Casting to unit-less dtype 'datetime64' is not supported. Pass e.g. 'datetime64[ns]' instead.
ERROR tests/test_logging_end_to_end.py::TestWriteAndReadLog::test_categorical - TypeError: Casting to unit-less dtype 'datetime64' is not supported. Pass e.g. 'datetime64[ns]' instead.
ERROR tests/test_logging_end_to_end.py::test_parse_log_file - TypeError: Casting to unit-less dtype 'datetime64' is not supported. Pass e.g. 'datetime64[ns]' instead.
ERROR tests/test_logging_end_to_end.py::test_parsed_log_object_pickleable - TypeError: Casting to unit-less dtype 'datetime64' is not supported. Pass e.g. 'datetime64[ns]' instead.
FAILED tests/test_diarrhoea.py::test_do_when_presentation_with_diarrhoea_severe_dehydration[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_bladder_cancer.py::test_initial_config_of_pop_high_prevalence[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_diarrhoea.py::test_do_when_presentation_with_diarrhoea_severe_dehydration_dxtest_notfunctional[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_cardiometabolicdisorders.py::test_no_availability_of_consumables_for_conditions[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_bladder_cancer.py::test_initial_config_of_pop_zero_prevalence[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_diarrhoea.py::test_do_when_presentation_with_diarrhoea_non_severe_dehydration[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_bladder_cancer.py::test_initial_config_of_pop_usual_prevalence[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_cardiometabolicdisorders.py::test_no_availability_of_consumables_for_events[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_diarrhoea.py::test_run_each_of_the_HSI[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_breast_cancer.py::test_initial_config_of_pop_high_prevalence[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_diarrhoea.py::test_does_treatment_prevent_death[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_breast_cancer.py::test_initial_config_of_pop_zero_prevalence[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_diarrhoea.py::test_do_treatment_for_those_that_will_die_if_consumables_available[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_breast_cancer.py::test_initial_config_of_pop_usual_prevalence[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_diarrhoea.py::test_do_treatment_for_those_that_will_die_if_consumables_not_available[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_diarrhoea.py::test_do_treatment_for_those_that_will_not_die[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_cardiometabolicdisorders.py::test_if_health_system_cannot_run[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_diarrhoea.py::test_effect_of_vaccine[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_cardiometabolicdisorders.py::test_hsi_investigation_not_following_symptoms[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_diarrhoea.py::test_check_perfect_treatment_leads_to_zero_risk_of_death[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_cardiometabolicdisorders.py::test_hsi_investigation_following_symptoms[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_analysis.py::test_flattening_and_unflattening_multiindex - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_cardiometabolicdisorders.py::test_hsi_weight_loss_and_medication[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_analysis.py::test_get_treatment_ids - TypeError: Categorical input must be list-like
FAILED tests/test_cardiometabolicdisorders.py::test_hsi_emergency_events[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_analysis.py::test_colormap_short_treatment_id - TypeError: Categorical input must be list-like
FAILED tests/test_healthcareseeking.py::test_healthcareseeking_does_occur_from_symptom_that_does_give_healthcareseeking_behaviour[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_healthcareseeking.py::test_healthcareseeking_does_not_occurs_from_symptom_that_do_not_give_healthcareseeking_behaviour[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_healthcareseeking.py::test_healthcareseeking_does_occur_from_symptom_that_does_give_emergency_healthcareseeking_behaviour[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_consumables.py::test_use_get_consumables_by_hsi_method_get_consumables - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_healthcareseeking.py::test_no_healthcareseeking_when_no_spurious_symptoms_and_no_disease_modules[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_consumables.py::test_outputs_to_log - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_healthcareseeking.py::test_healthcareseeking_occurs_with_spurious_symptoms_only[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_healthcareseeking.py::test_healthcareseeking_occurs_with_spurious_symptoms_and_disease_modules[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_healthcareseeking.py::test_one_per_hsi_scheduled_per_day_when_emergency_and_non_emergency_symptoms_are_onset[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_healthcareseeking.py::test_force_healthcare_seeking[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_healthcareseeking.py::test_force_healthcare_seeking_control_of_behaviour_through_parameters_and_arguments[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_enhanced_lifestyle.py::test_properties_and_dtypes[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_find_events_for_person_in_event_queue.py::test_can_look_at_future_events[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_healthcareseeking.py::test_same_day_healthcare_seeking_for_emergency_symptoms[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_healthburden.py::test_run_with_healthburden_with_dummy_diseases[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_healthcareseeking.py::test_same_day_healthcare_seeking_when_using_force_healthcareseeking[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_healthburden.py::test_arithmetic_of_disability_aggregation_calcs[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_healthcareseeking.py::test_everyone_seeks_care_for_symptom_with_high_odds_ratio_of_seeking_care[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_healthburden.py::test_arithmetic_of_dalys_calcs[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_healthcareseeking.py::test_care_seeking_from_symptoms_with_intermediate_level_of_care_seeking_and_emergency[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_healthburden.py::test_airthmetic_of_lifeyearslost[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_contraception.py::test_woman_starting_contraceptive_after_birth[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_healthcareseeking.py::test_care_seeking_from_symptoms_with_different_levels_of_prob_emergency[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_healthcareseeking.py::test_persons_have_maximum_of_one_hsi_scheduled[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_hiv.py::test_art_is_initiated_for_infants[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_healthsystem.py::test_using_parameter_or_argument_to_set_service_availability[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_analysis.py::test_colormap_cause_of_death_label[83563095832589325021] - TypeError: Categorical input must be list-like
FAILED tests/test_healthsystem.py::test_HealthSystemChangeParameters[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_hiv.py::test_hsi_testandrefer_and_circ[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_contraception.py::test_occurrence_of_HSI_for_maintaining_on_and_switching_to_methods[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_hiv.py::test_hsi_testandrefer_and_behavchg[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_hiv.py::test_hsi_testandrefer_and_prep[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_hiv.py::test_hsi_testandrefer_and_art[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_hiv.py::test_hsi_art_stopped_due_to_no_drug_available_and_no_restart[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_contraception.py::test_record_of_appt_footprint_for_switching_to_methods[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_hiv.py::test_hsi_art_stopped_due_to_no_drug_available_but_will_restart[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_hiv.py::test_hsi_art_stopped_if_healthsystem_cannot_run_hsi_and_no_restart[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_antenatal_interventions.py::test_perfect_run_of_anc_contacts_no_constraints[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_healthsystem.py::test_manipulation_of_service_availability[83563095832589325021] - TypeError: Categorical input must be list-like
FAILED tests/test_hiv.py::test_hsi_art_stopped_if_healthsystem_cannot_run_hsi_but_will_restart[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_healthsystem.py::test_hsi_run_on_same_day_if_scheduled_for_same_day[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_hiv.py::test_use_dummy_version[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_contraception.py::test_correct_number_of_live_births_created[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_hiv.py::test_initialisation[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_hiv.py::test_generation_of_new_infection[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_antenatal_interventions.py::test_anc_contacts_that_should_not_run_wont_run[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_hiv.py::test_generation_of_natural_history_process_no_art[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_hiv.py::test_generation_of_natural_history_process_with_art_before_aids[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_labour.py::test_event_scheduling_for_labour_onset_and_home_birth_no_care_seeking[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_contraception.py::test_initial_distribution_of_contraception[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_hiv.py::test_generation_of_natural_history_process_with_art_after_aids[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_antenatal_interventions.py::test_daisy_chain_care_seeking_logic_to_ensure_certain_number_of_contact[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_hiv.py::test_mtct_at_birth[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_hiv.py::test_mtct_during_breastfeeding_if_mother_infected_already[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_labour.py::test_event_scheduling_for_care_seeking_during_home_birth[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_contraception.py::test_contraception_coverage_with_use_healthsystem[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_control_order_of_events.py::test_control_of_ordering_in_the_day[83563095832589325021] - AssertionError: assert () == ('EventForSta...tForEndOfDay')
FAILED tests/test_hiv.py::test_mtct_during_breastfeeding_if_mother_infected_during_breastfeeding[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_hiv.py::test_test_and_refer_event_scheduled_by_main_event_poll[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_antenatal_interventions.py::test_initiation_of_treatment_for_maternal_anaemia_during_antenatal_inpatient_care[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_hiv.py::test_aids_symptoms_lead_to_treatment_being_initiated[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_labour.py::test_event_scheduling_for_labour_onset_and_facility_delivery[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_antenatal_interventions.py::test_initiation_of_treatment_for_hypertensive_disorder_during_antenatal_inpatient_care[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_labour.py::test_event_scheduling_for_admissions_from_antenatal_inpatient_ward_for_caesarean_section[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_control_order_of_events.py::test_control_of_ordering_in_full_model[83563095832589325021] - TypeError: Categorical input must be list-like
FAILED tests/test_core.py::test_categorical - TypeError: Cannot setitem on a Categorical with a new category (A), set the categories first
FAILED tests/test_core.py::TestLoadParametersFromDataframe::test_happy_path - TypeError: Categorical input must be list-like
FAILED tests/test_core.py::TestLoadParametersFromDataframe::test_string_stripping - TypeError: Categorical input must be list-like
FAILED tests/test_core.py::TestLoadParametersFromDataframe::test_parameter_df_not_in_class - AttributeError: 'DataFrame' object has no attribute 'append'
FAILED tests/test_core.py::TestLoadParametersFromDataframe::test_invalid_list[[1, 2, 3] - TypeError: Categorical input must be list-like
FAILED tests/test_core.py::TestLoadParametersFromDataframe::test_invalid_list[[1 2, 3]] - TypeError: Categorical input must be list-like
FAILED tests/test_core.py::TestLoadParametersFromDataframe::test_invalid_list[['a' 'b', 'c']] - TypeError: Categorical input must be list-like
FAILED tests/test_core.py::TestLoadParametersFromDataframe::test_invalid_list[a] - TypeError: Categorical input must be list-like
FAILED tests/test_core.py::TestLoadParametersFromDataframe::test_invalid_list[2] - TypeError: Categorical input must be list-like
FAILED tests/test_core.py::TestLoadParametersFromDataframe::test_invalid_date[[1, 2, 3]] - TypeError: Categorical input must be list-like
FAILED tests/test_core.py::TestLoadParametersFromDataframe::test_invalid_date[monday] - TypeError: Categorical input must be list-like
FAILED tests/test_core.py::TestLoadParametersFromDataframe::test_invalid_date[False] - TypeError: Categorical input must be list-like
FAILED tests/test_core.py::TestLoadParametersFromDataframe::test_skip_dataframe_and_series - TypeError: Categorical input must be list-like
FAILED tests/test_demography.py::test_run_dtypes_and_mothers_female[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_demography.py::test_storage_of_cause_of_death[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_antenatal_interventions.py::test_initiation_of_treatment_for_gestational_diabetes_during_antenatal_inpatient_care[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_maternal_health_helper_and_analysis_functions.py::test_analysis_events_circumnavigates_sf_and_competency_parameters[83563095832589325021] - TypeError: Categorical input must be list-like
FAILED tests/test_demography.py::test_py_calc[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_demography.py::test_py_calc_w_mask[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_demography.py::test_max_age_initial[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_measles.py::test_single_person[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_demography.py::test_ageing_of_old_people_up_to_max_age[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_module_dependencies.py::test_module_dependencies_allow_initialisation[83563095832589325021-HealthBurden] - Failed: Module HealthBurden appears to be missing dependency declarations required to run initialise_population and initialise_...
FAILED tests/test_labour.py::test_application_of_risk_of_complications_in_intrapartum_and_postpartum_phases[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_module_dependencies.py::test_module_dependencies_allow_initialisation[83563095832589325021-HealthSeekingBehaviour] - Failed: Module HealthSeekingBehaviour appears to be missing dependency declarations required to run initialise_population and i...
FAILED tests/test_module_dependencies.py::test_module_dependencies_allow_initialisation[83563095832589325021-Alri] - Failed: Module Alri appears to be missing dependency declarations required to run initialise_population and initialise_simulati...
FAILED tests/test_module_dependencies.py::test_module_dependencies_allow_initialisation[83563095832589325021-AlriPropertiesOfOtherModules] - Failed: Module AlriPropertiesOfOtherModules appears to be missing dependency declarations required to run initialise_population...
FAILED tests/test_module_dependencies.py::test_module_dependencies_allow_initialisation[83563095832589325021-HealthSystem] - Failed: Module HealthSystem appears to be missing dependency declarations required to run initialise_population and initialise_...
FAILED tests/test_module_dependencies.py::test_module_dependencies_allow_initialisation[83563095832589325021-DummyHivModule] - Failed: Module DummyHivModule appears to be missing dependency declarations required to run initialise_population and initialis...
FAILED tests/test_module_dependencies.py::test_module_dependencies_allow_initialisation[83563095832589325021-BladderCancer] - Failed: Module BladderCancer appears to be missing dependency declarations required to run initialise_population and initialise...
FAILED tests/test_module_dependencies.py::test_module_dependencies_allow_initialisation[83563095832589325021-BreastCancer] - Failed: Module BreastCancer appears to be missing dependency declarations required to run initialise_population and initialise_...
FAILED tests/test_antenatal_interventions.py::test_initiation_of_treatment_for_prom_with_or_without_chorioamnionitis_during_antenatal_inpatient_care[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_labour.py::test_logic_within_death_and_still_birth_events[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_antenatal_interventions.py::test_initiation_of_treatment_for_antepartum_haemorrhage_during_antenatal_inpatient_care[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_labour.py::test_bemonc_treatments_are_delivered_correctly_with_no_cons_or_quality_constraints_via_functions[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_module_dependencies.py::test_module_dependencies_allow_initialisation[83563095832589325021-Hiv] - Failed: Module Hiv appears to be missing dependency declarations required to run initialise_population and initialise_simulatio...
FAILED tests/test_module_dependencies.py::test_module_dependencies_allow_initialisation[83563095832589325021-CardioMetabolicDisorders] - Failed: Module CardioMetabolicDisorders appears to be missing dependency declarations required to run initialise_population and...
FAILED tests/test_antenatal_interventions.py::test_scheduling_and_treatment_effect_of_post_abortion_care[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_labour.py::test_cemonc_event_and_treatments_are_delivered_correct_with_no_cons_or_quality_constraints[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_antenatal_interventions.py::test_scheduling_and_treatment_effect_of_ectopic_pregnancy_case_management[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_module_dependencies.py::test_module_dependencies_allow_initialisation[83563095832589325021-Deviance] - Failed: Module Deviance appears to be missing dependency declarations required to run initialise_population and initialise_simu...
FAILED tests/test_module_dependencies.py::test_module_dependencies_allow_initialisation[83563095832589325021-CareOfWomenDuringPregnancy] - Failed: Module CareOfWomenDuringPregnancy appears to be missing dependency declarations required to run initialise_population a...
FAILED tests/test_antenatal_interventions.py::test_focused_anc_scheduling[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_basic_sims.py::test_make_test_property[83563095832589325021] - AssertionError: Series are different
FAILED tests/test_module_dependencies.py::test_module_dependencies_allow_initialisation[83563095832589325021-ChronicSyndrome] - Failed: Module ChronicSyndrome appears to be missing dependency declarations required to run initialise_population and initiali...
FAILED tests/test_basic_sims.py::test_birth_and_death - AttributeError: 'DataFrame' object has no attribute 'append'
FAILED tests/test_beddays.py::test_beddays_in_isolation[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_beddays.py::test_bed_days_basics[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_beddays.py::test_bed_days_property_is_inpatient[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_beddays.py::test_bed_days_released_on_death[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_beddays.py::test_bed_days_basics_with_healthsystem_disabled[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_beddays.py::test_the_use_of_beds_from_multiple_facilities[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_beddays.py::test_bed_days_allocation_to_HSI[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_beddays.py::test_bed_days_allocation_information_is_provided_to_HSI[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_beddays.py::test_in_patient_appt_included_and_logged[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_module_dependencies.py::test_module_dependencies_allow_initialisation[83563095832589325021-Labour] - Failed: Module Labour appears to be missing dependency declarations required to run initialise_population and initialise_simula...
FAILED tests/test_module_dependencies.py::test_module_dependencies_allow_initialisation[83563095832589325021-Contraception] - Failed: Module Contraception appears to be missing dependency declarations required to run initialise_population and initialise...
FAILED tests/test_module_dependencies.py::test_module_dependencies_allow_initialisation[83563095832589325021-Demography] - Failed: Module Demography appears to be missing dependency declarations required to run initialise_population and initialise_si...
FAILED tests/test_malaria.py::test_dx_algorithm_for_malaria_outcomes[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_module_dependencies.py::test_module_dependencies_allow_initialisation[83563095832589325021-Malaria] - Failed: Module Malaria appears to be missing dependency declarations required to run initialise_population and initialise_simul...
FAILED tests/test_module_dependencies.py::test_module_dependencies_allow_initialisation[83563095832589325021-Measles] - Failed: Module Measles appears to be missing dependency declarations required to run initialise_population and initialise_simul...
FAILED tests/test_module_dependencies.py::test_module_dependencies_allow_initialisation[83563095832589325021-Mockitis] - Failed: Module Mockitis appears to be missing dependency declarations required to run initialise_population and initialise_simu...
FAILED tests/test_module_dependencies.py::test_module_dependencies_allow_initialisation[83563095832589325021-Depression] - Failed: Module Depression appears to be missing dependency declarations required to run initialise_population and initialise_si...
FAILED tests/test_malaria.py::test_dx_algorithm_for_non_malaria_outcomes[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_module_dependencies.py::test_module_dependencies_allow_initialisation[83563095832589325021-Diarrhoea] - Failed: Module Diarrhoea appears to be missing dependency declarations required to run initialise_population and initialise_sim...
FAILED tests/test_module_dependencies.py::test_module_dependencies_allow_initialisation[83563095832589325021-DiarrhoeaPropertiesOfOtherModules] - Failed: Module DiarrhoeaPropertiesOfOtherModules appears to be missing dependency declarations required to run initialise_popul...
FAILED tests/test_module_dependencies.py::test_module_dependencies_allow_initialisation[83563095832589325021-Lifestyle] - Failed: Module Lifestyle appears to be missing dependency declarations required to run initialise_population and initialise_sim...
FAILED tests/test_module_dependencies.py::test_module_dependencies_allow_initialisation[83563095832589325021-Epi] - Failed: Module Epi appears to be missing dependency declarations required to run initialise_population and initialise_simulatio...
FAILED tests/test_module_dependencies.py::test_module_dependencies_allow_initialisation[83563095832589325021-Epilepsy] - Failed: Module Epilepsy appears to be missing dependency declarations required to run initialise_population and initialise_simu...
FAILED tests/test_malaria.py::test_severe_malaria_deaths_perfect_treatment[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_malaria.py::test_severe_malaria_deaths_treatment_failure[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_module_dependencies.py::test_module_dependencies_allow_initialisation[83563095832589325021-NewbornOutcomes] - Failed: Module NewbornOutcomes appears to be missing dependency declarations required to run initialise_population and initiali...
FAILED tests/test_module_dependencies.py::test_module_dependencies_allow_initialisation[83563095832589325021-OesophagealCancer] - Failed: Module OesophagealCancer appears to be missing dependency declarations required to run initialise_population and initia...
FAILED tests/test_module_dependencies.py::test_module_dependencies_allow_initialisation[83563095832589325021-OtherAdultCancer] - Failed: Module OtherAdultCancer appears to be missing dependency declarations required to run initialise_population and initial...
FAILED tests/test_module_dependencies.py::test_module_dependencies_allow_initialisation[83563095832589325021-Tb] - Failed: Module Tb appears to be missing dependency declarations required to run initialise_population and initialise_simulation...
FAILED tests/test_module_dependencies.py::test_module_dependencies_allow_initialisation[83563095832589325021-Wasting] - Failed: Module Wasting appears to be missing dependency declarations required to run initialise_population and initialise_simul...
FAILED tests/test_other_adult_cancers.py::test_initial_config_of_pop_high_prevalence[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_newborn_outcomes.py::test_to_check_babies_delivered_in_facility_receive_post_birth_care[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_other_adult_cancers.py::test_initial_config_of_pop_zero_prevalence[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_maternal_health_helper_and_analysis_functions.py::test_analysis_analysis_events_run_as_expected_and_update_parameters[83563095832589325021] - TypeError: Categorical input must be list-like
FAILED tests/test_other_adult_cancers.py::test_initial_config_of_pop_usual_prevalence[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_other_adult_cancers.py::test_check_progression_through_stages_is_blocked_by_treatment[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_module_dependencies.py::test_module_dependencies_allow_initialisation[83563095832589325021-PostnatalSupervisor] - Failed: Module PostnatalSupervisor appears to be missing dependency declarations required to run initialise_population and init...
FAILED tests/test_newborn_outcomes.py::test_to_check_babies_delivered_at_home_dont_receive_post_birth_care[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_postnatal.py::test_antenatal_disease_is_correctly_carried_over_to_postnatal_period_on_birth[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_newborn_outcomes.py::test_care_seeking_for_babies_delivered_at_home_who_develop_complications[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_maternal_health_helper_and_analysis_functions.py::test_analysis_events_force_availability_of_consumables_when_scheduled_in_anc[83563095832589325021] - TypeError: Categorical input must be list-like
FAILED tests/test_postnatal.py::test_application_of_maternal_complications_and_care_seeking_postnatal_week_one_event[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_module_dependencies.py::test_module_dependencies_allow_initialisation[83563095832589325021-PregnancySupervisor] - Failed: Module PregnancySupervisor appears to be missing dependency declarations required to run initialise_population and init...
FAILED tests/test_module_dependencies.py::test_module_dependencies_allow_initialisation[83563095832589325021-ProstateCancer] - Failed: Module ProstateCancer appears to be missing dependency declarations required to run initialise_population and initialis...
FAILED tests/test_module_dependencies.py::test_module_dependencies_allow_initialisation[83563095832589325021-RTI] - Failed: Module RTI appears to be missing dependency declarations required to run initialise_population and initialise_simulatio...
FAILED tests/test_newborn_outcomes.py::test_twin_and_single_twin_still_birth_logic_for_twins[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_module_dependencies.py::test_module_dependencies_allow_initialisation[83563095832589325021-Schisto] - Failed: Module Schisto appears to be missing dependency declarations required to run initialise_population and initialise_simul...
FAILED tests/test_module_dependencies.py::test_module_dependencies_allow_initialisation[83563095832589325021-SimplifiedBirths] - Failed: Module SimplifiedBirths appears to be missing dependency declarations required to run initialise_population and initial...
FAILED tests/test_module_dependencies.py::test_module_dependencies_allow_initialisation[83563095832589325021-Stunting] - Failed: Module Stunting appears to be missing dependency declarations required to run initialise_population and initialise_simu...
FAILED tests/test_module_dependencies.py::test_module_dependencies_allow_initialisation[83563095832589325021-StuntingPropertiesOfOtherModules] - Failed: Module StuntingPropertiesOfOtherModules appears to be missing dependency declarations required to run initialise_popula...
FAILED tests/test_module_dependencies.py::test_module_dependencies_allow_initialisation[83563095832589325021-SymptomManager] - Failed: Module SymptomManager appears to be missing dependency declarations required to run initialise_population and initialis...
FAILED tests/test_postnatal.py::test_application_of_neonatal_complications_and_care_seeking_postnatal_week_one_event[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_module_dependencies.py::test_module_dependencies_allow_initialisation[83563095832589325021-DummyTbModule] - Failed: Module DummyTbModule appears to be missing dependency declarations required to run initialise_population and initialise...
FAILED tests/test_newborn_outcomes.py::test_care_seeking_for_twins_delivered_at_home_who_develop_complications[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_maternal_health_helper_and_analysis_functions.py::test_analysis_events_force_availability_of_consumables_for_sba_analysis[83563095832589325021] - TypeError: Categorical input must be list-like
FAILED tests/test_postnatal.py::test_application_of_risk_of_death_to_mothers_postnatal_week_one_event[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_pregnancy_supervisor.py::test_store_dalys_in_mni_function_and_daly_calculations[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_newborn_outcomes.py::test_on_birth_applies_risk_of_complications_and_death_in_term_newborns_delivered_at_home_correctly[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_postnatal.py::test_application_of_risk_of_death_to_neonates_postnatal_week_one_event[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_pregnancy_supervisor.py::test_calculation_of_gestational_age[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_newborn_outcomes.py::test_on_birth_applies_risk_of_complications_and_death_in_preterm_newborns_delivered_at_home_correctly[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_maternal_health_helper_and_analysis_functions.py::test_analysis_events_force_availability_of_consumables_for_pnc_analysis[83563095832589325021] - TypeError: Categorical input must be list-like
FAILED tests/test_postnatal.py::test_application_of_risk_of_infection_and_sepsis_postnatal_supervisor_event[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_pregnancy_supervisor.py::test_application_of_risk_of_twin_pregnancy[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_newborn_outcomes.py::test_newborn_sba_hsi_deliveries_resuscitation_treatment_as_expected[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_postnatal.py::test_application_of_risk_of_spph_postnatal_supervisor_event[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_pregnancy_supervisor.py::test_spontaneous_abortion_ends_pregnancies_as_expected[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_newborn_outcomes.py::test_newborn_postnatal_check_hsi_delivers_treatment_as_expected[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_oesophagealcancer.py::test_initial_config_of_pop_high_prevalence[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_maternal_health_helper_and_analysis_functions.py::test_analysis_events_force_availability_of_consumables_for_newborn_hsi[83563095832589325021] - TypeError: Categorical input must be list-like
FAILED tests/test_oesophagealcancer.py::test_initial_config_of_pop_zero_prevalence[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_postnatal.py::test_application_of_risk_of_anaemia_postnatal_supervisor_event[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_oesophagealcancer.py::test_initial_config_of_pop_usual_prevalence[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_pregnancy_supervisor.py::test_induced_abortion_ends_pregnancies_as_expected[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_prostate_cancer.py::test_initial_config_of_pop_high_prevalence[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_prostate_cancer.py::test_initial_config_of_pop_zero_prevalence[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_prostate_cancer.py::test_initial_config_of_pop_usual_prevalence[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_prostate_cancer.py::test_check_progression_through_stages_is_blocked_by_treatment[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_simplified_births.py::test_pregnancy_and_birth_for_one_woman[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_simplified_births.py::test_no_pregnancy_among_in_ineligible_populations[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_simplified_births.py::test_no_births_if_no_one_is_pregnant[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_stunting.py::test_models[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_postnatal.py::test_application_of_risk_of_hypertensive_disorders_postnatal_supervisor_event[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_pregnancy_supervisor.py::test_abortion_complications[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_stunting.py::test_polling_event_onset[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_stunting.py::test_polling_event_recovery[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_pregnancy_supervisor.py::test_pregnancy_supervisor_placental_conditions_and_antepartum_haemorrhage[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_stunting.py::test_polling_event_progression[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_stunting.py::test_routine_assessment_for_chronic_undernutrition_if_stunted_and_correctly_diagnosed[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_stunting.py::test_routine_assessment_for_chronic_undernutrition_if_stunted_but_no_checking[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_stunting.py::test_routine_assessment_for_chronic_undernutrition_if_not_stunted[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_stunting.py::test_math_of_incidence_calcs[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_postnatal.py::test_application_of_risk_of_late_onset_neonatal_sepsis[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_symptommanager.py::test_no_symptoms_if_no_diseases[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_pregnancy_supervisor.py::test_still_births_ends_pregnancies_as_expected[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_symptommanager.py::test_spurious_symptoms_during_simulation[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_symptommanager.py::test_adding_quering_and_removing_symptoms[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_symptommanager.py::test_disease_module_in_recognised_module_names[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_symptommanager.py::test_baby_born_has_no_symptoms[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_symptommanager.py::test_disease_module_symptoms_registered[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_symptommanager.py::test_auto_onset_symptom[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_pregnancy_supervisor.py::test_pregnancy_supervisor_pre_eclampsia_and_progression[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_symptommanager.py::test_who_has_single_symptom[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_symptommanager.py::test_who_has_multiple_symptoms[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_symptommanager.py::test_have_what[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_symptommanager.py::test_who_not_have[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_symptommanager.py::test_causes_of[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_symptommanager.py::test_has_what[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_symptommanager.py::test_clear_symptoms_individual[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_symptommanager.py::test_has_what_disease_module[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_symptommanager.py::test_clear_symptoms_multiple_persons[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_pregnancy_supervisor.py::test_run_all_births_end_ectopic_no_care_seeking[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_symptommanager.py::test_add_symptom_individual_single_symptom[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_symptommanager.py::test_remove_symptom_individual_single_symptom[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_symptommanager.py::test_add_symptom_multiple_persons_single_symptom[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_symptommanager.py::test_remove_symptom_multiple_persons_single_symptom[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_symptommanager.py::test_change_symptom_individual_multiple_symptoms[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_pregnancy_supervisor.py::test_pregnancy_supervisor_gestational_hypertension_and_progression[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_symptommanager.py::test_change_symptom_multiple_persons_multiple_symptoms[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_tb.py::test_natural_history[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_tb.py::test_basic_run[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_tb.py::test_treatment_schedule[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_tb.py::test_treatment_failure[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_pregnancy_supervisor.py::test_preterm_labour_logic[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_tb.py::test_relapse_risk[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_tb.py::test_children_referrals[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_tb.py::test_ipt_to_child_of_tb_mother[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_pregnancy_supervisor.py::test_pregnancy_supervisor_gdm[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_tb.py::test_mdr[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_tb.py::test_cause_of_death[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_utils.py::test_logs_parsing - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_tb.py::test_active_tb_linear_model[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_pregnancy_supervisor.py::test_check_first_anc_visit_scheduling[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_pregnancy_supervisor.py::test_pregnancy_supervisor_chorio_and_prom[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_pregnancy_supervisor.py::test_pregnancy_supervisor_anaemia[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'
FAILED tests/test_pregnancy_supervisor.py::test_induction_of_labour_logic[83563095832589325021] - AttributeError: 'Series' object has no attribute 'iteritems'

@tamuri
Copy link
Collaborator Author

tamuri commented Mar 27, 2023

I get a deprecation warning (was previously a FutureWarning

Sorry, I didn't know pandas version at that time but, yes, must have been an older version. I'm getting deprecation warning too now.

@matt-graham
Copy link
Collaborator

@tamuri and I discussed this issue in a meeting today (2023/03/27). The initial plan is to target getting both all tests passing with updated dependencies plus exact reproducibility (in terms of elementwise equality of final population data frame) of a run of the src/scripts/profiling/scale_run.py script compared to running with the current dependency versions. We will aim to target Python 3.11 (which has been out since October 2022 and now has relatively good support in downstream Python packages) given there are quite significant performance gains out of the box compared to previous Python versions. For Pandas, the current latest stable release is v1.5.3, with a v2.0.0 release candidate available but no stable version yet (tracking issue pandas-dev/pandas#46776 suggests there may be a stable release in the next week or two). For now we will aim to test any changes against both v1.5.3 and v2.0.0 with the aim of being able to run against v2.0.0 when it's released given this also has some major performance improvements.

In terms of managing the transition, as a rough plan we may create a 'meta' branch / PR to track the changes needed to run successfully on the updated dependencies, with smaller PRs being made against this branch to deal with fixes for individual issues / failing tests, to facilitate splitting the work up. Similarly we will probably use this issue as meta-issue to track overall progress but create a task list / sub issues for specific changes.

@tamuri
Copy link
Collaborator Author

tamuri commented Mar 28, 2023

Another factor: how do we plan to roll this out? Will the updates be such that one will need the new environment as soon as they merge master? Or is there a grace period? I guess this is somewhat related to which versions we target. Do we make the necessary changes to allow updating the stack, whilst letting the code still run on existing version (e.g. v1.2.2 & v2 on pandas).

That might not be desirable, in which case we need to have a "move day"

@matt-graham
Copy link
Collaborator

/run python3.11-pandas2.0-all-tests

1 similar comment
@matt-graham
Copy link
Collaborator

/run python3.11-pandas2.0-all-tests

@ucl-comment-bot
Copy link

Run of all tests on Python v3.11 with Pandas v2.0 failed ❌

🆔 12512251308
⏲️ 0.00 minutes
#️⃣ 9d93c77

@matt-graham
Copy link
Collaborator

matt-graham commented Apr 4, 2023

Workflow run failed as it looks like our self-hosted runners don't run with passwordless sudo like GitHub hosted runners.

Might be worth updating test runners to install Python 3.11 therefore. Alternatively I could try using the setup-python action.

@tamuri
Copy link
Collaborator Author

tamuri commented Apr 5, 2023

Thanks, Matt. I've installed 3.11 on the test runners. The tox configuration didn't pick up the right version until I added {py311}: {env:TOXPYTHON:python3.11} to the basepython entry in tox.ini:

TLOmodel/tox.ini

Lines 15 to 17 in 9d93c77

basepython =
{py38,docs,profile}: {env:TOXPYTHON:python3.8}
{clean,check,report,codecov,spell}: {env:TOXPYTHON:python3}

I've not pushed that fix in case you wanted it to work some other way.

Later on, we can use conda to handle installation of right version of python as well as dependencies, and update tox to use that too.

@matt-graham
Copy link
Collaborator

Thanks @tamuri, I've submitted a new PR to remove the installation commands from the workflow jobs and update the tox configuration. Do you know what tox version is installed on the test runners? The documentation suggests that basepython shouldn't need to be specified when using environments with naming scheme py{xy} where x is major version number and y is minor version number, but it doesn't explicitly state what tox version this behaviour was added in.

@matt-graham
Copy link
Collaborator

/run python3.11-pandas2.0-all-tests

@ucl-comment-bot
Copy link

Run of all tests on Python v3.11 with Pandas v2.0 failed ❌

🆔 12538547731
⏲️ 628 minutes
#️⃣ 5655119

@matt-graham
Copy link
Collaborator

Running the tests locally from latest master plus the fixes in #910 and #911 nearly everything now seems to pass in Pandas v2.0. I did get a single test failure

tests/test_demography.py:272: in test_py_calc
    np.testing.assert_allclose(0, df_py['M'][1:])
../../miniconda3/envs/tlo-py311-pandas2/lib/python3.11/contextlib.py:81: in inner
    return func(*args, **kwds)
E   AssertionError:
E   Not equal to tolerance rtol=1e-07, atol=0
E
E   Mismatched elements: 1 / 120 (0.833%)
E   Max absolute difference: 0.75
E   Max relative difference: 1.
E    x: array(0)
E    y: array([0.75, 0.  , 0.  , 0.  , 0.  , 0.  , 0.  , 0.  , 0.  , 0.  , 0.  ,
E          0.  , 0.  , 0.  , 0.  , 0.  , 0.  , 0.  , 0.  , 0.  , 0.  , 0.  ,
E          0.  , 0.  , 0.  , 0.  , 0.  , 0.  , 0.  , 0.  , 0.  , 0.  , 0.  ,...

when running all tests with pytest-xdist with pytest tests -n 4, however on repeatedly re running just that specific test without pytest-xdist it appears to pass, as it does if I run all the tests in tests/test_demography.py with pytest tests/test_demography.py -n 4. Not entirely sure what is going therefore, but to exclude this being something about using pytest-xdist I will run all the tests on the GitHub Actions runners once #910 and #911 are merged in.

Have now started looking in to consistency in the population dataframes outputted using different Pandas versions. There does appear to currently be some differences - mainly concentrated in symptom columns and the un_HAZ_category property from Stunting. Currently trying to dig out why these arise.

@matt-graham
Copy link
Collaborator

/run python3.11-pandas2.0-all-tests

@matt-graham
Copy link
Collaborator

Have now started looking in to consistency in the population dataframes outputted using different Pandas versions. There does appear to currently be some differences - mainly concentrated in symptom columns and the un_HAZ_category property from Stunting. Currently trying to dig out why these arise.

With the fix in #943 population dataframes when running python src/scripts/profiling/scale_run.py --years 0 --months 1 --save-final-population using Panda v1.2.2 and v2.0.0 are now equal to each other. The checksum printed in the logs do not match, which I suspect means the checksum computation is not invariant over Pandas versions, but loading both pickled dataframes in Pandas v2.0.0 using pandas.read_pickle (using pickle.load directly to load dataframe pickled using older Pandas version fails) indicates equality between the dataframes using the DataFrame.equals method. Will repeat check for longer simulations to see if we still keep consistent results over more realistic simulation lengths.

@ucl-comment-bot
Copy link

Run of all tests on Python v3.11 with Pandas v2.0 failed ❌

🆔 12805460924
⏲️ 863 minutes
#️⃣ d6dc5d8

@matt-graham
Copy link
Collaborator

Same single test tests/test_demography.py:272: in test_py_calc failed in Actions run so doesn't seem like it is anything to do with pytest-xdist. Still can't reproduce this locally when running just this test or all tests in tests/test_demography.py so a bit confused at what is going on here, unless we are some how accidentally doing something stateful in the tests in another test module which is affecting things here.

Runs of scale_run.py over 1 year on Pandas v1.2.2 and v2.0.0 also gave non-equal final population dataframes. On the plus side the differences were all confined to a small set of columns corresponding to boolean properties in the lifestyle module

{'li_exposed_to_campaign_alcohol_reduction',
 'li_exposed_to_campaign_exercise_increase',
 'li_exposed_to_campaign_quit_smoking',
 'li_exposed_to_campaign_salt_reduction',
 'li_exposed_to_campaign_sugar_reduction',
 'li_exposed_to_campaign_weight_reduction'}

and in all cases seem to be that the values are True in Pandas v1.2.2 and False in v2.0.0 so likely this should be a relatively localised fix.

@matt-graham
Copy link
Collaborator

matt-graham commented Apr 18, 2023

Changes in #944 fix the problem causing divergence in population dataframes when running with Pandas v1.2.2 vs v2.0.0 in lifestyle related properties described above (see #944 (comment)). Now running a full 20 year run of scale_run.py script on both Pandas versions to see if we still get consistent outputs over that time period.

@matt-graham
Copy link
Collaborator

Failure in tests/test_demography.py::test_py_calc seems to be due to the simulation.modules["Demography"].AGE_RANGE_LOOKUP dictionary, which is a class level attribute and so shared between all instances of Simulation, getting altered somewhere from the usual default of

{0: '0-4', 1: '0-4', 2: '0-4', 3: '0-4', 4: '0-4', 5: '5-9', 6: '5-9', 7: '5-9', 8: '5-9', 9: '5-9', 10: '10-14', 11: '10-14', 12: '10-14', 13: '10-14', 14: '10-14', 15: '15-19', 16: '15-19', 17: '15-19', 18: '15-19', 19: '15-19', 20: '20-24', 21: '20-24', 22: '20-24', 23: '20-24', 24: '20-24', 25: '25-29', 26: '25-29', 27: '25-29', 28: '25-29', 29: '25-29', 30: '30-34', 31: '30-34', 32: '30-34', 33: '30-34', 34: '30-34', 35: '35-39', 36: '35-39', 37: '35-39', 38: '35-39', 39: '35-39', 40: '40-44', 41: '40-44', 42: '40-44', 43: '40-44', 44: '40-44', 45: '45-49', 46: '45-49', 47: '45-49', 48: '45-49', 49: '45-49', 50: '50-54', 51: '50-54', 52: '50-54', 53: '50-54', 54: '50-54', 55: '55-59', 56: '55-59', 57: '55-59', 58: '55-59', 59: '55-59', 60: '60-64', 61: '60-64', 62: '60-64', 63: '60-64', 64: '60-64', 65: '65-69', 66: '65-69', 67: '65-69', 68: '65-69', 69: '65-69', 70: '70-74', 71: '70-74', 72: '70-74', 73: '70-74', 74: '70-74', 75: '75-79', 76: '75-79', 77: '75-79', 78: '75-79', 79: '75-79', 80: '80-84', 81: '80-84', 82: '80-84', 83: '80-84', 84: '80-84', 85: '85-89', 86: '85-89', 87: '85-89', 88: '85-89', 89: '85-89', 90: '90-94', 91: '90-94', 92: '90-94', 93: '90-94', 94: '90-94', 95: '95-99', 96: '95-99', 97: '95-99', 98: '95-99', 99: '95-99'}

to

{0: '0-4', 1: '0-4', 2: '0-4', 3: '0-4', 4: '0-4', 5: '5-9', 6: '5-9', 7: '5-9', 8: '5-9', 9: '5-9', 10: '10-14', 11: '10-14', 12: '10-14', 13: '10-14', 14: '10-14', 15: '15-19', 16: '15-19', 17: '15-19', 18: '15-19', 19: '15-19', 20: '20-24', 21: '20-24', 22: '20-24', 23: '20-24', 24: '20-24', 25: '25-29', 26: '25-29', 27: '25-29', 28: '25-29', 29: '25-29', 30: '30-34', 31: '30-34', 32: '30-34', 33: '30-34', 34: '30-34', 35: '35-39', 36: '35-39', 37: '35-39', 38: '35-39', 39: '35-39', 40: '40-44', 41: '40-44', 42: '40-44', 43: '40-44', 44: '40-44', 45: '45-49', 46: '45-49', 47: '45-49', 48: '45-49', 49: '45-49', 50: '50-54', 51: '50-54', 52: '50-54', 53: '50-54', 54: '50-54', 55: '55-59', 56: '55-59', 57: '55-59', 58: '55-59', 59: '55-59', 60: '60-64', 61: '60-64', 62: '60-64', 63: '60-64', 64: '60-64', 65: '65-69', 66: '65-69', 67: '65-69', 68: '65-69', 69: '65-69', 70: '70-74', 71: '70-74', 72: '70-74', 73: '70-74', 74: '70-74', 75: '75-79', 76: '75-79', 77: '75-79', 78: '75-79', 79: '75-79', 80: '80-84', 81: '80-84', 82: '80-84', 83: '80-84', 84: '80-84', 85: '85-89', 86: '85-89', 87: '85-89', 88: '85-89', 89: '85-89', 90: '90-94', 91: '90-94', 92: '90-94', 93: '90-94', 94: '90-94', 95: '95-99', 96: '95-99', 97: '95-99', 98: '95-99', 99: '95-99', 100: '100+', 101: '100+', 102: '100+', 103: '100+', 104: '100+', 105: '100+', 106: '100+', 107: '100+', 108: '100+', 109: '100+', 110: '100+', 111: '100+', 112: '100+', 113: '100+', 114: '100+', 115: '100+', 116: '100+', 117: '100+', 118: '100+', 119: '100+', -1: '100+'}

As calc_py_lived_in_last_year uses the keys of the AGE_RANGE_LOOKUP dictionary to set the index of the returned py dataframe

py = pd.DataFrame(
index=pd.Index(data=list(self.AGE_RANGE_LOOKUP.keys()), name='age_years'),
columns=['M', 'F'],
data=0.0
)

the alteration to AGE_RANGE_LOOKUP changes the index of the df_py dataframe in the test, that is df_py is equal to

             F     M
age_years
-1         0.0  0.00
 0         0.0  0.75
 1         0.0  0.00
 2         0.0  0.00
 3         0.0  0.00
...        ...   ...
 115       0.0  0.00
 116       0.0  0.00
 117       0.0  0.00
 118       0.0  0.00
 119       0.0  0.00

rather than

             F     M
age_years
0          0.0  0.75
1          0.0  0.00
2          0.0  0.00
3          0.0  0.00
4          0.0  0.00
...        ...   ...
95         0.0  0.00
96         0.0  0.00
97         0.0  0.00
98         0.0  0.00
99         0.0  0.00

with the first entry in the dataframe no longer at index 0. Indexing in the test with loc rather than implicitly using iloc by indexing directly would ensure the index label rather than integer position is used and so make sure the test passes even if the age range lookup keys have been altered.

I assume the alteration of AGE_RANGE_LOOKUP is happening in one of the other tests in another test module which runs before the tests/test_demography.py::test_py_calc test when running all tests, which is why the failure only appears to occur when running all tests rather than the test individually or all the tests in tests_demography.py. Will see if I can find which test is altering the dictionary as we probably don't want such coupling between tests. Ideally I think we should move away from using class level attributes as much as possible in favour of initialising in __init__ methods because of the risk of these sort of issues.

@matt-graham
Copy link
Collaborator

I assume the alteration of AGE_RANGE_LOOKUP is happening in one of the other tests in another test module which runs before the tests/test_demography.py::test_py_calc test when running all tests, which is why the failure only appears to occur when running all tests rather than the test individually or all the tests in tests_demography.py. Will see if I can find which test is altering the dictionary as we probably don't want such coupling between tests.

Looking into this a bit further, I think this is happening in quite a subtle way due to AGE_RANGE_LOOKUP being created as a defaultdict instance by the create_age_range_lookup function in src/tlo/util.py

TLOmodel/src/tlo/util.py

Lines 39 to 40 in 1ea5fa5

default_category = f'{max_age}+'
lookup = defaultdict(lambda: default_category)

The behaviour of defaultdict is defined such that it can be mutated just by performing operations that call the __getitem__ method (that is indexing into the object / accessing its entries), as if __getitem__ is called with a key which does not currently exist in the dictionary, the value outputed by defaultfactory (lambda: default_category above) is returned and inserted in to the dictionary under the key. This means any code which lookups a key in AGE_RANGE_LOOKUP which does not yet exist will have the side effect of creating a new entry in AGE_RANGE_LOOKUP (which will be shared across all current and future instances of the Simulation class).

This means for example the usage in

age_group_lookup = sim.modules['Demography'].AGE_RANGE_LOOKUP
adult_age_groups = ['15-19', '20-24', '25-29', '30-34', '35-39', '40-44', '45-49']
def get_births_in_a_month_by_age_range_of_mother_at_pregnancy(_df, year, month):
_df = _df.drop(_df.index[_df.mother == -1]) # ignore pregnancies generated in first 9mo by other method
_df = _df.assign(year=_df['date'].dt.year)
_df = _df.assign(month=_df['date'].dt.month)
_df['mother_age_range'] = _df['mother_age_at_pregnancy'].map(age_group_lookup)

will update AGE_RANGE_LOOKUP with entries for any value in _df['mother_age_at_pregnancy'] for which there wasn't an entry previously in AGE_RANGE_LOOKUP.

@tamuri
Copy link
Collaborator Author

tamuri commented Apr 19, 2023

Huh, good catch. Wrapping with dict() after setup should be enough...? Though non-exisiting key lookups will throw key error.

@tamuri
Copy link
Collaborator Author

tamuri commented Apr 19, 2023

The intention was these age range categories were fixed and all modules should use the ones setup by the demography module (or roll their own if necessary). I think that's right, @tbhallett ?

@matt-graham
Copy link
Collaborator

Huh, good catch. Wrapping with dict() after setup should be enough...? Though non-exisiting key lookups will throw key error.

Yeah think this should fix the immediate problem - I'm currently running tests after making basically this change (but using a types.MappingProxyType instead of a dict as the former is immutable so an error should be raised if there are any other places the lookup table is accidentally being altered) and so far things seems to be passing. pandas.Series.map when passed a dictionary outputs NaN values for any values not present as keys in the dictionary so if it was map instances causing the insertions previously, then they should still run without error though the values mapped to will have been changed.

@tbhallett
Copy link
Collaborator

The intention was these age range categories were fixed and all modules should use the ones setup by the demography module (or roll their own if necessary). I think that's right, @tbhallett ?

Absolutely.

@matt-graham
Copy link
Collaborator

We are getting exact equality of the final population dataframes after a full 20 year simulation of the scale_run.py script under Pandas v1.2.2 or v2.0.0 🎉 so once we've verified above suggestion fixes the failing demography test, the remaining tasks are I think are then just to create the new environment files, update installation instructions and adjust GitHub Action workflows / tox.

@matt-graham
Copy link
Collaborator

/run python3.11-pandas2.0-all-tests

@ucl-comment-bot
Copy link

Run of all tests on Python v3.11 with Pandas v2.0 succeeded ✅

🆔 12902139034
⏲️ 801 minutes
#️⃣ 4c2dcda

@matt-graham
Copy link
Collaborator

/run python3.11-pandas2.0-all-tests

@ucl-comment-bot
Copy link

Run of all tests on Python v3.11 with Pandas v2.0 failed ❌

🆔 16880157883
⏲️ 542 minutes
#️⃣ 12f6cc5

@tamuri
Copy link
Collaborator Author

tamuri commented Oct 1, 2023

Notes for upgrade to Python 3.11. We'll need to:

  • update self-hosted runners' provisioning playbooks. 
  • container used by Azure Batch
  • TLOmodel README installation instructions
  • tox.ini

@tamuri tamuri moved this from Issues to In progress in Issue management Oct 12, 2023
@tamuri tamuri moved this from In progress to Issues in Issue management Oct 12, 2023
@tamuri tamuri moved this from Issues to In progress in Issue management Oct 12, 2023
@tamuri tamuri moved this from In progress to Issues in Issue management Oct 12, 2023
@tamuri tamuri moved this from Issues to In progress in Issue management Oct 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Issue management
In progress
Development

No branches or pull requests

3 participants