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

Shared base classes for demography classes #338

Draft
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

davidorme
Copy link
Collaborator

@davidorme davidorme commented Oct 21, 2024

Description

This PR:

  • Introduces the demography.core module and defines the PandasExporter and Cohorts abstract base classes.
  • The ABCs share a common class attribute ('array_attrs') which is used to define which fields to export to pandas.DataFrame and which fields need to be kept synchronized as cohorts are added or removed.
  • Applies the PandasExporter to many of the demography classes and then updates the documentation to use the new to_pandas() method inherited from the base class.
  • Adds some low level tests of some basic subclasses in tests.unit.demographt.test_core.py to show that the ABCs work independently and with multiple inheritance.

TODO:

  • The Cohorts base class isn't used yet - need to think about whether to do this here. The main use case is within Community for adding new 'rows' to StemTraits, the cohort data etc. I think it's probably better to handle Revise cohort structure inside Community #336 first and then roll that ABC usage out.
  • The Cohorts ABC name clashes with pyrealm.demography.community.Cohorts and needs renaming: CohortMethods or similar.
  • Also need to use this in any partition of pyrealm.demography.community.Canopy attributes into cohort and community dataclasses (see Group internal attributes in Canopy into cohort and community objects. #337).

Fixes #314

Type of change

  • New feature (non-breaking change which adds functionality)
  • Optimization (back-end change that speeds up the code)
  • Bug fix (non-breaking change which fixes an issue)

Key checklist

  • Make sure you've run the pre-commit checks: $ pre-commit run -a
  • All tests pass: $ poetry run pytest

Further checks

  • Code is commented, particularly in hard-to-understand areas
  • Tests added that prove fix is effective or that feature works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

Shared base classes for demography classes.
1 participant