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

Gradually introduce type checking #50

Merged
merged 7 commits into from
Sep 25, 2024
Merged

Gradually introduce type checking #50

merged 7 commits into from
Sep 25, 2024

Conversation

nebfield
Copy link
Member

@nebfield nebfield commented Sep 19, 2024

Now we're using a lot of type hints with pydantic, it would be sensible to enforce checking them with mypy

mypy has been configured to be pretty relaxed:

  • Only check pgscatalog.core to start with
  • If a function is untyped, it won't be checked
  • If a function is typed, it will be checked for type errors
  • If a function is partially typed, it will raise an error
  • Dependencies aren't checked - only our code

As we develop or refactor stuff we can rework functions to have more type hints bit by bit. We can configure mypy to be stricter later on.

I also added a pre-commit configuration if that's your cup of tea 🍵

Copy link

codecov bot commented Sep 19, 2024

Codecov Report

Attention: Patch coverage is 93.75000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 89.51%. Comparing base (d5dd802) to head (1b15510).
Report is 1 commits behind head on fix-nonadditive.

Files with missing lines Patch % Lines
pgscatalog.core/src/pgscatalog/core/lib/models.py 93.54% 2 Missing ⚠️
Additional details and impacted files
@@                 Coverage Diff                 @@
##           fix-nonadditive      #50      +/-   ##
===================================================
+ Coverage            89.43%   89.51%   +0.08%     
===================================================
  Files                   38       38              
  Lines                 2347     2347              
===================================================
+ Hits                  2099     2101       +2     
+ Misses                 248      246       -2     
Flag Coverage Δ
pgscatalog.core 90.75% <93.75%> (+0.15%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@nebfield nebfield marked this pull request as ready for review September 19, 2024 09:47
@nebfield nebfield requested review from ens-lgil and fyvon September 20, 2024 09:24
@nebfield nebfield merged commit b3b8f64 into fix-nonadditive Sep 25, 2024
6 checks passed
@nebfield nebfield deleted the mypy branch September 25, 2024 12:53
nebfield added a commit that referenced this pull request Oct 7, 2024
* add pydantic dependency

* implement pydantic model drafts

* split models into CatalogScoreVariant and ScoreVariant

* fix doctests

* refactor to use a DictWriter

* fix doctest imports

* refactor classes into separate files

* add non-additive error checking

* skip non-additive scores

* add non-additive CLI tests

* export EffectTypeError

* fix missing CatalogError

* tidy up: put reusable pydantic models in models.py and export them

* simplify n_finished check

* set all effect weight fields to str with coerce_numbers_to_str

* add rsid field validator

* fix field validator field name o_o

* Update score log structure (#49)

* include example of validating a scoring file header

* update header models

* integrate ScoreLog and ScoreLogs

* fix doctest imports

* add log warning re: missing variants

* test log output with incompatible effect type

* make ScoreLogs a RootModel to act as a json list

* refactor weight types from enum to string

* prevent revalidation of ScoreVariants during ScoreLog instantiation

* prevent checking position for complex variants

* fix log creation with missing variants

* update is_non_additive check to support mixed column types

* Tidy up: delete unused target variants module (#47)

* remove targetvariants class

* fix deleted imports

* fix imports

* Gradually introduce type checking (#50)

* set up type checking pre-commit

* set up type checks for pgscatalog.core

* add mypy action

* don't use poetry for mypy

* fix is_complex check

* delete redundant functions

* drop unused NormalisedScoringFile

* rename variants -> variant_sources in ScoreLog

* add support for ancestry specific allele frequencies

* fix writing out

* hm_match_chr and hm_match_pos: treat empty strings as None

* set up a ProcessPoolExecutor skeleton

* fix multiprocessing coverage

* convert empty strings to None: is_haplotype and is_diplotype

* fix TypeError -> ValueError for pydantic

* fix doctest

* add support for variant_type field

* add complex variant tests

* improve model documentation

* bump minor version

* simplify effect_weight_must_float again

* Revert "simplify effect_weight_must_float again"

This reverts commit 0d5c6e5.

* document and improve effect_weight_must_float

* docs: stop being confusing

* cache computed fields in model

* add more CLI logging messages

* add has_complex_alleles computed field

* set up annotated types in models and VariantLog model

* add package mypy config

* ignore typing when reading ScoreVariants as dicts of strings

* clarify log messages when writing out
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.

1 participant