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

Allow PROPERTIES to set a default value, and Modules to auto-initialise their DF columns to these values #1436

Merged
merged 15 commits into from
Sep 10, 2024

Conversation

willGraham01
Copy link
Collaborator

@willGraham01 willGraham01 commented Jul 29, 2024

Concerns #1428 | Cherry-pick of the global functionality that was proposed in #1429

Introduces the functionality needed for us to remove a lot of repeated code in the initialise_population method for Modules. Propertys can now have a default value set when they are created (falling back on the currently-provided defaults in PANDAS_TYPE_DEFAULT_TYPE_MAP if not provided) which will be used to fill the corresponding column in the population dataframe during initialise_population.

Modules that just want to set their own property columns in initialise_population can then directly inherit this implementation without needing to explicitly implement it themselves. If Modules want to run additional steps in this method, they can call super().initialise_population first, and then provide their specific instructions afterwards. And finally, if a Module wants to do something completely different at this stage, they can just overwrite the method as normal and avoid calling super().

As @tamuri suggested, we'll introduce the changes proposed in #1429 incrementally. This does mean we'll be supporting both methods of setting the property columns in the dataframe for a while, but gives us some granularity for bug-fixing/tracing.

@willGraham01 willGraham01 marked this pull request as ready for review July 29, 2024 09:13
Copy link
Collaborator

@matt-graham matt-graham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @willGraham01. Looks all sensible to me - have made a few minor suggestions regarding some of the type hints added, and one suggestion of adding a comment to clarify something that I initially misunderstood.

src/tlo/core.py Outdated Show resolved Hide resolved
src/tlo/core.py Outdated Show resolved Hide resolved
src/tlo/core.py Outdated Show resolved Hide resolved
src/tlo/core.py Outdated Show resolved Hide resolved
src/tlo/core.py Outdated Show resolved Hide resolved
src/tlo/core.py Show resolved Hide resolved
src/tlo/core.py Outdated Show resolved Hide resolved
@willGraham01
Copy link
Collaborator Author

Checks are failing due to some syntax in files that are not affected by this PR.

Review comments are addressed so happy to either wait for this to be fixed, or merge in now.

@matt-graham
Copy link
Collaborator

Checks are failing due to some syntax in files that are not affected by this PR.

Yeah this should be fixed by #1459

Review comments are addressed so happy to either wait for this to be fixed, or merge in now.

Shouldn't matter either way as we're already failing on master 🙈 - ideally I guess we merge in #1459 first though.

@willGraham01 willGraham01 merged commit 6ee10af into master Sep 10, 2024
59 checks passed
@willGraham01 willGraham01 deleted the wgraham/initialise-properties-by-default branch September 10, 2024 08:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants