From 3d3c5d5403346e01ca6df21f7e3c6d3edfa3cca8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 29 Sep 2022 03:41:42 +0000 Subject: [PATCH 01/77] chore(deps-dev): update pytest-cov requirement Updates the requirements on [pytest-cov](https://github.com/pytest-dev/pytest-cov) to permit the latest version. - [Release notes](https://github.com/pytest-dev/pytest-cov/releases) - [Changelog](https://github.com/pytest-dev/pytest-cov/blob/master/CHANGELOG.rst) - [Commits](https://github.com/pytest-dev/pytest-cov/compare/v3.0.0...v4.0.0) --- updated-dependencies: - dependency-name: pytest-cov dependency-type: direct:development ... Signed-off-by: dependabot[bot] --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 34fdf521..170ddcac 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,7 +30,7 @@ selenium = ">=4.2.0, <4.3.0" [tool.poetry.dev-dependencies] pre-commit = ">=2.19.0,<2.19.1" pytest = ">=7.1.2,<7.1.3" -pytest-cov = ">=3.0.0,<3.0.1" +pytest-cov = ">=3.0.0,<4.0.1" black = ">=22.3.0,<22.4.0" flake8 = ">=4.0.1,<4.1.0" pytest-xdist = "^2.5.0" From f90d26ba9b667c16161cf2c3931c042bec4a6179 Mon Sep 17 00:00:00 2001 From: github-actions Date: Thu, 29 Sep 2022 14:41:42 +0200 Subject: [PATCH 02/77] fix: add auto-release --- .github/workflows/release.yml | 23 +++++++++++++++++++++++ pyproject.toml | 9 +++++++++ 2 files changed, 32 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..139e0067 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,23 @@ +name: Semantic Release + +on: + push: + branches: + - main + +jobs: + release: + runs-on: ubuntu-latest + concurrency: release + + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Python Semantic Release + uses: relekang/python-semantic-release@v7.32.0 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + # Remember to copy the tool.semantic_release section from pyproject.toml + # as well \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index d9baefd8..f3cfc77d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -77,4 +77,13 @@ known_third_party = ["wandb"] [tool.mypy] ignore_missing_imports = true +[tool.semantic_release] +branch = "main" +version_variable = [ + "pyproject.toml:version" +] +upload_to_pypi = false +upload_to_release = true +build_command = "pip install poetry && poetry build" + [tool.pyright] \ No newline at end of file From 96610c8848331992cb894fbfd3344aba4c57a4d9 Mon Sep 17 00:00:00 2001 From: github-actions Date: Thu, 29 Sep 2022 14:42:38 +0200 Subject: [PATCH 03/77] fix: remove unused line in PR template --- .github/pull_request_template.md | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 3fb56546..7a97c26f 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,5 +1,4 @@ - [ ] I have battle-tested on Overtaci (RMAPPS1279) -- [ ] I have bumped the version as described in the [wiki](https://www.notion.so/Setting-up-Poetry-on-your-local-machine-76647d75e8fa4d9ba553cbc2a49946d9#dca1e0f2ce934a49acd1851aaf882d75) - [ ] I have assigned ranges (e.g. `>=0.1, <0.2`) to all new dependencies ## Notes for reviewers From b45b231fa3081ccc642b4ae60869812730ccd1f2 Mon Sep 17 00:00:00 2001 From: github-actions Date: Thu, 29 Sep 2022 14:43:50 +0200 Subject: [PATCH 04/77] fix: linting --- pyproject.toml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index f3cfc77d..64e8c31d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -62,10 +62,6 @@ exclude_lines = [ "if __name__ == .__main__.:", ] -[tool.semantic_release] -version_variable = [ - "pyproject.toml:version" -] branch = "main" upload_to_pypi = false upload_to_release = true From c85da0f5b51e48632d03c699a1b12e7cb78470bb Mon Sep 17 00:00:00 2001 From: github-actions Date: Thu, 29 Sep 2022 14:49:09 +0200 Subject: [PATCH 05/77] fix: incorrect placement of section --- pyproject.toml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 64e8c31d..da53533e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -62,11 +62,6 @@ exclude_lines = [ "if __name__ == .__main__.:", ] -branch = "main" -upload_to_pypi = false -upload_to_release = true -build_command = "poetry build" - [tool.isort] known_third_party = ["wandb"] From b647157dfc99703a7c1ff873def1b9c9c1cd32a5 Mon Sep 17 00:00:00 2001 From: semantic-release Date: Thu, 29 Sep 2022 15:07:39 +0200 Subject: [PATCH 06/77] 0.1.0 Automatically generated by python-semantic-release --- CHANGELOG.md | 170 +++++++++++++++++++++++++++++++++++++++++++++++++ pyproject.toml | 2 +- 2 files changed, 171 insertions(+), 1 deletion(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..965a93fb --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,170 @@ +# Changelog + + + +## v0.1.0 (2022-09-29) +### Feature +* Add binary threshold option for `model_performance` ([`528d3a0`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/528d3a0de432d607bd9528911b9cf877818aaa71)) +* Add MB PAT for auto-approval ([`d933498`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/d9334982b7431d3ae887ef4fef8aacdd53ceb8de)) +* Add automerge for dependabot PRs ([`5b1c962`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/5b1c9621152b933c33dc14d2f8a389b4d644bacd)) +* Migrate `model_performance` to T2D ([`a161d30`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/a161d300a57c3566f715ddb67f66e87d1c683568)) +* Add ranges to pr_template and dependencies ([`74124bc`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/74124bcc7c753b7b5a34f0e4688dc196c574ea1a)) +* Add dependabot ([`a8e3c08`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/a8e3c08be4ff42485d347dbb279ec725741e0cb6)) +* Add script to train (multiple) models, sync the best to wandb, and move wandb runs to an archive folder ([`6cb63db`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/6cb63db1d1d96ebe22692001d02d0ea868016ffb)) +* Add PROJECT_ROOT_DIR ([`e915a19`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/e915a19d9f29ff13e3916c9c0be7696eaa63be86)) +* Remove stop-on-concurrency ([`38f9b81`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/38f9b81fe0026420614f55e41a2ffce02c05294b)) +* Invalidate cache for $HOME as well ([`bf4afde`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/bf4afdedc964d9f58dce45094d2f75ea381e0724)) +* Make WandB log to disk then upload in batch ([`f5f6121`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/f5f6121f13a172a541edcc790c362c355f4592ba)) +* Example for extra evaluation from model predictions ([`547fa8d`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/547fa8db426f5e434ff34c031f9c5cf215e5ee22)) +* Save model evaluation to disk ([`4ff1fea`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/4ff1fead9413f7bb917ced9150be48635f2609f0)) +* Update loader to take csv ([`1050b5e`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/1050b5e29a0ac46b301578d6749d64670ec5decc)) +* Update dependencies ([`1a1b459`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/1a1b459e153d48175ed298e349df962244ed4047)) +* Log feature importance table ([`f783d2a`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/f783d2a443495aa8c50d8906b4be259d5cdae065)) +* Feature importance for ebm ([`cca0f6d`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/cca0f6dfcb93e9ead5d2f67359317da636486d87)) +* Add mean warning days ([`5a61611`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/5a61611ca4be6974b1942c2735b85deb332ccadc)) +* Split testing_project into overtaci and integration for github actions ([`d1a3221`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/d1a3221c696d1da5e952a9ee8a1853b8321af9f1)) +* Add plots to evaluate_model ([`fe627f6`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/fe627f65a2a1fb7b261fbf483938cf1866daf26f)) +* Check if we can skip poetry install ([`8310cdb`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/8310cdb41e0f7e4900e29efaeb8cf7e9b61f9b6c)) +* Parralelise pytest on github actions only ([`c5ce87b`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/c5ce87b581d9eafd9425a1469193f041f1c57912)) +* Integration testing conf independent of overtaci_testing ([`24a22b3`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/24a22b30cf17a56d78c1666b975ecc6ef61b5e8a)) +* Add tests ([`bf77f4a`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/bf77f4a385cfe7a65e776eebd05e3d771894fdd3)) +* Add remaining plots and tests ([`c3789b0`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/c3789b00c00af24ee85458b4d9f0d0bf28cf794f)) +* Add heatmap ([`0acf651`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/0acf651ad6a445d1b5682529c1f6c523771d3812)) +* Run pytest in parallel ([`a80dcf4`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/a80dcf4e7da01ead6040fb22427d32267f8bf5e2)) +* Add cache versioning ([`29d456c`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/29d456c71b0dce0ce57bd84ba465cf03d469cc4e)) +* Add flag for GPU training of xgboost ([`1027250`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/102725092705d72f36b2cefe11e0907604bbdb5b)) +* Even faster caching, hopefully ([`e8314b6`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/e8314b6af0166dbd993473c76f70feb0ee663d2b)) +* Add more caching ([`603c3c6`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/603c3c6fb1694117ca743250e5c57cb97a174fef)) +* Added naive bayes ([`a635b2c`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/a635b2c9d405172385ef08b9041d4c9d42151438)) +* Added explainable boosting machine ([`5a9aafb`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/5a9aafbd6fdf505af618d9505944c901009ced05)) +* Added explainable boosting machine ([`c6d8582`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/c6d8582ff130cbb3ae1f3301b329d9f8fef631a8)) +* Added z-score-normalization ([`a2faa12`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/a2faa1246fff289f6dfe215d1f7a6d505b7da00f)) +* Add sensitivity_by_time_to_outcome ([`0afba8a`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/0afba8a7c9169f3e4c0ae4690428dbe6bd335c8c)) +* Add logistic regression ([`28a9fb6`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/28a9fb63d82bbc736c65f7ad9d1a40b09600b582)) +* Added NAs to synth data generation ([`44b679d`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/44b679df7df736a8e3d807d68844dbb389033569)) +* Working parallelisation 🤘 ([`f283a0b`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/f283a0b608b03ddb786c4b1e0be0872a332f7fbf)) +* Add better default params for xgboost ([`eb7d2a7`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/eb7d2a7c69e144c0f05bc9159509f4de74b56dc0)) +* :rocket: compose configs ([`f9783d1`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/f9783d1a1619ecc64094fa7c94256e320306caa0)) +* Add confusion matrix to performance_by_threshold ([`e1cb42c`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/e1cb42c4e4697b52c857101bb4d579791883cdbb)) +* True_prevalence, positive and negative rate to performance by threshold ([`2c85067`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/2c85067978f68e23791e741780a332815dab753d)) +* Add timestamp and timestamp_outcome to synth_pred_data ([`2d22172`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/2d221723a66b7e53c2be91d78635e09208ef16c3)) +* Add basic pipeline test ([`a62ab76`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/a62ab76693faa2b2e6436bd92b334f1722b5a670)) +* Add option for CV or not ([`4b27123`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/4b271230897c860ea6eeb063b71e852454189a60)) +* Performance by threshold table ([`390fcf0`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/390fcf0bf737ea51e95aec4886b7f21f2a6ca825)) +* Ignore init with isort and ignore unused imports in init ([`45ad9e9`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/45ad9e9d548b61dca0280b975d2ae3d1854e6ac9)) +* Log performance metrics ([`678bc37`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/678bc37cd1ff096eeaf380fa38865b118d34a29a)) +* Migrate to new package structure, upgrade ([`c114d19`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/c114d1930d4a9e5a4a7d982068ac86399ca7c814)) +* Migrate to new package structure, upgrade ([`cd8390a`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/cd8390a8f169385922fc5ce9acbd9903a2ad2aa9)) +* Add cache to pytest ([`85e1dc4`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/85e1dc4794c48ebd38f9f03271907151d8f26ec8)) + +### Fix +* Renamed dependency ([`e73734e`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/e73734e37c705b100d52efc35223e1526262d2f9)) +* Bug if `ModelPerformance` used without id2label ([`b928ab7`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/b928ab7085454b450256dd81bf4ba916f635d17e)) +* Improvements from review ([`1d88ea0`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/1d88ea07763e1333debe35f516f3ac4d03acc556)) +* Invalid placement of version key for poetry install ([`52fbebe`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/52fbebeb091e4ae18b3c34ace4503865a7944ad9)) +* Update documentation of GA. ([`70442fe`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/70442fe4f68db97ac5d184ab80f170441051046c)) +* Allow duplication of small utils ([`2c1b043`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/2c1b043be4e4ef57690bc04f40f3ad59926c37a2)) +* Ensure cache depends on python-version ([`1052caf`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/1052caf1742f65f2075901e6756ef5404ee2224a)) +* Overspecified python 3.9.0 slowing down pytest ([`aa14654`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/aa14654491e6aedf2c88fc90ea87f3c90a99bfe7)) +* Typo in pytest ([`8ca7a3b`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/8ca7a3b610c8f6221b596a1568619c4c573d4fa1)) +* Altair_saver requires selenium <4.3.0 ([`eb99574`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/eb99574d70eb0b81cc88a90bbcdceb80e9eda0a9)) +* Minor test changes ([`a3f1f5f`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/a3f1f5fa04a5f5c95325f25c10644fe3b2cdab5f)) +* Remove interpret to avoid llvmlite ([`36f1d01`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/36f1d01b18442304568bc6882f943197919e7226)) +* Misspecified types ([`94e5fd4`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/94e5fd4edf7efbe5b894fdf3053dee2ef6d44208)) +* Another typo in .toml, remove darglint as dep ([`df34e1b`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/df34e1b584a3d14e93d92d6c5fb97fb321b27d77)) +* Typo in toml ([`57d3d02`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/57d3d02e933736090f920bd52739c101f4f5fce2)) +* Spelling error in toml ([`8d67ded`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/8d67ded228faa3969404c3e19adc7df23c6466f7)) +* Fix failing tests ([`f06ac16`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/f06ac168c96239f4bbfe1d23a8759cb5ae346230)) +* Type in .venv sourcing ([`d154d13`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/d154d137c3338bb8a7bb91ab31c7b975dff9e401)) +* Remove unix-specific github actions runs ([`e000a90`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/e000a90eaef76770fa1201b4d894142db4904da7)) +* Minor fixes ([`3505e70`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/3505e70d1bdc5209bbfa6bdd7890d1f012b340e3)) +* Remove mypy type ignores ([`ae66393`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/ae66393c5b98b9b5f5c8191cde8fa015c4a81a2f)) +* Succesful training on overtaci ([`8e84c4b`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/8e84c4b7acb6bd00f3225bdd99007d1a557ca4e7)) +* Minor changes ([`2222141`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/22221418decc9177f4eef7e04b6bd1f635c4430d)) +* Failing tests ([`1c5ace1`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/1c5ace15a1aba370a5051753c8a65964238cd973)) +* Clean darglint ([`41d5565`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/41d556562e84b204b7fcf4a5f57f09d7ca9eb77f)) +* Rename github action ([`35f3dd5`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/35f3dd571c2b79da33d5bac49356084f7f0463ac)) +* Update t2d outcome ([`0bda7bd`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/0bda7bd778da42bc206ee09b819957878ae1ef47)) +* Failed import ([`885c8e2`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/885c8e25c6569f1a5802bc1a837cd427c4c4e23e)) +* Wrong direction of bool ([`f8ed7f3`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/f8ed7f3e8676ba7ee74f78919f2d31a38c480f16)) +* Sort feature importance plot ([`cbe81b3`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/cbe81b305b62fee9f876110eb76a773b004bf703)) +* Change argsort direction ([`19d635d`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/19d635d88f022ddf5a651ce0dbb82d895b7dd4a3)) +* Control n features to plot ([`0e7bc23`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/0e7bc23cff5283efbde54852231959195c923c5a)) +* Skip feature_importances_ for ebm ([`be1c8d4`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/be1c8d46756e4ea029ecdcf4477fedf4709a44a8)) +* Check if array exists ([`edabb56`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/edabb5675e1a4c82f244e3d275cc6cc254b6a221)) +* Refer to correct test project on overtaci ([`b4210d8`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/b4210d8e3b271842792ef107d3071a9cfe799763)) +* Add mean_warning_days to test ([`283a6cc`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/283a6cca3049be8b91d4735f8ce9637d2a977d1d)) +* Add mean_warning_days to test ([`c2dc20f`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/c2dc20fc9faa91078d128a64f02d17becf0e33f7)) +* Incorrect calculation of warning days per false positive ([`235e404`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/235e404120666dacccd7f24ed74832a5a1ae85cd)) +* Add chromedriver to GH actions ([`ce9478d`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/ce9478d916cf64a417a6d712c39a2aff22dcaca1)) +* Update tests ([`3bc6873`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/3bc68735b93497cced9dc05f196a692cce80d519)) +* Round decimals to percent ([`cdb3346`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/cdb3346a977a6b2f3a57e106c169d3c300ea64f3)) +* Remove pytest.ini ([`d041a16`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/d041a1664e9643145c54d9dcf6aa9af8b7356fb4)) +* Return nan if only 1 class in AUC calculation ([`17c1380`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/17c1380925e5404902b060fb1e2243fb393a6614)) +* Scale y-labels to whole numbers, e.g. 0.5 -> 50% ([`9d3ca8f`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/9d3ca8f1ccc1870d15bf2d0fd973281a83257010)) +* Config_naming ([`874a564`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/874a56497e5c686bfe040efbd8f03b80ab969201)) +* We must install poetry ([`f2474e6`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/f2474e6537b64a9d87020091ed41cf498aedbd8c)) +* Enable newline interpretation for pytest.ini ([`25f0026`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/25f00261624e516f7392de42df1bb155a082d750)) +* Try another way of parralising ([`5fcec4d`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/5fcec4d4a0a84845061b034ca3ee4a71d09bc147)) +* Remove plot saving ([`5c6819c`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/5c6819c289593163dad1137a89f309ccc197a3e4)) +* Tentative fix of warning_days ([`1bf99e5`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/1bf99e558cd5615a7ffe8d21da51608f98901510)) +* Remove pytest parallelisation, slows down locally ([`05cfc37`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/05cfc37bb56ed2631d3af1088ae127eff103ddea)) +* Titling of legend ([`884e08d`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/884e08d8365c2cce161eb0b6989c9e3a70448ab3)) +* Cleanup ([`c7d1fb0`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/c7d1fb0647d924cbda40b4387c732ac1eb029a64)) +* Set known_third_party for wandb ([`4cc0ec7`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/4cc0ec7b68cdd6d7813ce14e7792122c1d6a410c)) +* Caching ([`b587b14`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/b587b1473df6bf531c2536a66cc63bdea6ca2485)) +* Handle ebm on arm ([`dccd3ce`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/dccd3ce3d3804b4255a3c9fd636f8ea165effc8a)) +* Apply recommendations ([`306bdb9`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/306bdb93b91cadd90bf9a3359df08340ee54af66)) +* Apply recommendations ([`c85fb55`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/c85fb55aaf305817824eba13352399513973d6a9)) +* Create figures folder if it doesn't exist ([`0a86e29`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/0a86e29446c32b73027f5f4b9fee9bdb0d5de865)) +* Add folder to save html to in tests ([`4323e83`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/4323e83557e73de6af87ec6837208ed9b94a7471)) +* Downgrade selenium since altair uses deprecated api ([`2ba94a2`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/2ba94a2d14d52a7bac1452da99f4b4df304294b4)) +* Fixed bug when there is NAs in the pred_timestamps ([`2df71fe`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/2df71fe438537742cb0e71e161914e641f829c46)) +* Update config for test ([`5f16eef`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/5f16eef882d228a982047b826099f2d5cc9ff389)) +* Simplify configs ([`f9cee28`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/f9cee28f326fcff854275b2c0bf56c2b02de0ab8)) +* Hyperparameters sweep works ([`5ac5f1a`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/5ac5f1a17ce3d7661ffa9f019b84707f7fcb5ba7)) +* Working example ([`9f66d23`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/9f66d23e2cba94961deccd72249d92b52bc05449)) +* First working example ([`0e52681`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/0e52681a1ed0e8e80348e9eb4d710b0dc9fccc3e)) +* Wandb testing with dryrun ([`142b2cc`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/142b2ccbbe1160109b619918e3d9e41b26e208b9)) +* Remove random gitignore strings ([`6c42c23`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/6c42c230af21251bb5e8f072395c6d7e2e150936)) +* Random gitnogre string ([`c289822`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/c289822a4d958d75848dd78b70f8e07c89a45a57)) +* Dependencies fixed ([`81d2740`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/81d274075b7c5f32e2d95f41c0a5532a23c74968)) +* Set upper bounds for packages ([`b91026e`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/b91026ee7827acd0ba0629849214855d7b6fc0fe)) +* Add support for wandb_run dryrun ([`9e227cd`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/9e227cd06e90cb84a8f9247d35dd0c1ba1874b30)) +* Tests not passing ([`af9ecb9`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/af9ecb988b1bcba1b2a279d8b820bd29d1ed13a2)) +* Remove " in test_basic_pipeline.yaml ([`c1b5b22`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/c1b5b223a247017135597a18571cd7945dab4340)) +* Remove " from yaml config ([`8693d14`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/8693d1452dc1c4222fc131e4b41847952a8099de)) +* Failing tests ([`21e3397`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/21e339723266121ba9f7c6faba1fdc0ed27ba295)) +* Bugs in performance_by_threshold ([`8ddd71d`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/8ddd71db15d61610c41053751f66789f91c5ae67)) +* Bugs ([`3506541`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/3506541fe154a85dd715929086d7719d7e105a5b)) +* Update synth_prediction_data ([`3808757`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/3808757a4f81b24d49b0bf0693d272a4bec62deb)) +* Generalise flatten_nested_dict ([`521baf0`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/521baf0b3f21f041025da770340b621fcae5a30c)) +* Check caching ([`afb16e9`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/afb16e980814de44bf1bbbf1d49d5bb5c12e4dbb)) +* Ga pytest not caching dependencies ([`fad35e9`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/fad35e9e5de75dd16c9ac7077ebc1d4e40a54ce1)) +* Ignore .csv again ([`6a9a764`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/6a9a7645bee7c0ca50023c7556c3e48105e6da1b)) +* Add fake data files ([`4fbcab9`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/4fbcab912efed3772d9ea178283419c668c81cd8)) +* Tests not passing ([`b78dc20`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/b78dc201b574108d1481a1c95faff3a4e93db995)) +* Failing tests due to path rename ([`8407307`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/8407307dad4e6e412df7c7de9fddf37dba1edf15)) +* First train with synth data ([`a4195ee`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/a4195ee31f1ffec758cc0dc9e9ba9402df2db033)) +* Run on all examples ([`7795e06`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/7795e0623773838571fb07ac10d93a8d1b4ea32e)) +* Working version! ([`5f803f4`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/5f803f43e5702c425db0396e8986f306151ac7b8)) +* Test MVP ([`d92b6be`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/d92b6be09b6d86993e9179c054d248d950365cec)) +* Add misc corrections ([`a17fce7`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/a17fce71940307cf34b1c3002cac23ed1b54e375)) +* Basic version working ([`b1d5e10`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/b1d5e101a40722528214cbcb30b983554c9349f7)) +* Misc ([`fa6a8ba`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/fa6a8baabb93953879f5492536443b46050290eb)) +* Use pyproject.toml for poetry github action caching ([`db1e542`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/db1e54280c0b309cdc33cc4db5e481cc8d951483)) +* Update dependencies ([`41cff75`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/41cff754ebebd9172298922fa7816251d640bc97)) +* Update poetry.lock ([`4cd40bb`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/4cd40bbdb40a8f3b76cd2d83d2af80b64bd76243)) +* Improve from Lasse's comments ([`528864d`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/528864df3264d4014d629f54ed86f6f369ff61c6)) +* Keyerror on test ([`83bc031`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/83bc031909dfc05672b2e196db83526678a40e48)) +* Remove ambiguous comment ([`a4413bc`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/a4413bc25e00e46e6a178b6ec4be86170adedf62)) +* Update pytest version ([`44eb8d5`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/44eb8d5359e4bbf1e0a3a403b8353780a7aca1b2)) + +### Documentation +* Add missing docstrings ([`664c8d3`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/664c8d34d9aef246c44f4b325405bf65ebd45d33)) +* Some info on feature importance ([`a22a325`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/a22a325f1c2a739189c1250411654035202b8f6c)) +* Expand local chromedriver set up ([`348cb70`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/348cb7043f7e8e1e23a3d9814e06e63684baf22b)) +* Fix links to chromedriver ([`4032a79`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/4032a791daeec84e03d9200888fc1badd4baae3e)) +* Installing chromedriver ([`7c40ea4`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/7c40ea4d7af9090e8bf7a28b7bdb6bb620d2b13d)) +* Update docstring ([`8231659`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/8231659041ad7b3883edb97ac41112ef5dd687b0)) +* Updated train model introduction ([`6fe1353`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/6fe1353918ece9a152ab00f40c90e089dd7ca4d2)) diff --git a/pyproject.toml b/pyproject.toml index d9baefd8..0da50cd8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "psycopt2d" -version = "0.1.2" +version = "0.1.0" description = "Training scripts for the psycop-t2d project" authors = ["Your Name "] From af89cdd96a90db3305f0087cd2e8347cc3b1821d Mon Sep 17 00:00:00 2001 From: github-actions Date: Thu, 29 Sep 2022 15:10:41 +0200 Subject: [PATCH 07/77] fix: bump release version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index c0ed0e6d..6a56be92 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "psycopt2d" -version = "0.1.0" +version = "0.2.0" description = "Training scripts for the psycop-t2d project" authors = ["Your Name "] From 8fcb3f8703ea57697e5f89d4aaf799aec3559ff6 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Thu, 29 Sep 2022 15:11:59 +0200 Subject: [PATCH 08/77] fix: bump release version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 6a56be92..c0ed0e6d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "psycopt2d" -version = "0.2.0" +version = "0.1.0" description = "Training scripts for the psycop-t2d project" authors = ["Your Name "] From 4b90e57e0642b5d92d3359fbe68a5bdefd827468 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Thu, 29 Sep 2022 15:17:24 +0200 Subject: [PATCH 09/77] fix: bump version after more lenient branch protections From fe07436759b1a03bdc7c9eb738506e5f674c3d0c Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Thu, 29 Sep 2022 15:30:48 +0200 Subject: [PATCH 10/77] fix: bump version after even more lenient branch protections From 3e7806880598722b7a9d5200e649aa0aca7d1984 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Thu, 29 Sep 2022 15:32:57 +0200 Subject: [PATCH 11/77] fix: bump version after more lenient branch protections v4 From c231bc3dda115062ce9ad94840bf36e6a8a1d395 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Thu, 29 Sep 2022 15:33:10 +0200 Subject: [PATCH 12/77] fix: bump version after more lenient branch protections v4 From eb8a8c8695e4baad5d214561faf203ed1a7c50dc Mon Sep 17 00:00:00 2001 From: github-actions Date: Thu, 29 Sep 2022 13:34:06 +0000 Subject: [PATCH 13/77] 0.1.1 Automatically generated by python-semantic-release --- CHANGELOG.md | 9 +++++++++ pyproject.toml | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 965a93fb..fa10b9aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,15 @@ +## v0.1.1 (2022-09-29) +### Fix +* Bump version after more lenient branch protections v4 ([`c231bc3`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/c231bc3dda115062ce9ad94840bf36e6a8a1d395)) +* Bump version after more lenient branch protections v4 ([`3e78068`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/3e7806880598722b7a9d5200e649aa0aca7d1984)) +* Bump version after even more lenient branch protections ([`fe07436`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/fe07436759b1a03bdc7c9eb738506e5f674c3d0c)) +* Bump version after more lenient branch protections ([`4b90e57`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/4b90e57e0642b5d92d3359fbe68a5bdefd827468)) +* Bump release version ([`8fcb3f8`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/8fcb3f8703ea57697e5f89d4aaf799aec3559ff6)) +* Bump release version ([`af89cdd`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/af89cdd96a90db3305f0087cd2e8347cc3b1821d)) + ## v0.1.0 (2022-09-29) ### Feature * Add binary threshold option for `model_performance` ([`528d3a0`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/528d3a0de432d607bd9528911b9cf877818aaa71)) diff --git a/pyproject.toml b/pyproject.toml index c0ed0e6d..785b38aa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "psycopt2d" -version = "0.1.0" +version = "0.1.1" description = "Training scripts for the psycop-t2d project" authors = ["Your Name "] From 6b1170de1fcd04958afbb21fecbfd631e8e73517 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Thu, 29 Sep 2022 15:37:20 +0200 Subject: [PATCH 14/77] fix: try using personal access token to override --- .github/workflows/bump-version.yml | 14 ++++++++++++++ .github/workflows/release.yml | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/bump-version.yml diff --git a/.github/workflows/bump-version.yml b/.github/workflows/bump-version.yml new file mode 100644 index 00000000..806788f5 --- /dev/null +++ b/.github/workflows/bump-version.yml @@ -0,0 +1,14 @@ +# GitHub action to check if pre-commit has been run. Runs from .pre-commit-config.yaml, where the pre-commit actions are. + +name: run-pre-commit + +on: + pull_request: + +jobs: + pre-commit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + - uses: pre-commit/action@v3.0.0 \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 139e0067..4aed6e83 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,6 +18,6 @@ jobs: - name: Python Semantic Release uses: relekang/python-semantic-release@v7.32.0 with: - github_token: ${{ secrets.GITHUB_TOKEN }} + github_token: ${{ MB_PERSONAL_ACCESS_TOKEN}} # Remember to copy the tool.semantic_release section from pyproject.toml # as well \ No newline at end of file From 0c7d7938672e25b992f3d3d358098699a66eb14b Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Thu, 29 Sep 2022 15:37:50 +0200 Subject: [PATCH 15/77] fix: typo in release.yml --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4aed6e83..45d20467 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,6 +18,6 @@ jobs: - name: Python Semantic Release uses: relekang/python-semantic-release@v7.32.0 with: - github_token: ${{ MB_PERSONAL_ACCESS_TOKEN}} + github_token: ${{ secrets.MB_PERSONAL_ACCESS_TOKEN}} # Remember to copy the tool.semantic_release section from pyproject.toml # as well \ No newline at end of file From 1aa2dd07f7103f2573eb9991d0bab5194c4fa253 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Thu, 29 Sep 2022 15:41:09 +0200 Subject: [PATCH 16/77] fix: bump version after more lenient branch protections v4 From a90f4b0e42b8458c8db1728fb4925dc9edd08b13 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Thu, 29 Sep 2022 15:52:54 +0200 Subject: [PATCH 17/77] fix: bump version after more lenient branch protections v5 From 55c3acff60c892dd6b3f32ffeb0539f6eddd87a0 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Thu, 29 Sep 2022 15:54:26 +0200 Subject: [PATCH 18/77] fix: bump version after more lenient branch protections v6 From 05d04b4a4ed8667c90ecc3b6ace566a571a4b70d Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Thu, 29 Sep 2022 15:55:46 +0200 Subject: [PATCH 19/77] fix: bump version after more lenient branch protections v7 From c58e6c396ecfedd3a30a5ca2d47772d3a6d28355 Mon Sep 17 00:00:00 2001 From: github-actions Date: Thu, 29 Sep 2022 13:56:42 +0000 Subject: [PATCH 20/77] 0.1.2 Automatically generated by python-semantic-release --- CHANGELOG.md | 9 +++++++++ pyproject.toml | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fa10b9aa..238bfd2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,15 @@ +## v0.1.2 (2022-09-29) +### Fix +* Bump version after more lenient branch protections v7 ([`05d04b4`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/05d04b4a4ed8667c90ecc3b6ace566a571a4b70d)) +* Bump version after more lenient branch protections v6 ([`55c3acf`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/55c3acff60c892dd6b3f32ffeb0539f6eddd87a0)) +* Bump version after more lenient branch protections v5 ([`a90f4b0`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/a90f4b0e42b8458c8db1728fb4925dc9edd08b13)) +* Bump version after more lenient branch protections v4 ([`1aa2dd0`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/1aa2dd07f7103f2573eb9991d0bab5194c4fa253)) +* Typo in release.yml ([`0c7d793`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/0c7d7938672e25b992f3d3d358098699a66eb14b)) +* Try using personal access token to override ([`6b1170d`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/6b1170de1fcd04958afbb21fecbfd631e8e73517)) + ## v0.1.1 (2022-09-29) ### Fix * Bump version after more lenient branch protections v4 ([`c231bc3`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/c231bc3dda115062ce9ad94840bf36e6a8a1d395)) diff --git a/pyproject.toml b/pyproject.toml index 785b38aa..da53533e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "psycopt2d" -version = "0.1.1" +version = "0.1.2" description = "Training scripts for the psycop-t2d project" authors = ["Your Name "] From 3af0ae6c4303d69235acfd0f4f929406068210d4 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Thu, 29 Sep 2022 16:04:03 +0200 Subject: [PATCH 21/77] fix: add PAT to checkout for it to persist for python semantic release --- .github/workflows/release.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 45d20467..aa642cfa 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -14,6 +14,7 @@ jobs: - uses: actions/checkout@v2 with: fetch-depth: 0 + token: ${{ secrets.MB_PERSONAL_ACCESS_TOKEN }} - name: Python Semantic Release uses: relekang/python-semantic-release@v7.32.0 From 240a8f453382a83d878f0aa176332674b9f3d613 Mon Sep 17 00:00:00 2001 From: github-actions Date: Thu, 29 Sep 2022 14:05:03 +0000 Subject: [PATCH 22/77] 0.1.3 Automatically generated by python-semantic-release --- CHANGELOG.md | 4 ++++ pyproject.toml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 238bfd2f..d35bc180 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ +## v0.1.3 (2022-09-29) +### Fix +* Add PAT to checkout for it to persist for python semantic release ([`3af0ae6`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/3af0ae6c4303d69235acfd0f4f929406068210d4)) + ## v0.1.2 (2022-09-29) ### Fix * Bump version after more lenient branch protections v7 ([`05d04b4`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/05d04b4a4ed8667c90ecc3b6ace566a571a4b70d)) diff --git a/pyproject.toml b/pyproject.toml index da53533e..df3b0ff4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "psycopt2d" -version = "0.1.2" +version = "0.1.3" description = "Training scripts for the psycop-t2d project" authors = ["Your Name "] From cd6d699c8522d0812ec5ee96b75126b7dafcb04f Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Thu, 29 Sep 2022 16:22:51 +0200 Subject: [PATCH 23/77] ci: document how to add pypi --- .github/workflows/release.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index aa642cfa..d3a642e9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -11,6 +11,7 @@ jobs: concurrency: release steps: + # Checkout action is required for token to persist - uses: actions/checkout@v2 with: fetch-depth: 0 @@ -21,4 +22,10 @@ jobs: with: github_token: ${{ secrets.MB_PERSONAL_ACCESS_TOKEN}} # Remember to copy the tool.semantic_release section from pyproject.toml - # as well \ No newline at end of file + # as well + # To enable pypi, + # 1) Set upload_to_pypi to true in pyproject.toml and + # 2) Set the pypi_token in the repo + # 3) Uncomment the two lines below + # repository_username: __token__ + # repository_password: ${{ secrets.PYPI_TOKEN }} \ No newline at end of file From 942fd50cdc01bec06bca9895c51dbf80a60728ed Mon Sep 17 00:00:00 2001 From: Lasse Hansen Date: Thu, 29 Sep 2022 16:45:28 +0200 Subject: [PATCH 24/77] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 61440203..cde00153 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ To do that: **Work locally** 1. Write your plot function in an appropriate file in the `psycopt2d > visualization` directory. 2. Test the plot on synthetic prediction data. Write a test in `tests>name_of_your_plot.py`. - Use the `evaluate_saved_model_predictions.py` script as a guide. + Use the `evaluate_saved_model_predictions.py` script or the other visualization tests as a guide. **Work remotely** From 10a3047109f71054f641a44bfda05ad884e55878 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Fri, 30 Sep 2022 09:16:15 +0200 Subject: [PATCH 25/77] ci: test automerge with MartinBernstorff --- .github/workflows/dependabot_automerge.yml | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/.github/workflows/dependabot_automerge.yml b/.github/workflows/dependabot_automerge.yml index 677646e9..43707afc 100644 --- a/.github/workflows/dependabot_automerge.yml +++ b/.github/workflows/dependabot_automerge.yml @@ -11,15 +11,23 @@ permissions: jobs: dependabot-automerge: runs-on: ubuntu-latest - if: ${{ github.actor == 'dependabot[bot]'}} + if: ${{ github.actor == 'MartinBernstorff'}} + # if: ${{ github.actor == 'dependabot[bot]'}} steps: + # Checkout action is required for token to persist + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + token: ${{ secrets.MB_PERSONAL_ACCESS_TOKEN }} + - name: Enable auto-merge for Dependabot PRs run: gh pr merge --auto --merge "$PR_URL" # Use Github CLI to merge automatically the PR env: PR_URL: ${{github.event.pull_request.html_url}} GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} - + - name: Auto approve dependabot PRs - if: github.actor == 'dependabot[bot]' + if: github.actor == 'MartinBernstorff' + # if: github.actor == 'dependabot[bot]' uses: hmarr/auto-approve-action@v2 From 78ec2cb24eabd63905200a17cdf51a0a1bff8fa2 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Fri, 30 Sep 2022 09:16:41 +0200 Subject: [PATCH 26/77] ci: add test before release --- .github/workflows/main_test_and_release.yml | 78 +++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 .github/workflows/main_test_and_release.yml diff --git a/.github/workflows/main_test_and_release.yml b/.github/workflows/main_test_and_release.yml new file mode 100644 index 00000000..74f8d0f4 --- /dev/null +++ b/.github/workflows/main_test_and_release.yml @@ -0,0 +1,78 @@ +name: Semantic Release + +on: + push: + branches: + - main + +jobs: + test: + runs-on: ${{ matrix.os }} + + strategy: + matrix: + os: [macos-latest, ubuntu-latest, windows-latest] + python-version: [3.9] + + steps: + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - name: Checkout repo + uses: actions/checkout@v3 + + ### Caching + - name: Install Poetry + uses: snok/install-poetry@v1 + with: + version: 1.1.15 + virtualenvs-create: true + virtualenvs-in-project: true + + - name: Load cached venv + id: cached-poetry-dependencies + uses: actions/cache@v2.1.6 + with: + path: | + .venv + poetry.lock + # Cache the complete venv dir for a given os, python version, pyproject.toml + key: venv-${{ runner.os }}-python-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml') }}-${{ hashFiles('.github/workflows/cache_version') }} + + ### Installing + - name: Install Project + if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' + run: poetry install -vvv + + ### Run tests + - name: Run pytest + run: | + poetry run pytest --cov=src --cov-report term-missing --color=yes + + + release: + runs-on: ubuntu-latest + concurrency: release + needs: test + + steps: + # Checkout action is required for token to persist + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + token: ${{ secrets.MB_PERSONAL_ACCESS_TOKEN }} + + - name: Python Semantic Release + uses: relekang/python-semantic-release@v7.32.0 + with: + github_token: ${{ secrets.MB_PERSONAL_ACCESS_TOKEN}} + # Remember to copy the tool.semantic_release section from pyproject.toml + # as well + # To enable pypi, + # 1) Set upload_to_pypi to true in pyproject.toml and + # 2) Set the pypi_token in the repo + # 3) Uncomment the two lines below + # repository_username: __token__ + # repository_password: ${{ secrets.PYPI_TOKEN }} \ No newline at end of file From 79b00ce1977a639d068de11c2f24d77710a1dfee Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Fri, 30 Sep 2022 09:16:58 +0200 Subject: [PATCH 27/77] ci: split ci for PRs and main --- .github/workflows/release.yml | 31 ------------------- .../workflows/{pytest.yml => test_prs.yml} | 6 ---- 2 files changed, 37 deletions(-) delete mode 100644 .github/workflows/release.yml rename .github/workflows/{pytest.yml => test_prs.yml} (88%) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index d3a642e9..00000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,31 +0,0 @@ -name: Semantic Release - -on: - push: - branches: - - main - -jobs: - release: - runs-on: ubuntu-latest - concurrency: release - - steps: - # Checkout action is required for token to persist - - uses: actions/checkout@v2 - with: - fetch-depth: 0 - token: ${{ secrets.MB_PERSONAL_ACCESS_TOKEN }} - - - name: Python Semantic Release - uses: relekang/python-semantic-release@v7.32.0 - with: - github_token: ${{ secrets.MB_PERSONAL_ACCESS_TOKEN}} - # Remember to copy the tool.semantic_release section from pyproject.toml - # as well - # To enable pypi, - # 1) Set upload_to_pypi to true in pyproject.toml and - # 2) Set the pypi_token in the repo - # 3) Uncomment the two lines below - # repository_username: __token__ - # repository_password: ${{ secrets.PYPI_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/pytest.yml b/.github/workflows/test_prs.yml similarity index 88% rename from .github/workflows/pytest.yml rename to .github/workflows/test_prs.yml index a84cbd3b..e12825c7 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/test_prs.yml @@ -1,7 +1,5 @@ name: CI Pytest on: - push: - branches: [ main, dev ] pull_request: branches: [ main, dev ] @@ -23,10 +21,6 @@ jobs: - name: Checkout repo uses: actions/checkout@v3 - ## setup chromedriver for saving Altair plots - - name: setup-chromedriver - uses: nanasess/setup-chromedriver@v1.0.7 - ### Caching - name: Install Poetry uses: snok/install-poetry@v1 From e708d6479287c76133c2becc13d43b84b91d0abe Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Fri, 30 Sep 2022 09:19:08 +0200 Subject: [PATCH 28/77] fix: automerge with MB PAT --- .github/workflows/dependabot_automerge.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dependabot_automerge.yml b/.github/workflows/dependabot_automerge.yml index 43707afc..93aa9c97 100644 --- a/.github/workflows/dependabot_automerge.yml +++ b/.github/workflows/dependabot_automerge.yml @@ -25,7 +25,7 @@ jobs: run: gh pr merge --auto --merge "$PR_URL" # Use Github CLI to merge automatically the PR env: PR_URL: ${{github.event.pull_request.html_url}} - GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} + GITHUB_TOKEN: ${{ secrets.MB_PERSONAL_ACCESS_TOKEN }} - name: Auto approve dependabot PRs if: github.actor == 'MartinBernstorff' From 19b62306b1cb974d7ce7277dbd395e4629171e61 Mon Sep 17 00:00:00 2001 From: github-actions Date: Fri, 30 Sep 2022 07:20:06 +0000 Subject: [PATCH 29/77] 0.1.4 Automatically generated by python-semantic-release --- CHANGELOG.md | 4 ++++ pyproject.toml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d35bc180..6d21e41b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ +## v0.1.4 (2022-09-30) +### Fix +* Automerge with MB PAT ([`e708d64`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/e708d6479287c76133c2becc13d43b84b91d0abe)) + ## v0.1.3 (2022-09-29) ### Fix * Add PAT to checkout for it to persist for python semantic release ([`3af0ae6`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/3af0ae6c4303d69235acfd0f4f929406068210d4)) diff --git a/pyproject.toml b/pyproject.toml index df3b0ff4..024d7e1e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "psycopt2d" -version = "0.1.3" +version = "0.1.4" description = "Training scripts for the psycop-t2d project" authors = ["Your Name "] From 4638a64c4b7f59152483eb91b41730ea51aa43cf Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Fri, 30 Sep 2022 09:22:25 +0200 Subject: [PATCH 30/77] fix: only run automerge for dependabot PRs --- .github/workflows/dependabot_automerge.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/dependabot_automerge.yml b/.github/workflows/dependabot_automerge.yml index 93aa9c97..e1a352ef 100644 --- a/.github/workflows/dependabot_automerge.yml +++ b/.github/workflows/dependabot_automerge.yml @@ -11,8 +11,7 @@ permissions: jobs: dependabot-automerge: runs-on: ubuntu-latest - if: ${{ github.actor == 'MartinBernstorff'}} - # if: ${{ github.actor == 'dependabot[bot]'}} + if: ${{ github.actor == 'dependabot[bot]'}} steps: # Checkout action is required for token to persist @@ -28,6 +27,5 @@ jobs: GITHUB_TOKEN: ${{ secrets.MB_PERSONAL_ACCESS_TOKEN }} - name: Auto approve dependabot PRs - if: github.actor == 'MartinBernstorff' - # if: github.actor == 'dependabot[bot]' + if: github.actor == 'dependabot[bot]' uses: hmarr/auto-approve-action@v2 From 82feb25502f06e08d65e026d545be3240dd4d94b Mon Sep 17 00:00:00 2001 From: github-actions Date: Fri, 30 Sep 2022 07:32:46 +0000 Subject: [PATCH 31/77] 0.1.5 Automatically generated by python-semantic-release --- CHANGELOG.md | 4 ++++ pyproject.toml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d21e41b..e2150af7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ +## v0.1.5 (2022-09-30) +### Fix +* Only run automerge for dependabot PRs ([`4638a64`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/4638a64c4b7f59152483eb91b41730ea51aa43cf)) + ## v0.1.4 (2022-09-30) ### Fix * Automerge with MB PAT ([`e708d64`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/e708d6479287c76133c2becc13d43b84b91d0abe)) diff --git a/pyproject.toml b/pyproject.toml index 024d7e1e..1ed1671c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "psycopt2d" -version = "0.1.4" +version = "0.1.5" description = "Training scripts for the psycop-t2d project" authors = ["Your Name "] From fb2dfd07ab4efbd47cc79fc1bff6592ce04c4698 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Fri, 30 Sep 2022 09:38:41 +0200 Subject: [PATCH 32/77] ci: don't invalidate cache because of version bump --- .github/workflows/dependabot_automerge.yml | 2 +- .github/workflows/main_test_and_release.yml | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/dependabot_automerge.yml b/.github/workflows/dependabot_automerge.yml index e1a352ef..99a475eb 100644 --- a/.github/workflows/dependabot_automerge.yml +++ b/.github/workflows/dependabot_automerge.yml @@ -28,4 +28,4 @@ jobs: - name: Auto approve dependabot PRs if: github.actor == 'dependabot[bot]' - uses: hmarr/auto-approve-action@v2 + uses: hmarr/auto-approve-action@v2 \ No newline at end of file diff --git a/.github/workflows/main_test_and_release.yml b/.github/workflows/main_test_and_release.yml index 74f8d0f4..584adbf9 100644 --- a/.github/workflows/main_test_and_release.yml +++ b/.github/workflows/main_test_and_release.yml @@ -31,6 +31,12 @@ jobs: virtualenvs-create: true virtualenvs-in-project: true + - name: Overwrite version number from pyproject.toml, so it doesn't invalidate cache + id: remove-version-from-toml + run: | + sed -i "s/version = \".*\"/version = \"0.0.0\"/g" pyproject.toml + cat pyproject.toml + - name: Load cached venv id: cached-poetry-dependencies uses: actions/cache@v2.1.6 From 2cbd2b7c160dbf86c385d252ccf9b415f78e73fe Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Fri, 30 Sep 2022 09:39:58 +0200 Subject: [PATCH 33/77] fix: version bump shouldn't invalidate cache in PRs --- .github/workflows/test_prs.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/test_prs.yml b/.github/workflows/test_prs.yml index e12825c7..34d11868 100644 --- a/.github/workflows/test_prs.yml +++ b/.github/workflows/test_prs.yml @@ -22,6 +22,12 @@ jobs: uses: actions/checkout@v3 ### Caching + - name: Overwrite version number from pyproject.toml, so it doesn't invalidate cache + id: remove-version-from-toml + run: | + sed -i "s/version = \".*\"/version = \"0.0.0\"/g" pyproject.toml + cat pyproject.toml + - name: Install Poetry uses: snok/install-poetry@v1 with: From 7699cf8bc06db47a48f59bfd310c88f756d16c69 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Fri, 30 Sep 2022 09:49:13 +0200 Subject: [PATCH 34/77] ci: only remove version number on ubuntu --- .github/workflows/main_test_and_release.yml | 1 + .github/workflows/test_prs.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/main_test_and_release.yml b/.github/workflows/main_test_and_release.yml index 584adbf9..461e7d04 100644 --- a/.github/workflows/main_test_and_release.yml +++ b/.github/workflows/main_test_and_release.yml @@ -33,6 +33,7 @@ jobs: - name: Overwrite version number from pyproject.toml, so it doesn't invalidate cache id: remove-version-from-toml + if: ${{ matrix.os }} == "ubuntu-latest" run: | sed -i "s/version = \".*\"/version = \"0.0.0\"/g" pyproject.toml cat pyproject.toml diff --git a/.github/workflows/test_prs.yml b/.github/workflows/test_prs.yml index 34d11868..59fdf4d5 100644 --- a/.github/workflows/test_prs.yml +++ b/.github/workflows/test_prs.yml @@ -24,6 +24,7 @@ jobs: ### Caching - name: Overwrite version number from pyproject.toml, so it doesn't invalidate cache id: remove-version-from-toml + if: ${{ matrix.os }} == "ubuntu-latest" run: | sed -i "s/version = \".*\"/version = \"0.0.0\"/g" pyproject.toml cat pyproject.toml From 12c8c3385826da774ca7ebb54650cd5e543af797 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Fri, 30 Sep 2022 09:58:02 +0200 Subject: [PATCH 35/77] ci: try again with removing version for cache --- .github/workflows/main_test_and_release.yml | 4 ++-- .github/workflows/test_prs.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main_test_and_release.yml b/.github/workflows/main_test_and_release.yml index 461e7d04..30d5bfe8 100644 --- a/.github/workflows/main_test_and_release.yml +++ b/.github/workflows/main_test_and_release.yml @@ -1,4 +1,4 @@ -name: Semantic Release +name: Test and release main on: push: @@ -33,7 +33,7 @@ jobs: - name: Overwrite version number from pyproject.toml, so it doesn't invalidate cache id: remove-version-from-toml - if: ${{ matrix.os }} == "ubuntu-latest" + if: matrix.os == "ubuntu-latest" run: | sed -i "s/version = \".*\"/version = \"0.0.0\"/g" pyproject.toml cat pyproject.toml diff --git a/.github/workflows/test_prs.yml b/.github/workflows/test_prs.yml index 59fdf4d5..c7d85b0b 100644 --- a/.github/workflows/test_prs.yml +++ b/.github/workflows/test_prs.yml @@ -24,7 +24,7 @@ jobs: ### Caching - name: Overwrite version number from pyproject.toml, so it doesn't invalidate cache id: remove-version-from-toml - if: ${{ matrix.os }} == "ubuntu-latest" + if: matrix.os == "ubuntu-latest" run: | sed -i "s/version = \".*\"/version = \"0.0.0\"/g" pyproject.toml cat pyproject.toml From dcd43321fcd4eacbb7b3ba6e6f2697e4cad8bde6 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Fri, 30 Sep 2022 09:58:39 +0200 Subject: [PATCH 36/77] ci: another attempt at removing version bump --- .github/workflows/main_test_and_release.yml | 2 +- .github/workflows/test_prs.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main_test_and_release.yml b/.github/workflows/main_test_and_release.yml index 30d5bfe8..09dad3ce 100644 --- a/.github/workflows/main_test_and_release.yml +++ b/.github/workflows/main_test_and_release.yml @@ -33,7 +33,7 @@ jobs: - name: Overwrite version number from pyproject.toml, so it doesn't invalidate cache id: remove-version-from-toml - if: matrix.os == "ubuntu-latest" + if: matrix.os == 'ubuntu-latest' run: | sed -i "s/version = \".*\"/version = \"0.0.0\"/g" pyproject.toml cat pyproject.toml diff --git a/.github/workflows/test_prs.yml b/.github/workflows/test_prs.yml index c7d85b0b..05965921 100644 --- a/.github/workflows/test_prs.yml +++ b/.github/workflows/test_prs.yml @@ -24,7 +24,7 @@ jobs: ### Caching - name: Overwrite version number from pyproject.toml, so it doesn't invalidate cache id: remove-version-from-toml - if: matrix.os == "ubuntu-latest" + if: matrix.os == 'ubuntu-latest' run: | sed -i "s/version = \".*\"/version = \"0.0.0\"/g" pyproject.toml cat pyproject.toml From d844c5a9b3f0f7b70d8b967a25328f967d2ee7cc Mon Sep 17 00:00:00 2001 From: github-actions Date: Fri, 30 Sep 2022 08:04:57 +0000 Subject: [PATCH 37/77] 0.1.6 Automatically generated by python-semantic-release --- CHANGELOG.md | 4 ++++ pyproject.toml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e2150af7..e5b906b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ +## v0.1.6 (2022-09-30) +### Fix +* Version bump shouldn't invalidate cache in PRs ([`2cbd2b7`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/2cbd2b7c160dbf86c385d252ccf9b415f78e73fe)) + ## v0.1.5 (2022-09-30) ### Fix * Only run automerge for dependabot PRs ([`4638a64`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/4638a64c4b7f59152483eb91b41730ea51aa43cf)) diff --git a/pyproject.toml b/pyproject.toml index 1ed1671c..c7f59ecf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "psycopt2d" -version = "0.1.5" +version = "0.1.6" description = "Training scripts for the psycop-t2d project" authors = ["Your Name "] From 9a4422a954c7092090811fa480424da6b5084567 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Fri, 30 Sep 2022 10:06:59 +0200 Subject: [PATCH 38/77] ci: cache poetry installation --- .github/workflows/main_test_and_release.yml | 10 +++++++ .github/workflows/test_prs.yml | 29 ++++++++++++++------- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/.github/workflows/main_test_and_release.yml b/.github/workflows/main_test_and_release.yml index 09dad3ce..1f586cd8 100644 --- a/.github/workflows/main_test_and_release.yml +++ b/.github/workflows/main_test_and_release.yml @@ -48,6 +48,16 @@ jobs: # Cache the complete venv dir for a given os, python version, pyproject.toml key: venv-${{ runner.os }}-python-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml') }}-${{ hashFiles('.github/workflows/cache_version') }} + - name: Load cached .local (Poetry install location) + id: cached-poetry-dependencies + if: matrix.os == 'ubuntu-latest' | matrix.os == 'macos-latest' + uses: actions/cache@v2.1.6 + with: + path: | + ~/.local/ + # Cache the complete venv dir for a given os, python version, pyproject.toml + key: venv-${{ runner.os }}-python-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml') }}-${{ hashFiles('.github/workflows/cache_version') }}--${{ hashFiles('.github/workflows/test_prs.yml') }} + ### Installing - name: Install Project if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' diff --git a/.github/workflows/test_prs.yml b/.github/workflows/test_prs.yml index 05965921..6d5ebbe9 100644 --- a/.github/workflows/test_prs.yml +++ b/.github/workflows/test_prs.yml @@ -13,6 +13,7 @@ jobs: python-version: [3.9] steps: + ### Setup prerequisites - name: Set up Python uses: actions/setup-python@v4 with: @@ -28,14 +29,7 @@ jobs: run: | sed -i "s/version = \".*\"/version = \"0.0.0\"/g" pyproject.toml cat pyproject.toml - - - name: Install Poetry - uses: snok/install-poetry@v1 - with: - version: 1.1.15 - virtualenvs-create: true - virtualenvs-in-project: true - + - name: Load cached venv id: cached-poetry-dependencies uses: actions/cache@v2.1.6 @@ -45,8 +39,25 @@ jobs: poetry.lock # Cache the complete venv dir for a given os, python version, pyproject.toml key: venv-${{ runner.os }}-python-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml') }}-${{ hashFiles('.github/workflows/cache_version') }} + + - name: Load cached .local (Poetry install location) + id: cached-poetry-dependencies + if: matrix.os == 'ubuntu-latest' | matrix.os == 'macos-latest' + uses: actions/cache@v2.1.6 + with: + path: | + ~/.local/ + # Cache the complete venv dir for a given os, python version, pyproject.toml + key: venv-${{ runner.os }}-python-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml') }}-${{ hashFiles('.github/workflows/cache_version') }}--${{ hashFiles('.github/workflows/test_prs.yml') }} + + # Installing + - name: Install Poetry + uses: snok/install-poetry@v1 + with: + version: 1.1.15 + virtualenvs-create: true + virtualenvs-in-project: true - ### Installing - name: Install Project if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' run: poetry install -vvv From c31f0850d6fe6a105590d5eb201856a997767ab4 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Fri, 30 Sep 2022 10:07:20 +0200 Subject: [PATCH 39/77] ci: poetry cache should depend on workflow specification --- .github/workflows/main_test_and_release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main_test_and_release.yml b/.github/workflows/main_test_and_release.yml index 1f586cd8..6d42fd15 100644 --- a/.github/workflows/main_test_and_release.yml +++ b/.github/workflows/main_test_and_release.yml @@ -56,7 +56,7 @@ jobs: path: | ~/.local/ # Cache the complete venv dir for a given os, python version, pyproject.toml - key: venv-${{ runner.os }}-python-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml') }}-${{ hashFiles('.github/workflows/cache_version') }}--${{ hashFiles('.github/workflows/test_prs.yml') }} + key: venv-${{ runner.os }}-python-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml') }}-${{ hashFiles('.github/workflows/cache_version') }}--${{ hashFiles('.github/workflows/main_test_and_release.yml') }} ### Installing - name: Install Project From 06ffdb9c2f18e74ae248469469d0f5c8e4c8bc0f Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Fri, 30 Sep 2022 10:08:08 +0200 Subject: [PATCH 40/77] ci: fix duplicate identifier --- .github/workflows/main_test_and_release.yml | 2 +- .github/workflows/test_prs.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main_test_and_release.yml b/.github/workflows/main_test_and_release.yml index 6d42fd15..5a80860e 100644 --- a/.github/workflows/main_test_and_release.yml +++ b/.github/workflows/main_test_and_release.yml @@ -49,7 +49,7 @@ jobs: key: venv-${{ runner.os }}-python-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml') }}-${{ hashFiles('.github/workflows/cache_version') }} - name: Load cached .local (Poetry install location) - id: cached-poetry-dependencies + id: cached-poetry if: matrix.os == 'ubuntu-latest' | matrix.os == 'macos-latest' uses: actions/cache@v2.1.6 with: diff --git a/.github/workflows/test_prs.yml b/.github/workflows/test_prs.yml index 6d5ebbe9..7df918e4 100644 --- a/.github/workflows/test_prs.yml +++ b/.github/workflows/test_prs.yml @@ -41,7 +41,7 @@ jobs: key: venv-${{ runner.os }}-python-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml') }}-${{ hashFiles('.github/workflows/cache_version') }} - name: Load cached .local (Poetry install location) - id: cached-poetry-dependencies + id: cached-poetry if: matrix.os == 'ubuntu-latest' | matrix.os == 'macos-latest' uses: actions/cache@v2.1.6 with: From 6a23cab2d2db5f2023c277750e49890ed76b0eee Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Fri, 30 Sep 2022 10:09:47 +0200 Subject: [PATCH 41/77] ci: fix 'or' specification --- .github/workflows/main_test_and_release.yml | 2 +- .github/workflows/test_prs.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main_test_and_release.yml b/.github/workflows/main_test_and_release.yml index 5a80860e..b9bfbffc 100644 --- a/.github/workflows/main_test_and_release.yml +++ b/.github/workflows/main_test_and_release.yml @@ -50,7 +50,7 @@ jobs: - name: Load cached .local (Poetry install location) id: cached-poetry - if: matrix.os == 'ubuntu-latest' | matrix.os == 'macos-latest' + if: matrix.os == 'ubuntu-latest' && matrix.os == 'macos-latest' # && is 'or' for some reason uses: actions/cache@v2.1.6 with: path: | diff --git a/.github/workflows/test_prs.yml b/.github/workflows/test_prs.yml index 7df918e4..1141ae39 100644 --- a/.github/workflows/test_prs.yml +++ b/.github/workflows/test_prs.yml @@ -42,7 +42,7 @@ jobs: - name: Load cached .local (Poetry install location) id: cached-poetry - if: matrix.os == 'ubuntu-latest' | matrix.os == 'macos-latest' + if: matrix.os == 'ubuntu-latest' && matrix.os == 'macos-latest' # && is 'or' for some reason uses: actions/cache@v2.1.6 with: path: | From 489301bd8924658ebce0e6dcbee8f4161d0361f7 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Fri, 30 Sep 2022 10:11:31 +0200 Subject: [PATCH 42/77] ci: move poetry cache before poetry install --- .github/workflows/main_test_and_release.yml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/workflows/main_test_and_release.yml b/.github/workflows/main_test_and_release.yml index b9bfbffc..06e88ed2 100644 --- a/.github/workflows/main_test_and_release.yml +++ b/.github/workflows/main_test_and_release.yml @@ -24,12 +24,6 @@ jobs: uses: actions/checkout@v3 ### Caching - - name: Install Poetry - uses: snok/install-poetry@v1 - with: - version: 1.1.15 - virtualenvs-create: true - virtualenvs-in-project: true - name: Overwrite version number from pyproject.toml, so it doesn't invalidate cache id: remove-version-from-toml @@ -59,6 +53,13 @@ jobs: key: venv-${{ runner.os }}-python-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml') }}-${{ hashFiles('.github/workflows/cache_version') }}--${{ hashFiles('.github/workflows/main_test_and_release.yml') }} ### Installing + - name: Install Poetry + uses: snok/install-poetry@v1 + with: + version: 1.1.15 + virtualenvs-create: true + virtualenvs-in-project: true + - name: Install Project if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' run: poetry install -vvv From 12b3c93cc229ceec300464a1ccfe2e62be8e2f32 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Fri, 30 Sep 2022 10:12:56 +0200 Subject: [PATCH 43/77] ci: cache .local on ubuntu OR macos --- .github/workflows/main_test_and_release.yml | 2 +- .github/workflows/test_prs.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main_test_and_release.yml b/.github/workflows/main_test_and_release.yml index 06e88ed2..8f77efd8 100644 --- a/.github/workflows/main_test_and_release.yml +++ b/.github/workflows/main_test_and_release.yml @@ -44,7 +44,7 @@ jobs: - name: Load cached .local (Poetry install location) id: cached-poetry - if: matrix.os == 'ubuntu-latest' && matrix.os == 'macos-latest' # && is 'or' for some reason + if: (matrix.os == 'ubuntu-latest' && matrix.os == 'macos-latest') # && is 'or' for some reason uses: actions/cache@v2.1.6 with: path: | diff --git a/.github/workflows/test_prs.yml b/.github/workflows/test_prs.yml index 1141ae39..0277535c 100644 --- a/.github/workflows/test_prs.yml +++ b/.github/workflows/test_prs.yml @@ -42,7 +42,7 @@ jobs: - name: Load cached .local (Poetry install location) id: cached-poetry - if: matrix.os == 'ubuntu-latest' && matrix.os == 'macos-latest' # && is 'or' for some reason + if: (matrix.os == 'ubuntu-latest' && matrix.os == 'macos-latest') # && is 'or' for some reason uses: actions/cache@v2.1.6 with: path: | From 55ce611ef4389cb8abda9f87fa16088ce43c2970 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Fri, 30 Sep 2022 10:14:40 +0200 Subject: [PATCH 44/77] ci: macos OR ubuntu, && -> || --- .github/workflows/main_test_and_release.yml | 2 +- .github/workflows/test_prs.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main_test_and_release.yml b/.github/workflows/main_test_and_release.yml index 8f77efd8..1f368fd4 100644 --- a/.github/workflows/main_test_and_release.yml +++ b/.github/workflows/main_test_and_release.yml @@ -44,7 +44,7 @@ jobs: - name: Load cached .local (Poetry install location) id: cached-poetry - if: (matrix.os == 'ubuntu-latest' && matrix.os == 'macos-latest') # && is 'or' for some reason + if: (matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest') uses: actions/cache@v2.1.6 with: path: | diff --git a/.github/workflows/test_prs.yml b/.github/workflows/test_prs.yml index 0277535c..a5f365b7 100644 --- a/.github/workflows/test_prs.yml +++ b/.github/workflows/test_prs.yml @@ -42,7 +42,7 @@ jobs: - name: Load cached .local (Poetry install location) id: cached-poetry - if: (matrix.os == 'ubuntu-latest' && matrix.os == 'macos-latest') # && is 'or' for some reason + if: (matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest') uses: actions/cache@v2.1.6 with: path: | From 6290c6c80cc18e482dc694be4545e6897df657b9 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Fri, 30 Sep 2022 10:46:27 +0200 Subject: [PATCH 45/77] ci: attempt using GITHUB_TOKEN for automerge --- .github/workflows/dependabot_automerge.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/dependabot_automerge.yml b/.github/workflows/dependabot_automerge.yml index 99a475eb..b61a05aa 100644 --- a/.github/workflows/dependabot_automerge.yml +++ b/.github/workflows/dependabot_automerge.yml @@ -18,13 +18,13 @@ jobs: - uses: actions/checkout@v2 with: fetch-depth: 0 - token: ${{ secrets.MB_PERSONAL_ACCESS_TOKEN }} + token: ${{ secrets.GITHUB_TOKEN }} - name: Enable auto-merge for Dependabot PRs run: gh pr merge --auto --merge "$PR_URL" # Use Github CLI to merge automatically the PR env: PR_URL: ${{github.event.pull_request.html_url}} - GITHUB_TOKEN: ${{ secrets.MB_PERSONAL_ACCESS_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Auto approve dependabot PRs if: github.actor == 'dependabot[bot]' From 1b5f5a91e89826ba1c530c82570eb4465008a506 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Fri, 30 Sep 2022 13:08:42 +0200 Subject: [PATCH 46/77] feat: first CI release --- .github/dependabot.yml | 11 ++++++----- .github/pull_request_template.md | 2 +- .github/workflows/bump-version.yml | 14 -------------- .github/workflows/dependabot_automerge.yml | 9 +++------ .github/workflows/main_test_and_release.yml | 20 +++++++++++++------- pyproject.toml | 2 +- 6 files changed, 24 insertions(+), 34 deletions(-) delete mode 100644 .github/workflows/bump-version.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml index bbbd43c7..2666ee2d 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -8,10 +8,11 @@ updates: - package-ecosystem: "pip" # See documentation for possible values directory: "/" # Location of package manifests schedule: - interval: "daily" + interval: "weekly" day: "monday" - time: "05:00" + time: "01:00" timezone: "Europe/Copenhagen" - reviewers: - - "MartinBernstorff" - open-pull-requests-limit: 20 + open-pull-requests-limit: 5 + commit-message: + prefix: "fix:" + include: "scope" diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 7a97c26f..651849fa 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,5 +1,5 @@ - [ ] I have battle-tested on Overtaci (RMAPPS1279) -- [ ] I have assigned ranges (e.g. `>=0.1, <0.2`) to all new dependencies +- [ ] I have assigned ranges (e.g. `>=0.1, <0.2`) to all new dependencies (allows dependabot to keep dependency ranges wide for better compatability) ## Notes for reviewers Reviewers can skip X, but should pay attention to Y. diff --git a/.github/workflows/bump-version.yml b/.github/workflows/bump-version.yml deleted file mode 100644 index 806788f5..00000000 --- a/.github/workflows/bump-version.yml +++ /dev/null @@ -1,14 +0,0 @@ -# GitHub action to check if pre-commit has been run. Runs from .pre-commit-config.yaml, where the pre-commit actions are. - -name: run-pre-commit - -on: - pull_request: - -jobs: - pre-commit: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 - - uses: pre-commit/action@v3.0.0 \ No newline at end of file diff --git a/.github/workflows/dependabot_automerge.yml b/.github/workflows/dependabot_automerge.yml index b61a05aa..8650d52b 100644 --- a/.github/workflows/dependabot_automerge.yml +++ b/.github/workflows/dependabot_automerge.yml @@ -15,11 +15,6 @@ jobs: steps: # Checkout action is required for token to persist - - uses: actions/checkout@v2 - with: - fetch-depth: 0 - token: ${{ secrets.GITHUB_TOKEN }} - - name: Enable auto-merge for Dependabot PRs run: gh pr merge --auto --merge "$PR_URL" # Use Github CLI to merge automatically the PR env: @@ -28,4 +23,6 @@ jobs: - name: Auto approve dependabot PRs if: github.actor == 'dependabot[bot]' - uses: hmarr/auto-approve-action@v2 \ No newline at end of file + uses: hmarr/auto-approve-action@v2 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/main_test_and_release.yml b/.github/workflows/main_test_and_release.yml index 1f368fd4..6cc8179c 100644 --- a/.github/workflows/main_test_and_release.yml +++ b/.github/workflows/main_test_and_release.yml @@ -24,14 +24,20 @@ jobs: uses: actions/checkout@v3 ### Caching - - - name: Overwrite version number from pyproject.toml, so it doesn't invalidate cache - id: remove-version-from-toml + - name: Linux, Overwrite version number from pyproject.toml, so it doesn't invalidate cache + id: remove-version-from-toml-macos if: matrix.os == 'ubuntu-latest' run: | sed -i "s/version = \".*\"/version = \"0.0.0\"/g" pyproject.toml cat pyproject.toml + - name: Mac, Overwrite version number from pyproject.toml, so it doesn't invalidate cache + id: remove-version-from-toml-ubuntu + if: matrix.os == 'macos-latest' + run: | + sed -i '' "s/version = \".*\"/version = \"0.0.0\"/g" pyproject.toml + cat pyproject.toml + - name: Load cached venv id: cached-poetry-dependencies uses: actions/cache@v2.1.6 @@ -42,7 +48,7 @@ jobs: # Cache the complete venv dir for a given os, python version, pyproject.toml key: venv-${{ runner.os }}-python-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml') }}-${{ hashFiles('.github/workflows/cache_version') }} - - name: Load cached .local (Poetry install location) + - name: Mac, Linux, Load cached .local (Poetry install location) id: cached-poetry if: (matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest') uses: actions/cache@v2.1.6 @@ -80,12 +86,12 @@ jobs: - uses: actions/checkout@v2 with: fetch-depth: 0 - token: ${{ secrets.MB_PERSONAL_ACCESS_TOKEN }} + token: ${{ secrets.RELEASE_BOT }} - name: Python Semantic Release uses: relekang/python-semantic-release@v7.32.0 - with: - github_token: ${{ secrets.MB_PERSONAL_ACCESS_TOKEN}} + with: + github_token: ${{ secrets.RELEASE_BOT }} # Remember to copy the tool.semantic_release section from pyproject.toml # as well # To enable pypi, diff --git a/pyproject.toml b/pyproject.toml index c7f59ecf..8067a2e6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "psycopt2d" -version = "0.1.6" +version = "0.0.0" description = "Training scripts for the psycop-t2d project" authors = ["Your Name "] From d14a05c4e32bb6fdc4ce7195d3a932105ef258ca Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Fri, 30 Sep 2022 13:19:49 +0200 Subject: [PATCH 47/77] fix: CI didn't run; match version with latest release --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 8067a2e6..c7f59ecf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "psycopt2d" -version = "0.0.0" +version = "0.1.6" description = "Training scripts for the psycop-t2d project" authors = ["Your Name "] From 4c89bd71b5766371f4116f4ffdf3398c5706fb03 Mon Sep 17 00:00:00 2001 From: github-actions Date: Fri, 30 Sep 2022 11:27:39 +0000 Subject: [PATCH 48/77] 0.2.0 Automatically generated by python-semantic-release --- CHANGELOG.md | 7 +++++++ pyproject.toml | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e5b906b1..aa578918 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ +## v0.2.0 (2022-09-30) +### Feature +* First CI release ([`1b5f5a9`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/1b5f5a91e89826ba1c530c82570eb4465008a506)) + +### Fix +* CI didn't run; match version with latest release ([`d14a05c`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/d14a05c4e32bb6fdc4ce7195d3a932105ef258ca)) + ## v0.1.6 (2022-09-30) ### Fix * Version bump shouldn't invalidate cache in PRs ([`2cbd2b7`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/2cbd2b7c160dbf86c385d252ccf9b415f78e73fe)) diff --git a/pyproject.toml b/pyproject.toml index c7f59ecf..6a56be92 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "psycopt2d" -version = "0.1.6" +version = "0.2.0" description = "Training scripts for the psycop-t2d project" authors = ["Your Name "] From e68f8cf67e805bab9c19949529cdfb8d36720186 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Fri, 30 Sep 2022 14:31:02 +0200 Subject: [PATCH 49/77] ci: try centralised caching --- .github/workflows/main_test_and_release.yml | 36 ++------------------- .github/workflows/test_prs.yml | 29 ++--------------- 2 files changed, 6 insertions(+), 59 deletions(-) diff --git a/.github/workflows/main_test_and_release.yml b/.github/workflows/main_test_and_release.yml index 6cc8179c..2b6abe85 100644 --- a/.github/workflows/main_test_and_release.yml +++ b/.github/workflows/main_test_and_release.yml @@ -24,39 +24,9 @@ jobs: uses: actions/checkout@v3 ### Caching - - name: Linux, Overwrite version number from pyproject.toml, so it doesn't invalidate cache - id: remove-version-from-toml-macos - if: matrix.os == 'ubuntu-latest' - run: | - sed -i "s/version = \".*\"/version = \"0.0.0\"/g" pyproject.toml - cat pyproject.toml - - - name: Mac, Overwrite version number from pyproject.toml, so it doesn't invalidate cache - id: remove-version-from-toml-ubuntu - if: matrix.os == 'macos-latest' - run: | - sed -i '' "s/version = \".*\"/version = \"0.0.0\"/g" pyproject.toml - cat pyproject.toml - - - name: Load cached venv - id: cached-poetry-dependencies - uses: actions/cache@v2.1.6 - with: - path: | - .venv - poetry.lock - # Cache the complete venv dir for a given os, python version, pyproject.toml - key: venv-${{ runner.os }}-python-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml') }}-${{ hashFiles('.github/workflows/cache_version') }} - - - name: Mac, Linux, Load cached .local (Poetry install location) - id: cached-poetry - if: (matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest') - uses: actions/cache@v2.1.6 - with: - path: | - ~/.local/ - # Cache the complete venv dir for a given os, python version, pyproject.toml - key: venv-${{ runner.os }}-python-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml') }}-${{ hashFiles('.github/workflows/cache_version') }}--${{ hashFiles('.github/workflows/main_test_and_release.yml') }} + - name: Cache poetry and venv + id: cache-poetry-and-venv + uses: MartinBernstorff/cache-poetry-and-venv@latest ### Installing - name: Install Poetry diff --git a/.github/workflows/test_prs.yml b/.github/workflows/test_prs.yml index a5f365b7..88a798bc 100644 --- a/.github/workflows/test_prs.yml +++ b/.github/workflows/test_prs.yml @@ -23,32 +23,9 @@ jobs: uses: actions/checkout@v3 ### Caching - - name: Overwrite version number from pyproject.toml, so it doesn't invalidate cache - id: remove-version-from-toml - if: matrix.os == 'ubuntu-latest' - run: | - sed -i "s/version = \".*\"/version = \"0.0.0\"/g" pyproject.toml - cat pyproject.toml - - - name: Load cached venv - id: cached-poetry-dependencies - uses: actions/cache@v2.1.6 - with: - path: | - .venv - poetry.lock - # Cache the complete venv dir for a given os, python version, pyproject.toml - key: venv-${{ runner.os }}-python-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml') }}-${{ hashFiles('.github/workflows/cache_version') }} - - - name: Load cached .local (Poetry install location) - id: cached-poetry - if: (matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest') - uses: actions/cache@v2.1.6 - with: - path: | - ~/.local/ - # Cache the complete venv dir for a given os, python version, pyproject.toml - key: venv-${{ runner.os }}-python-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml') }}-${{ hashFiles('.github/workflows/cache_version') }}--${{ hashFiles('.github/workflows/test_prs.yml') }} + - name: Cache poetry and venv + id: cache-poetry-and-venv + uses: MartinBernstorff/cache-poetry-and-venv@latest # Installing - name: Install Poetry From 28834bad0527d99ba79dba7ca76fdcb3313aa4c8 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Fri, 30 Sep 2022 15:08:59 +0200 Subject: [PATCH 50/77] ci: retry centralised cache From c9238ea2011410d7432b8f37177afd2b996dc644 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Fri, 30 Sep 2022 15:41:14 +0200 Subject: [PATCH 51/77] ci: skip unused steps, invalidate cache based on matrix --- .github/workflows/test_prs.yml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test_prs.yml b/.github/workflows/test_prs.yml index 88a798bc..65dd1c9d 100644 --- a/.github/workflows/test_prs.yml +++ b/.github/workflows/test_prs.yml @@ -11,13 +11,15 @@ jobs: matrix: os: [macos-latest, ubuntu-latest, windows-latest] python-version: [3.9] + poetry-version: [1.1.15] + cache-version: [0.0.0] # Change this number if you want to manually invalidate all caches steps: ### Setup prerequisites - name: Set up Python uses: actions/setup-python@v4 with: - python-version: 3.9 + python-version: $ {{ matrix.python-version }} - name: Checkout repo uses: actions/checkout@v3 @@ -26,17 +28,21 @@ jobs: - name: Cache poetry and venv id: cache-poetry-and-venv uses: MartinBernstorff/cache-poetry-and-venv@latest + with: + poetry-version: ${{ matrix.poetry-version }} + cache-version: ${{ matrix.cache-version }} # Installing - name: Install Poetry + if: steps.cache-poetry-and-venv.outputs.poetry-cache-hit != 'true' uses: snok/install-poetry@v1 with: - version: 1.1.15 + version: ${{ matrix.poetry-version }} virtualenvs-create: true virtualenvs-in-project: true - name: Install Project - if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' + if: steps.cache-poetry-and-venv.outputs.venv-cache-hit != 'true' run: poetry install -vvv ### Run tests From 9774d6e10f1dd28f00745accf23ec6902eef35db Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Fri, 30 Sep 2022 15:42:17 +0200 Subject: [PATCH 52/77] fix: typo on CI --- .github/workflows/test_prs.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test_prs.yml b/.github/workflows/test_prs.yml index 65dd1c9d..b0029537 100644 --- a/.github/workflows/test_prs.yml +++ b/.github/workflows/test_prs.yml @@ -1,10 +1,10 @@ -name: CI Pytest +name: test_pr on: pull_request: branches: [ main, dev ] jobs: - pytest: + test_pr: runs-on: ${{ matrix.os }} strategy: @@ -19,7 +19,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v4 with: - python-version: $ {{ matrix.python-version }} + python-version: ${{ matrix.python-version }} - name: Checkout repo uses: actions/checkout@v3 From 8ffdd368a5a0762a26268eb1ffe34ced897334cc Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Fri, 30 Sep 2022 15:44:11 +0200 Subject: [PATCH 53/77] ci: retry centralised cache From 316e64335ee1b14aaf1c0a02fc7aad474af7a09a Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Fri, 30 Sep 2022 15:56:38 +0200 Subject: [PATCH 54/77] feat: try decomposing actions --- .../test_prs.yml => actions/test/action.yml} | 38 +++++++++++-------- .github/workflows/main_test_and_release.yml | 35 ++++------------- .github/workflows/pr_test.yml | 25 ++++++++++++ 3 files changed, 54 insertions(+), 44 deletions(-) rename .github/{workflows/test_prs.yml => actions/test/action.yml} (56%) create mode 100644 .github/workflows/pr_test.yml diff --git a/.github/workflows/test_prs.yml b/.github/actions/test/action.yml similarity index 56% rename from .github/workflows/test_prs.yml rename to .github/actions/test/action.yml index b0029537..f629a891 100644 --- a/.github/workflows/test_prs.yml +++ b/.github/actions/test/action.yml @@ -1,25 +1,31 @@ -name: test_pr -on: - pull_request: - branches: [ main, dev ] +name: 'Run tests' +description: 'Run tests' +inputs: + os: + description: "Which OS to run on" + required: true + default: 'ubuntu-latest' + python-version: + description: "Which Python version to run on" + required: true + default: 3.9 + poetry-version: + description: "Which version of Poetry to install" + default: 1.1.15 + cache-version: + description: "Cache version for invalidation" + default: 0.0.0 jobs: test_pr: - runs-on: ${{ matrix.os }} - - strategy: - matrix: - os: [macos-latest, ubuntu-latest, windows-latest] - python-version: [3.9] - poetry-version: [1.1.15] - cache-version: [0.0.0] # Change this number if you want to manually invalidate all caches + runs-on: ${{ input.os }} steps: ### Setup prerequisites - name: Set up Python uses: actions/setup-python@v4 with: - python-version: ${{ matrix.python-version }} + python-version: ${{ inputs.python-version }} - name: Checkout repo uses: actions/checkout@v3 @@ -29,15 +35,15 @@ jobs: id: cache-poetry-and-venv uses: MartinBernstorff/cache-poetry-and-venv@latest with: - poetry-version: ${{ matrix.poetry-version }} - cache-version: ${{ matrix.cache-version }} + poetry-version: ${{ inputs.poetry-version }} + cache-version: ${{ inputs.cache-version }} # Installing - name: Install Poetry if: steps.cache-poetry-and-venv.outputs.poetry-cache-hit != 'true' uses: snok/install-poetry@v1 with: - version: ${{ matrix.poetry-version }} + version: ${{ inputs.poetry-version }} virtualenvs-create: true virtualenvs-in-project: true diff --git a/.github/workflows/main_test_and_release.yml b/.github/workflows/main_test_and_release.yml index 2b6abe85..a7512937 100644 --- a/.github/workflows/main_test_and_release.yml +++ b/.github/workflows/main_test_and_release.yml @@ -13,38 +13,17 @@ jobs: matrix: os: [macos-latest, ubuntu-latest, windows-latest] python-version: [3.9] + poetry-version: [1.1.15] + cache-version: [0.0.0] # Change this number if you want to manually invalidate all caches steps: - - name: Set up Python - uses: actions/setup-python@v4 + - name: Run tests + uses: ./.github/actions/test with: + os: ${{ matrix.os }} python-version: ${{ matrix.python-version }} - - - name: Checkout repo - uses: actions/checkout@v3 - - ### Caching - - name: Cache poetry and venv - id: cache-poetry-and-venv - uses: MartinBernstorff/cache-poetry-and-venv@latest - - ### Installing - - name: Install Poetry - uses: snok/install-poetry@v1 - with: - version: 1.1.15 - virtualenvs-create: true - virtualenvs-in-project: true - - - name: Install Project - if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' - run: poetry install -vvv - - ### Run tests - - name: Run pytest - run: | - poetry run pytest --cov=src --cov-report term-missing --color=yes - + poetry-version: ${{ matrix.poetry-version }} + cache-version: ${{ matrix.cache-version }} release: runs-on: ubuntu-latest diff --git a/.github/workflows/pr_test.yml b/.github/workflows/pr_test.yml new file mode 100644 index 00000000..878ac30b --- /dev/null +++ b/.github/workflows/pr_test.yml @@ -0,0 +1,25 @@ +name: test_pr +on: + pull_request: + branches: [ main, dev ] + +jobs: + test_pr: + runs-on: ${{ matrix.os }} + + strategy: + matrix: + os: [macos-latest, ubuntu-latest, windows-latest] + python-version: [3.9] + poetry-version: [1.1.15] + cache-version: [0.0.0] # Change this number if you want to manually invalidate all caches + + steps: + - name: Run tests + uses: ./.github/actions/test + with: + os: ${{ matrix.os }} + python-version: ${{ matrix.python-version }} + poetry-version: ${{ matrix.poetry-version }} + cache-version: ${{ matrix.cache-version }} + From 29c5f9289453b09130673d1348affd36efbf63f8 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Fri, 30 Sep 2022 15:58:07 +0200 Subject: [PATCH 55/77] fix: checkout repo before attempting to use action --- .github/actions/test/action.yml | 3 --- .github/workflows/main_test_and_release.yml | 3 +++ .github/workflows/pr_test.yml | 3 +++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/actions/test/action.yml b/.github/actions/test/action.yml index f629a891..252a7aaa 100644 --- a/.github/actions/test/action.yml +++ b/.github/actions/test/action.yml @@ -27,9 +27,6 @@ jobs: with: python-version: ${{ inputs.python-version }} - - name: Checkout repo - uses: actions/checkout@v3 - ### Caching - name: Cache poetry and venv id: cache-poetry-and-venv diff --git a/.github/workflows/main_test_and_release.yml b/.github/workflows/main_test_and_release.yml index a7512937..6159aa88 100644 --- a/.github/workflows/main_test_and_release.yml +++ b/.github/workflows/main_test_and_release.yml @@ -17,6 +17,9 @@ jobs: cache-version: [0.0.0] # Change this number if you want to manually invalidate all caches steps: + - name: Checkout repo + uses: actions/checkout@v3 + - name: Run tests uses: ./.github/actions/test with: diff --git a/.github/workflows/pr_test.yml b/.github/workflows/pr_test.yml index 878ac30b..63244b97 100644 --- a/.github/workflows/pr_test.yml +++ b/.github/workflows/pr_test.yml @@ -15,6 +15,9 @@ jobs: cache-version: [0.0.0] # Change this number if you want to manually invalidate all caches steps: + - name: Checkout repo + uses: actions/checkout@v3 + - name: Run tests uses: ./.github/actions/test with: From e668badddeb80155da0bcf26c9bd5e155b3237bb Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Fri, 30 Sep 2022 16:00:18 +0200 Subject: [PATCH 56/77] fix: typo in action (input -> inputs) --- .github/actions/test/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/test/action.yml b/.github/actions/test/action.yml index 252a7aaa..f1c3ca19 100644 --- a/.github/actions/test/action.yml +++ b/.github/actions/test/action.yml @@ -18,7 +18,7 @@ inputs: jobs: test_pr: - runs-on: ${{ input.os }} + runs-on: ${{ inputs.os }} steps: ### Setup prerequisites From 612e88e92e592bcb7145ac12159161456b9cc6f4 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Fri, 30 Sep 2022 16:03:27 +0200 Subject: [PATCH 57/77] fix: another attempt --- .github/actions/test/action.yml | 12 +++--------- .github/workflows/main_test_and_release.yml | 1 - .github/workflows/pr_test.yml | 1 - 3 files changed, 3 insertions(+), 11 deletions(-) diff --git a/.github/actions/test/action.yml b/.github/actions/test/action.yml index f1c3ca19..45e0fd71 100644 --- a/.github/actions/test/action.yml +++ b/.github/actions/test/action.yml @@ -1,10 +1,6 @@ name: 'Run tests' description: 'Run tests' inputs: - os: - description: "Which OS to run on" - required: true - default: 'ubuntu-latest' python-version: description: "Which Python version to run on" required: true @@ -16,11 +12,9 @@ inputs: description: "Cache version for invalidation" default: 0.0.0 -jobs: - test_pr: - runs-on: ${{ inputs.os }} - - steps: +runs: + using: "composite" + steps: ### Setup prerequisites - name: Set up Python uses: actions/setup-python@v4 diff --git a/.github/workflows/main_test_and_release.yml b/.github/workflows/main_test_and_release.yml index 6159aa88..c0e28a36 100644 --- a/.github/workflows/main_test_and_release.yml +++ b/.github/workflows/main_test_and_release.yml @@ -23,7 +23,6 @@ jobs: - name: Run tests uses: ./.github/actions/test with: - os: ${{ matrix.os }} python-version: ${{ matrix.python-version }} poetry-version: ${{ matrix.poetry-version }} cache-version: ${{ matrix.cache-version }} diff --git a/.github/workflows/pr_test.yml b/.github/workflows/pr_test.yml index 63244b97..39179639 100644 --- a/.github/workflows/pr_test.yml +++ b/.github/workflows/pr_test.yml @@ -21,7 +21,6 @@ jobs: - name: Run tests uses: ./.github/actions/test with: - os: ${{ matrix.os }} python-version: ${{ matrix.python-version }} poetry-version: ${{ matrix.poetry-version }} cache-version: ${{ matrix.cache-version }} From 35745779716151b6e3f90e5a1b93023a27943603 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Fri, 30 Sep 2022 16:05:25 +0200 Subject: [PATCH 58/77] fix: specify shell --- .github/actions/test/action.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/actions/test/action.yml b/.github/actions/test/action.yml index 45e0fd71..c38e0f47 100644 --- a/.github/actions/test/action.yml +++ b/.github/actions/test/action.yml @@ -40,9 +40,11 @@ runs: - name: Install Project if: steps.cache-poetry-and-venv.outputs.venv-cache-hit != 'true' + shell: bash run: poetry install -vvv ### Run tests - name: Run pytest + shell: bash run: | poetry run pytest --cov=src --cov-report term-missing --color=yes From b8afd2f1ca34594e4936981cc9ca919e8f5fb3b8 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Fri, 30 Sep 2022 16:14:06 +0200 Subject: [PATCH 59/77] ci: update for modified caching --- .github/actions/test/action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/actions/test/action.yml b/.github/actions/test/action.yml index c38e0f47..b1b8522f 100644 --- a/.github/actions/test/action.yml +++ b/.github/actions/test/action.yml @@ -28,6 +28,7 @@ runs: with: poetry-version: ${{ inputs.poetry-version }} cache-version: ${{ inputs.cache-version }} + python-versoin: ${{ inputs.python-version }} # Installing - name: Install Poetry From 674688248d9dc300fe307217c064cfc97f8c7422 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Fri, 30 Sep 2022 16:14:40 +0200 Subject: [PATCH 60/77] ci: fix type on python-version --- .github/actions/test/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/test/action.yml b/.github/actions/test/action.yml index b1b8522f..825b0e6e 100644 --- a/.github/actions/test/action.yml +++ b/.github/actions/test/action.yml @@ -28,7 +28,7 @@ runs: with: poetry-version: ${{ inputs.poetry-version }} cache-version: ${{ inputs.cache-version }} - python-versoin: ${{ inputs.python-version }} + python-version: ${{ inputs.python-version }} # Installing - name: Install Poetry From 822ac84721962a9c03bd45810f72553f3c05dc33 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Fri, 30 Sep 2022 16:16:13 +0200 Subject: [PATCH 61/77] ci: retry centralised cache From b06034fc070a922155a5f421272be17d482ad2e3 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Fri, 30 Sep 2022 23:08:12 +0200 Subject: [PATCH 62/77] ci: improve based on comments --- .github/workflows/main_test_and_release.yml | 5 ++-- .github/workflows/pr_test.yml | 27 --------------------- 2 files changed, 3 insertions(+), 29 deletions(-) delete mode 100644 .github/workflows/pr_test.yml diff --git a/.github/workflows/main_test_and_release.yml b/.github/workflows/main_test_and_release.yml index c0e28a36..cc57e1b3 100644 --- a/.github/workflows/main_test_and_release.yml +++ b/.github/workflows/main_test_and_release.yml @@ -1,6 +1,7 @@ -name: Test and release main +name: Test (and release) on: + pull_request: push: branches: - main @@ -31,7 +32,7 @@ jobs: runs-on: ubuntu-latest concurrency: release needs: test - + if: github.ref == 'refs/heads/main' steps: # Checkout action is required for token to persist - uses: actions/checkout@v2 diff --git a/.github/workflows/pr_test.yml b/.github/workflows/pr_test.yml deleted file mode 100644 index 39179639..00000000 --- a/.github/workflows/pr_test.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: test_pr -on: - pull_request: - branches: [ main, dev ] - -jobs: - test_pr: - runs-on: ${{ matrix.os }} - - strategy: - matrix: - os: [macos-latest, ubuntu-latest, windows-latest] - python-version: [3.9] - poetry-version: [1.1.15] - cache-version: [0.0.0] # Change this number if you want to manually invalidate all caches - - steps: - - name: Checkout repo - uses: actions/checkout@v3 - - - name: Run tests - uses: ./.github/actions/test - with: - python-version: ${{ matrix.python-version }} - poetry-version: ${{ matrix.poetry-version }} - cache-version: ${{ matrix.cache-version }} - From 35af1854f9c2f681b0258ebeb414c1e64925fc26 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Sat, 1 Oct 2022 15:52:20 +0200 Subject: [PATCH 63/77] Rerun tests --- .github/workflows/main_test_and_release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main_test_and_release.yml b/.github/workflows/main_test_and_release.yml index cc57e1b3..89d8f3a1 100644 --- a/.github/workflows/main_test_and_release.yml +++ b/.github/workflows/main_test_and_release.yml @@ -32,7 +32,7 @@ jobs: runs-on: ubuntu-latest concurrency: release needs: test - if: github.ref == 'refs/heads/main' + if: github.ref == 'refs/heads/master' steps: # Checkout action is required for token to persist - uses: actions/checkout@v2 From 828f954a7285cf586161bd4568cc3160c8a19980 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Sun, 2 Oct 2022 16:30:46 +0200 Subject: [PATCH 64/77] Fix typo in GA, master -> main --- .github/workflows/main_test_and_release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main_test_and_release.yml b/.github/workflows/main_test_and_release.yml index 89d8f3a1..6db630e2 100644 --- a/.github/workflows/main_test_and_release.yml +++ b/.github/workflows/main_test_and_release.yml @@ -32,7 +32,7 @@ jobs: runs-on: ubuntu-latest concurrency: release needs: test - if: github.ref == 'refs/heads/master' + if: github.ref == 'refs/head/main' steps: # Checkout action is required for token to persist - uses: actions/checkout@v2 From 1b644d78cd9977c81fb142f0cefc190905aa19bd Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Sun, 2 Oct 2022 16:37:09 +0200 Subject: [PATCH 65/77] Invalidate cache --- .github/workflows/main_test_and_release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main_test_and_release.yml b/.github/workflows/main_test_and_release.yml index 6db630e2..af8757c5 100644 --- a/.github/workflows/main_test_and_release.yml +++ b/.github/workflows/main_test_and_release.yml @@ -15,7 +15,7 @@ jobs: os: [macos-latest, ubuntu-latest, windows-latest] python-version: [3.9] poetry-version: [1.1.15] - cache-version: [0.0.0] # Change this number if you want to manually invalidate all caches + cache-version: [0.0.1] # Change this number if you want to manually invalidate all caches steps: - name: Checkout repo From 62fbd6f8104fef4ba8f8465cee1678738eb49438 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Sun, 2 Oct 2022 17:21:54 +0200 Subject: [PATCH 66/77] Invalidate cache --- .github/workflows/main_test_and_release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main_test_and_release.yml b/.github/workflows/main_test_and_release.yml index af8757c5..3c4b0620 100644 --- a/.github/workflows/main_test_and_release.yml +++ b/.github/workflows/main_test_and_release.yml @@ -15,7 +15,7 @@ jobs: os: [macos-latest, ubuntu-latest, windows-latest] python-version: [3.9] poetry-version: [1.1.15] - cache-version: [0.0.1] # Change this number if you want to manually invalidate all caches + cache-version: [0.0.2] # Change this number if you want to manually invalidate all caches steps: - name: Checkout repo From 004d00cc1e8433b9bb1b4f52a79283c5de925358 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Mon, 3 Oct 2022 10:31:30 +0200 Subject: [PATCH 67/77] ci: migrate to shared test workflow --- .github/test/action.yml | 51 +++++++++++++++++++++ .github/workflows/main_test_and_release.yml | 38 ++++----------- 2 files changed, 61 insertions(+), 28 deletions(-) create mode 100644 .github/test/action.yml diff --git a/.github/test/action.yml b/.github/test/action.yml new file mode 100644 index 00000000..825b0e6e --- /dev/null +++ b/.github/test/action.yml @@ -0,0 +1,51 @@ +name: 'Run tests' +description: 'Run tests' +inputs: + python-version: + description: "Which Python version to run on" + required: true + default: 3.9 + poetry-version: + description: "Which version of Poetry to install" + default: 1.1.15 + cache-version: + description: "Cache version for invalidation" + default: 0.0.0 + +runs: + using: "composite" + steps: + ### Setup prerequisites + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: ${{ inputs.python-version }} + + ### Caching + - name: Cache poetry and venv + id: cache-poetry-and-venv + uses: MartinBernstorff/cache-poetry-and-venv@latest + with: + poetry-version: ${{ inputs.poetry-version }} + cache-version: ${{ inputs.cache-version }} + python-version: ${{ inputs.python-version }} + + # Installing + - name: Install Poetry + if: steps.cache-poetry-and-venv.outputs.poetry-cache-hit != 'true' + uses: snok/install-poetry@v1 + with: + version: ${{ inputs.poetry-version }} + virtualenvs-create: true + virtualenvs-in-project: true + + - name: Install Project + if: steps.cache-poetry-and-venv.outputs.venv-cache-hit != 'true' + shell: bash + run: poetry install -vvv + + ### Run tests + - name: Run pytest + shell: bash + run: | + poetry run pytest --cov=src --cov-report term-missing --color=yes diff --git a/.github/workflows/main_test_and_release.yml b/.github/workflows/main_test_and_release.yml index 2b6abe85..2633ed2a 100644 --- a/.github/workflows/main_test_and_release.yml +++ b/.github/workflows/main_test_and_release.yml @@ -1,6 +1,7 @@ -name: Test and release main +name: Test (and release) on: + pull_request: push: branches: - main @@ -13,44 +14,25 @@ jobs: matrix: os: [macos-latest, ubuntu-latest, windows-latest] python-version: [3.9] + poetry-version: [1.1.15] + cache-version: [0.0.2] # Change this number if you want to manually invalidate all caches steps: - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python-version }} - - name: Checkout repo uses: actions/checkout@v3 - ### Caching - - name: Cache poetry and venv - id: cache-poetry-and-venv - uses: MartinBernstorff/cache-poetry-and-venv@latest - - ### Installing - - name: Install Poetry - uses: snok/install-poetry@v1 + - name: Run tests + uses: ./.github/actions/test with: - version: 1.1.15 - virtualenvs-create: true - virtualenvs-in-project: true - - - name: Install Project - if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' - run: poetry install -vvv - - ### Run tests - - name: Run pytest - run: | - poetry run pytest --cov=src --cov-report term-missing --color=yes - + python-version: ${{ matrix.python-version }} + poetry-version: ${{ matrix.poetry-version }} + cache-version: ${{ matrix.cache-version }} release: runs-on: ubuntu-latest concurrency: release needs: test - + if: ${{ github.ref == 'refs/heads/main' }} steps: # Checkout action is required for token to persist - uses: actions/checkout@v2 From d08c2d2096df30b25e0fd18f63c55debed6fc862 Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 3 Oct 2022 08:35:08 +0000 Subject: [PATCH 68/77] 0.3.0 Automatically generated by python-semantic-release --- CHANGELOG.md | 11 +++++++++++ pyproject.toml | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aa578918..7ce858a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,17 @@ +## v0.3.0 (2022-10-03) +### Feature +* Try decomposing actions ([`316e643`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/316e64335ee1b14aaf1c0a02fc7aad474af7a09a)) + +### Fix +* Specify shell ([`3574577`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/35745779716151b6e3f90e5a1b93023a27943603)) +* Another attempt ([`612e88e`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/612e88e92e592bcb7145ac12159161456b9cc6f4)) +* Typo in action (input -> inputs) ([`e668bad`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/e668badddeb80155da0bcf26c9bd5e155b3237bb)) +* Checkout repo before attempting to use action ([`29c5f92`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/29c5f9289453b09130673d1348affd36efbf63f8)) +* Typo on CI ([`9774d6e`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/9774d6e10f1dd28f00745accf23ec6902eef35db)) + ## v0.2.0 (2022-09-30) ### Feature * First CI release ([`1b5f5a9`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/1b5f5a91e89826ba1c530c82570eb4465008a506)) diff --git a/pyproject.toml b/pyproject.toml index 6a56be92..4a0b119c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "psycopt2d" -version = "0.2.0" +version = "0.3.0" description = "Training scripts for the psycop-t2d project" authors = ["Your Name "] From c75743b93d681c06d68741cbf2a1fd319a5fd555 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Mon, 3 Oct 2022 14:28:37 +0200 Subject: [PATCH 69/77] ci: delete unused test action --- .github/test/action.yml | 51 ----------------------------------------- 1 file changed, 51 deletions(-) delete mode 100644 .github/test/action.yml diff --git a/.github/test/action.yml b/.github/test/action.yml deleted file mode 100644 index 825b0e6e..00000000 --- a/.github/test/action.yml +++ /dev/null @@ -1,51 +0,0 @@ -name: 'Run tests' -description: 'Run tests' -inputs: - python-version: - description: "Which Python version to run on" - required: true - default: 3.9 - poetry-version: - description: "Which version of Poetry to install" - default: 1.1.15 - cache-version: - description: "Cache version for invalidation" - default: 0.0.0 - -runs: - using: "composite" - steps: - ### Setup prerequisites - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: ${{ inputs.python-version }} - - ### Caching - - name: Cache poetry and venv - id: cache-poetry-and-venv - uses: MartinBernstorff/cache-poetry-and-venv@latest - with: - poetry-version: ${{ inputs.poetry-version }} - cache-version: ${{ inputs.cache-version }} - python-version: ${{ inputs.python-version }} - - # Installing - - name: Install Poetry - if: steps.cache-poetry-and-venv.outputs.poetry-cache-hit != 'true' - uses: snok/install-poetry@v1 - with: - version: ${{ inputs.poetry-version }} - virtualenvs-create: true - virtualenvs-in-project: true - - - name: Install Project - if: steps.cache-poetry-and-venv.outputs.venv-cache-hit != 'true' - shell: bash - run: poetry install -vvv - - ### Run tests - - name: Run pytest - shell: bash - run: | - poetry run pytest --cov=src --cov-report term-missing --color=yes From 346368ad0a8dd013814e25941d9b6560941bc410 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Tue, 4 Oct 2022 14:07:51 +0200 Subject: [PATCH 70/77] ci: update PR template --- .github/pull_request_template.md | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 651849fa..a2475804 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,5 +1,6 @@ - [ ] I have battle-tested on Overtaci (RMAPPS1279) - [ ] I have assigned ranges (e.g. `>=0.1, <0.2`) to all new dependencies (allows dependabot to keep dependency ranges wide for better compatability) +- [ ] At least one of the commits is prefixed with either "fix:" or "feat:" ## Notes for reviewers Reviewers can skip X, but should pay attention to Y. From 501c27383779601d9faade95b30646de393b2873 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Sat, 1 Oct 2022 18:56:01 +0200 Subject: [PATCH 71/77] minor linting --- src/psycopt2d/evaluation.py | 15 +++++++-------- src/psycopt2d/visualization/altair_utils.py | 3 ++- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/psycopt2d/evaluation.py b/src/psycopt2d/evaluation.py index 7c21001a..5129b3f2 100644 --- a/src/psycopt2d/evaluation.py +++ b/src/psycopt2d/evaluation.py @@ -1,12 +1,12 @@ """Functions for evaluating a model's prredictions.""" -from typing import Iterable, Optional +from collections.abc import Iterable import altair as alt import numpy as np import pandas as pd -import wandb from sklearn.metrics import f1_score, roc_auc_score from sklearn.pipeline import Pipeline +from wandb.sdk.wandb_run import Run as wandb_run from psycopt2d.tables import generate_feature_importances_table from psycopt2d.tables.performance_by_threshold import ( @@ -30,7 +30,7 @@ def evaluate_model( y_col_name: str, train_col_names: Iterable[str], y_hat_prob_col_name: str, - run: Optional[wandb.run] = None, + run: wandb_run, ): """Runs the evaluation suite on the model and logs to WandB. At present, this includes: @@ -49,8 +49,7 @@ def evaluate_model( y_col_name (str): Label column name train_col_names (Iterable[str]): Column names for all predictors y_hat_prob_col_name (str): Column name containing pred_proba output - run (Optional[wandb.run]): WandB run to log to. Will not log to WandB if - set to None + run (wandb_run): WandB run to log to. """ y = eval_dataset[y_col_name] y_hat_probs = eval_dataset[y_hat_prob_col_name] @@ -88,7 +87,7 @@ def evaluate_model( f.write(f"{run.id},{auc}\n") # Tables - ## Performance by threshold + # Performance by threshold performance_by_threshold_df = generate_performance_by_positive_rate_table( labels=y, pred_probs=y_hat_probs, @@ -128,7 +127,7 @@ def evaluate_model( ) run.log({"feature_importance_table": feature_importances_table}) - ## Sensitivity by time to outcome + # Sensitivity by time to outcome plots.update( { "sensitivity_by_time_by_threshold": plot_sensitivity_by_time_to_outcome( @@ -163,6 +162,6 @@ def evaluate_model( }, ) - ## Log all the figures to wandb + # Log all the figures to wandb for chart_name, chart_obj in plots.items(): log_altair_to_wandb(chart=chart_obj, chart_name=chart_name, run=run) diff --git a/src/psycopt2d/visualization/altair_utils.py b/src/psycopt2d/visualization/altair_utils.py index 07372dd9..b99e7245 100644 --- a/src/psycopt2d/visualization/altair_utils.py +++ b/src/psycopt2d/visualization/altair_utils.py @@ -3,6 +3,7 @@ import wandb from altair.vegalite.v4.api import Chart +from wandb.sdk.wandb_run import Run as wandb_run def altair_chart_to_file( @@ -32,7 +33,7 @@ def altair_chart_to_file( return str(filepath) -def log_altair_to_wandb(chart: Chart, chart_name: str, run: wandb.run): +def log_altair_to_wandb(chart: Chart, chart_name: str, run: wandb_run): # type: ignore """Helper to log Altair charts. Args: From de621e8bbdb22addae980822f0926cfd733d1e3a Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Sat, 1 Oct 2022 19:16:39 +0200 Subject: [PATCH 72/77] fix: some extra linting --- src/psycopt2d/train_model.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/psycopt2d/train_model.py b/src/psycopt2d/train_model.py index 15697ddf..d60bb630 100644 --- a/src/psycopt2d/train_model.py +++ b/src/psycopt2d/train_model.py @@ -1,7 +1,6 @@ """Training script for training a single model for predicting t2d.""" import os from pathlib import Path -from typing import List, Tuple import hydra import numpy as np @@ -55,6 +54,8 @@ def create_preprocessing_pipeline(cfg): def create_model(cfg): + """Instantiate and return a model object based on settings in the config + file.""" model_dict = MODELS.get(cfg.model.model_name) model_args = model_dict["static_hyperparameters"] @@ -66,7 +67,7 @@ def create_model(cfg): return mdl -def load_dataset_from_config(cfg) -> Tuple[pd.DataFrame, pd.DataFrame]: +def load_dataset_from_config(cfg) -> tuple[pd.DataFrame, pd.DataFrame]: """Load dataset based on settings in the config file.""" allowed_data_sources = {"csv", "synthetic"} @@ -115,12 +116,12 @@ def stratified_cross_validation( cfg, pipe: Pipeline, dataset: pd.DataFrame, - train_col_names: List[str], + train_col_names: list[str], outcome_col_name: str, ): """Performs stratified and grouped cross validation using the pipeline.""" - X = dataset[train_col_names] - y = dataset[outcome_col_name] + X = dataset[train_col_names] # pylint: disable=invalid-name + y = dataset[outcome_col_name] # pylint: disable=invalid-name # Create folds folds = StratifiedGroupKFold(n_splits=cfg.training.n_splits).split( @@ -132,7 +133,7 @@ def stratified_cross_validation( # Perform CV and get out of fold predictions dataset["oof_y_hat"] = np.nan for train_idxs, val_idxs in folds: - X_, y_ = X.loc[train_idxs], y.loc[train_idxs] + X_, y_ = X.loc[train_idxs], y.loc[train_idxs] # pylint: disable=invalid-name pipe.fit(X_, y_) y_hat = pipe.predict_proba(X_)[:, 1] @@ -146,11 +147,12 @@ def stratified_cross_validation( @hydra.main( - config_path=CONFIG_PATH, + config_path=str(CONFIG_PATH), config_name="default_config", version_base="1.2", ) def main(cfg): + """Main function for training a single model.""" run = wandb.init( project=cfg.project.name, reinit=True, @@ -172,12 +174,12 @@ def main(cfg): pipe = Pipeline(steps) # train - ## define columns - OUTCOME_COL_NAME = ( + # define columns + OUTCOME_COL_NAME = ( # pylint: disable=invalid-name f"outc_dichotomous_t2d_within_{cfg.data.lookahead_days}_days_max_fallback_0" ) - TRAIN_COL_NAMES = [ + TRAIN_COL_NAMES = [ # pylint: disable=invalid-name c for c in train.columns if c.startswith(cfg.data.pred_col_name_prefix) ] @@ -187,9 +189,9 @@ def main(cfg): pipe["model"].feature_names = TRAIN_COL_NAMES if cfg.training.n_splits is None: # train on pre-defined splits - X_train = train[TRAIN_COL_NAMES] + X_train = train[TRAIN_COL_NAMES] # pylint: disable=invalid-name y_train = train[OUTCOME_COL_NAME] - X_val = val[TRAIN_COL_NAMES] + X_val = val[TRAIN_COL_NAMES] # pylint: disable=invalid-name pipe.fit(X_train, y_train) From 03a0be1772737379cdcb2088934f6e7666d54013 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Sat, 1 Oct 2022 19:24:36 +0200 Subject: [PATCH 73/77] fix: more linting, enable pylint pre-commit hook --- .pre-commit-config.yaml | 13 ++++++++++ src/psycopt2d/evaluation.py | 2 +- .../synth_data_generator.py | 1 + src/psycopt2d/tables/__init__.py | 1 + src/psycopt2d/tables/tables.py | 24 ++++++++++++++----- 5 files changed, 34 insertions(+), 7 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 031bf0eb..02e37842 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -44,3 +44,16 @@ repos: entry: check-yaml language: python types: [yaml] + + - repo: https://github.com/pycqa/pylint + rev: v2.15.2 + hooks: + - id: pylint + types: [python] + args: + [ + "-rn", # Only display messages + "-sn", # Don't display the score + "--disable=R,import-error" # Refactors are not important enough to block a commit. + # Unused-imports aren't testable by the github action, so don't test that here. + ] \ No newline at end of file diff --git a/src/psycopt2d/evaluation.py b/src/psycopt2d/evaluation.py index 5129b3f2..f3505ecb 100644 --- a/src/psycopt2d/evaluation.py +++ b/src/psycopt2d/evaluation.py @@ -122,7 +122,7 @@ def evaluate_model( ) # Log as table too for readability feature_importances_table = generate_feature_importances_table( - column_names=feature_names, + feature_names=feature_names, feature_importances=pipe["model"].feature_importances_, ) run.log({"feature_importance_table": feature_importances_table}) diff --git a/src/psycopt2d/synth_data_generator/synth_data_generator.py b/src/psycopt2d/synth_data_generator/synth_data_generator.py index 61a18e57..aba6e34f 100644 --- a/src/psycopt2d/synth_data_generator/synth_data_generator.py +++ b/src/psycopt2d/synth_data_generator/synth_data_generator.py @@ -1,3 +1,4 @@ +# TODO: Refactor this to use only be an application of module in psycop-ml-utils instead. from pathlib import Path from typing import Dict, List, Optional, Tuple, Union diff --git a/src/psycopt2d/tables/__init__.py b/src/psycopt2d/tables/__init__.py index 234ec2e1..20d4dcf2 100644 --- a/src/psycopt2d/tables/__init__.py +++ b/src/psycopt2d/tables/__init__.py @@ -1,2 +1,3 @@ +# pylint: disable=missing-module-docstring from .performance_by_threshold import generate_performance_by_positive_rate_table from .tables import auc_by_group_table, generate_feature_importances_table diff --git a/src/psycopt2d/tables/tables.py b/src/psycopt2d/tables/tables.py index dfbe1345..746af043 100644 --- a/src/psycopt2d/tables/tables.py +++ b/src/psycopt2d/tables/tables.py @@ -1,5 +1,7 @@ +"""Tables for evaluation of models.""" +from collections.abc import Iterable from functools import partial -from typing import Iterable, List, Union +from typing import Union import pandas as pd import wandb @@ -10,7 +12,7 @@ def auc_by_group_table( df: pd.DataFrame, pred_probs_col_name: str, outcome_col_name: str, - groups: Union[List[str], str], + groups: Union[list[str], str], ) -> pd.DataFrame: """Create table with AUC per group. @@ -19,7 +21,7 @@ def auc_by_group_table( and groups to stratify by. pred_probs_col_name (str): The column containing the predicted probabilities outcome_col_name (str): The column containing the labels - groups (Union[List[str], str]): The (categorical) groups to + groups (Union[list[str], str]): The (categorical) groups to stratify the table by. Returns: @@ -68,13 +70,23 @@ def _calc_auc_and_n( def generate_feature_importances_table( - column_names: Iterable[str], + feature_names: Iterable[str], feature_importances: Iterable[str], output_format: str = "wandb_table", -) -> Union[pd.DataFrame, str]: +) -> Union[pd.DataFrame, wandb.Table]: + """Generate table with feature importances. + + Args: + feature_names (Iterable[str]): The names of the columns to generate feature_importances for + feature_importances (Iterable[str]): The feature importances + output_format (str, optional): The output format. Takes one of "html", "df", "wandb_table". Defaults to "wandb_table". + + Returns: + Union[pd.DataFrame, wandb.Table]: The table with feature importances + """ df = pd.DataFrame( - {"predictor": column_names, "feature_importance": feature_importances}, + {"predictor": feature_names, "feature_importance": feature_importances}, ) df = df.sort_values("feature_importance", ascending=False) From d72b913295bee00db2592ef7a93091d803ddba22 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Sun, 2 Oct 2022 16:30:03 +0200 Subject: [PATCH 74/77] Rename List to list --- reports/render_report.py | 6 ++--- .../evaluate_saved_model_predictions.py | 10 ++++---- src/psycopt2d/feature_transformers.py | 10 ++++---- src/psycopt2d/load.py | 6 ++--- src/psycopt2d/sync_best_runs_to_wandb.py | 4 ++-- .../synth_data_generator.py | 14 +++++------ src/psycopt2d/utils.py | 24 +++++++++---------- .../visualization/feature_importance.py | 4 ++-- .../visualization/performance_over_time.py | 4 ++-- src/psycopt2d/visualization/sens_over_time.py | 8 +++---- 10 files changed, 45 insertions(+), 45 deletions(-) diff --git a/reports/render_report.py b/reports/render_report.py index 0b2ca444..1c784fb8 100644 --- a/reports/render_report.py +++ b/reports/render_report.py @@ -6,7 +6,7 @@ be in a dir called 'tables' and figures in a dir called 'figs' """ -from typing import List +from typing import list import pandas as pd @@ -48,11 +48,11 @@ def load_table(filepath: str): return df.to_markdown() -def center_text(text: List[str]): +def center_text(text: list[str]): return "\n" + f"""
{_join_by_newline(text)}
""" -def _join_by_newline(text: List[str]): +def _join_by_newline(text: list[str]): return "\n\n".join(text) diff --git a/src/psycopt2d/evaluate_saved_model_predictions.py b/src/psycopt2d/evaluate_saved_model_predictions.py index 9a0c21d6..5fae4c72 100644 --- a/src/psycopt2d/evaluate_saved_model_predictions.py +++ b/src/psycopt2d/evaluate_saved_model_predictions.py @@ -9,7 +9,7 @@ from pathlib import Path import pandas as pd -from omegaconf.dictconfig import DictConfig +from omegaconf.dictconfig import dictConfig from psycopt2d.utils import PROJECT_ROOT, read_pickle from psycopt2d.visualization import plot_auc_by_time_from_first_visit @@ -23,20 +23,20 @@ def infer_outcome_col_name(df: pd.DataFrame): raise ValueError("More than one outcome inferred") -def infer_predictor_col_names(df: pd.DataFrame, cfg: DictConfig) -> list[str]: +def infer_predictor_col_names(df: pd.DataFrame, cfg: dictConfig) -> list[str]: """Get the predictors that are used in the model. Args: df (pd.Dataframe): Dataframe with model predictions - cfg (DictConfig): Config file + cfg (dictConfig): Config file Returns: - list[str]: List of predictors + list[str]: list of predictors """ return [c for c in df.columns if c.startswith(cfg.data.pred_col_name_prefix)] -def load_model_predictions_and_cfg(path: Path) -> tuple[pd.DataFrame, DictConfig]: +def load_model_predictions_and_cfg(path: Path) -> tuple[pd.DataFrame, dictConfig]: """Load model predictions and config file from a pickle file. Args: diff --git a/src/psycopt2d/feature_transformers.py b/src/psycopt2d/feature_transformers.py index 7af641b1..bf318af5 100644 --- a/src/psycopt2d/feature_transformers.py +++ b/src/psycopt2d/feature_transformers.py @@ -1,6 +1,6 @@ """Custom transformers for data preprocessing.""" from datetime import datetime -from typing import List, Optional +from typing import Optional, list from sklearn.base import BaseEstimator, TransformerMixin @@ -10,15 +10,15 @@ class ConvertToBoolean(BaseEstimator, TransformerMixin): def __init__( self, - columns_to_include: Optional[List[str]] = None, - columns_to_skip: Optional[List[str]] = ["age_in_years", "sex_female"], + columns_to_include: Optional[list[str]] = None, + columns_to_skip: Optional[list[str]] = ["age_in_years", "sex_female"], ignore_dtypes: Optional[set] = {"datetime64[ns]", " None: """ Args: - columns_to_include (List[str], optional): Columns to convert to boolean. + columns_to_include (list[str], optional): Columns to convert to boolean. Acts as a whitelist, skipping all columns not in the list. - columns_to_skip (List[str], optional): Columns to not convert to boolean. + columns_to_skip (list[str], optional): Columns to not convert to boolean. Acts as a blacklist. Defaults to ["age_in_years", "male"]. Default to None in which case all columns are included. diff --git a/src/psycopt2d/load.py b/src/psycopt2d/load.py index d2afafca..f12e4d99 100644 --- a/src/psycopt2d/load.py +++ b/src/psycopt2d/load.py @@ -1,7 +1,7 @@ # from datetime import date, datetime, timedelta from datetime import date, datetime, timedelta from pathlib import Path -from typing import List, Optional, Union +from typing import Optional, Union, list import pandas as pd from psycopmlutils.sql.loader import sql_load @@ -11,7 +11,7 @@ def load_dataset( - split_names: Union[List[str], str], + split_names: Union[list[str], str], dir: Path, drop_patient_if_outcome_before_date: Union[datetime, str], min_lookahead_days: int, @@ -21,7 +21,7 @@ def load_dataset( """Load dataset for t2d. Args: - split_names (Union[List[str], str]): Names of splits, includes "train", "val", + split_names (Union[list[str], str]): Names of splits, includes "train", "val", "test". dir (Path): Directory of the dataset. drop_patient_if_outcome_before_date (Union[datetime, str]): Remove patients which diff --git a/src/psycopt2d/sync_best_runs_to_wandb.py b/src/psycopt2d/sync_best_runs_to_wandb.py index 84ed1046..cf49f8da 100644 --- a/src/psycopt2d/sync_best_runs_to_wandb.py +++ b/src/psycopt2d/sync_best_runs_to_wandb.py @@ -19,7 +19,7 @@ def get_best_run_ids(top_n: int) -> list[str]: top_n (int): Number of runs to return Returns: - list[str]: List of run ids + list[str]: list of run ids """ df = pd.read_csv(AUC_LOGGING_FILE_PATH) return df.sort_values("auc", ascending=False)["run_id"].tolist()[:top_n] @@ -42,7 +42,7 @@ def sync_runs_to_wandb(runs: list[str], project: str) -> None: """Sync runs to wandb. Args: - runs (list[str]): List of run ids + runs (list[str]): list of run ids project (str): Project name """ diff --git a/src/psycopt2d/synth_data_generator/synth_data_generator.py b/src/psycopt2d/synth_data_generator/synth_data_generator.py index aba6e34f..ae42ac45 100644 --- a/src/psycopt2d/synth_data_generator/synth_data_generator.py +++ b/src/psycopt2d/synth_data_generator/synth_data_generator.py @@ -1,6 +1,6 @@ # TODO: Refactor this to use only be an application of module in psycop-ml-utils instead. from pathlib import Path -from typing import Dict, List, Optional, Tuple, Union +from typing import Optional, Union import numpy as np import pandas as pd @@ -8,20 +8,20 @@ def generate_synth_data( - predictors: Dict, + predictors: dict, outcome_column_name: str, n_samples: int, logistic_outcome_model: str, intercept: Optional[Union[int, float, complex, str, bytes]] = 0, na_prob: Optional[float] = 0.01, - na_ignore_cols: List[str] = [], + na_ignore_cols: list[str] = [], prob_outcome: Optional[float] = 0.08, - noise_mean_sd: Optional[Tuple[float, float]] = (0, 1), + noise_mean_sd: Optional[tuple[float, float]] = (0, 1), ) -> pd.DataFrame: """Takes a dict and generates synth data from it. Args: - predictors (Dict): A dict representing each column of shape: + predictors (dict): A dict representing each column of shape: {"col_name": { "column_type": str, @@ -37,9 +37,9 @@ def generate_synth_data( intercept (float, optional): The intercept of the logistic outcome model. Defaults to 0. na_prob (float, optional): Probability of changing a value in a predictor column to NA. - na_ignore_cols (List[str], optional): Columns to ignore when creating NAs + na_ignore_cols (list[str], optional): Columns to ignore when creating NAs prob_outcome (float): Probability of a given row receiving "1" for the outcome. - noise_mean_sd (Tuple[float, float], optional): mean and sd of the noise. + noise_mean_sd (tuple[float, float], optional): mean and sd of the noise. Increase SD to obtain more uncertain models. Returns: diff --git a/src/psycopt2d/utils.py b/src/psycopt2d/utils.py index 7cc5ced1..eb6601f2 100644 --- a/src/psycopt2d/utils.py +++ b/src/psycopt2d/utils.py @@ -1,12 +1,12 @@ import time from collections.abc import MutableMapping from pathlib import Path -from typing import Any, Dict, Iterable, List, Union +from typing import Any, Iterable, Union, dict, list import dill as pkl import numpy as np import pandas as pd -from omegaconf.dictconfig import DictConfig +from omegaconf.dictconfig import dictConfig from wasabi import msg from psycopt2d.model_performance import ModelPerformance @@ -45,22 +45,22 @@ def format_dict_for_printing(d: dict) -> str: def flatten_nested_dict( - d: Dict, + d: dict, parent_key: str = "", sep: str = ".", -) -> Dict: +) -> dict: """Recursively flatten an infinitely nested dict. E.g. {"level1": {"level2": "level3": {"level4": 5}}}} becomes {"level1.level2.level3.level4": 5}. Args: - d (Dict): Dict to flatten. + d (dict): dict to flatten. parent_key (str): The parent key for the current dict, e.g. "level1" for the first iteration. sep (str): How to separate each level in the dict. Defaults to ".". Returns: - Dict: The flattened dict. + dict: The flattened dict. """ items = [] @@ -111,12 +111,12 @@ def drop_records_if_datediff_days_smaller_than( ] -def round_floats_to_edge(series: pd.Series, bins: List[float]) -> np.ndarray: +def round_floats_to_edge(series: pd.Series, bins: list[float]) -> np.ndarray: """Rounds a float to the lowest value it is larger than. Args: series (pd.Series): The series of floats to round to bin edges. - bins (List[floats]): Values to round to. + bins (list[floats]): Values to round to. Returns: A numpy ndarray with the borders. @@ -158,12 +158,12 @@ def calculate_performance_metrics( return performance_metrics -def bin_continuous_data(series: pd.Series, bins: List[int]) -> pd.Series: +def bin_continuous_data(series: pd.Series, bins: list[int]) -> pd.Series: """For prettier formatting of continuous binned data such as age. Args: series (pd.Series): Series with continuous data such as age - bins (List[int]): Desired bins + bins (list[int]): Desired bins Returns: pd.Series: Binned data @@ -247,13 +247,13 @@ def read_pickle(path: str) -> Any: return pkl.load(f) -def prediction_df_with_metadata_to_disk(df: pd.DataFrame, cfg: DictConfig) -> None: +def prediction_df_with_metadata_to_disk(df: pd.DataFrame, cfg: dictConfig) -> None: """Saves prediction dataframe with and hydra config to disk. Stored as a dict with keys "df" and "cfg". Args: df (pd.DataFrame): Dataframe to save. - cfg (DictConfig): Hydra config. + cfg (dictConfig): Hydra config. """ model_args = format_dict_for_printing(cfg.model) diff --git a/src/psycopt2d/visualization/feature_importance.py b/src/psycopt2d/visualization/feature_importance.py index 5c9c2238..70ea625e 100644 --- a/src/psycopt2d/visualization/feature_importance.py +++ b/src/psycopt2d/visualization/feature_importance.py @@ -1,4 +1,4 @@ -from typing import Iterable, List, Union +from typing import Iterable, Union, list import altair as alt import numpy as np @@ -8,7 +8,7 @@ def plot_feature_importances( column_names: Iterable[str], - feature_importances: Union[List[float], np.ndarray], + feature_importances: Union[list[float], np.ndarray], top_n_feature_importances: int, ) -> alt.Chart: """Plots feature importances. diff --git a/src/psycopt2d/visualization/performance_over_time.py b/src/psycopt2d/visualization/performance_over_time.py index ccfcb366..16a3cbc2 100644 --- a/src/psycopt2d/visualization/performance_over_time.py +++ b/src/psycopt2d/visualization/performance_over_time.py @@ -3,7 +3,7 @@ 2. AUC by time from first visit 3. AUC by time until diagnosis """ -from typing import Callable, Iterable, List, Optional +from typing import Callable, Iterable, Optional, list import altair as alt import numpy as np @@ -105,7 +105,7 @@ def create_performance_by_time_from_event_df( prediction_timestamps: Iterable[pd.Timestamp], metric_fn: Callable, direction: str, - bins: List[int], + bins: list[int], pretty_bins: Optional[bool] = True, drop_na_events: Optional[bool] = True, ) -> pd.DataFrame: diff --git a/src/psycopt2d/visualization/sens_over_time.py b/src/psycopt2d/visualization/sens_over_time.py index b948ad9a..b5623b3e 100644 --- a/src/psycopt2d/visualization/sens_over_time.py +++ b/src/psycopt2d/visualization/sens_over_time.py @@ -1,5 +1,5 @@ from functools import partial -from typing import Iterable, List +from typing import Iterable, list import altair as alt import numpy as np @@ -96,17 +96,17 @@ def create_sensitivity_by_time_to_outcome_df( def plot_sensitivity_by_time_to_outcome( labels: Iterable[int], y_hat_probs: Iterable[int], - pred_proba_thresholds: List[float], + pred_proba_thresholds: list[float], outcome_timestamps: Iterable[pd.Timestamp], prediction_timestamps: Iterable[pd.Timestamp], - bins: List[int] = [0, 28, 182, 365, 730, 1825], + bins: list[int] = [0, 28, 182, 365, 730, 1825], ): """Plot sensitivity by time to outcome. Args: labels (Iterable[int]): True labels of the data. y_hat_probs (Iterable[int]): Predicted probability of class 1. - pred_proba_thresholds (Iterable[float]): List of pred_proba thresholds to plot, above which predictions are classified as positive. + pred_proba_thresholds (Iterable[float]): list of pred_proba thresholds to plot, above which predictions are classified as positive. outcome_timestamps (Iterable[pd.Timestamp]): Timestamp of the outcome, if any. prediction_timestamps (Iterable[pd.Timestamp]): Timestamp of the prediction. bins (list, optional): Default bins for time to outcome. Defaults to [0, 1, 7, 14, 28, 182, 365, 730, 1825]. From ad4142b315cc9feaad9d07a61ad4d745a3a463ce Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Tue, 4 Oct 2022 11:14:19 +0200 Subject: [PATCH 75/77] lint: fix all pylint --- .pre-commit-config.yaml | 3 +- docs/conf.py | 2 +- pyproject.toml | 12 ++- reports/render_report.py | 40 ++++++---- src/psycopt2d/about.py | 1 + .../generate_synthetic_dataset_for_eval.py | 14 ++-- .../evaluate_saved_model_predictions.py | 19 +++-- src/psycopt2d/evaluation.py | 2 +- src/psycopt2d/feature_transformers.py | 26 ++++--- src/psycopt2d/load.py | 17 +++-- src/psycopt2d/models.py | 6 +- .../synth_data_generator.py | 23 ++++-- .../tables/performance_by_threshold.py | 76 ++++++++++--------- src/psycopt2d/train_model.py | 6 +- src/psycopt2d/utils.py | 22 +++--- src/psycopt2d/visualization/__init__.py | 1 + src/psycopt2d/visualization/altair_utils.py | 1 + src/psycopt2d/visualization/base_charts.py | 4 +- .../visualization/feature_importance.py | 5 +- .../visualization/performance_over_time.py | 15 ++-- src/psycopt2d/visualization/prob_over_time.py | 3 +- src/psycopt2d/visualization/sens_over_time.py | 7 +- tests/conftest.py | 1 + tests/test_auc_by_group_table.py | 1 + tests/test_calculate_performance_metrics.py | 28 +++---- tests/test_performance_by_threshold.py | 18 +++-- tests/test_sens_over_time.py | 36 ++++----- tests/test_train_model.py | 1 + tests/test_utils.py | 2 + tests/test_visualizations.py | 5 ++ tests/utils_for_testing.py | 25 +++++- 31 files changed, 259 insertions(+), 163 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 02e37842..6d75ff71 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -14,9 +14,10 @@ repos: - id: add-trailing-comma - repo: https://github.com/asottile/pyupgrade - rev: v2.37.3 + rev: v3.0.0 hooks: - id: pyupgrade + args: ["--py39-plus"] - repo: https://github.com/myint/docformatter rev: v1.5.0 diff --git a/docs/conf.py b/docs/conf.py index 7d96a078..b420ec84 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# pylint: disable-all # # psycop-t2d documentation build configuration file, created by # sphinx-quickstart. diff --git a/pyproject.toml b/pyproject.toml index 4a0b119c..c135d610 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -62,12 +62,18 @@ exclude_lines = [ "if __name__ == .__main__.:", ] -[tool.isort] -known_third_party = ["wandb"] - [tool.mypy] ignore_missing_imports = true +[tool.pylint] +load-plugins = "pylint.extensions.docparams,pylint.extensions.code_style,pylint.extensions.for_any_all,pylint.extensions.typing" +good-names = "df,p,f,d,e,n,k,i,v,y_,X,y" +disable = "too-many-lines,line-too-long,missing-raises-doc,no-self-argument,unused-wildcard-import,wildcard-import,no-else-return,too-many-arguments,redefined-outer-name,c-extension-no-member,wrong-import-order,import-outside-toplevel" +extension-pkg-allow-list = "wandb" + +[tool.isort] +known_third_party = ["wandb"] + [tool.semantic_release] branch = "main" version_variable = [ diff --git a/reports/render_report.py b/reports/render_report.py index 1c784fb8..77885ea3 100644 --- a/reports/render_report.py +++ b/reports/render_report.py @@ -6,14 +6,13 @@ be in a dir called 'tables' and figures in a dir called 'figs' """ -from typing import list import pandas as pd from psycopt2d.utils import PROJECT_ROOT # import pandoc -# See comment in pyproject.toml on Pandoc, not currently in use. import pandoc +# See comment in pyproject.toml on Pandoc, not currently in use. Should work now, see: https://github.com/boisgera/pandoc/pull/49#issuecomment-1265983279 AUTHORS = ["Lasse Hansen", "MB", "KCE"] TITLE = "Paradigm Shattering Paper 1" @@ -25,6 +24,7 @@ def insert_figure(line: str, fig_number: int): + """Add a figure to the report as md.""" path, caption = line.split(":") path = path.strip().replace("{", "") caption = caption.strip().replace("}", "") @@ -34,35 +34,40 @@ def insert_figure(line: str, fig_number: int): def insert_table(line: str, table_number: int): + """Add a table to the report as md.""" path, caption = line.split(":") path = path.strip().replace("{", "") caption = caption.strip().replace("}", "") - md_table = load_table(path) + md_table = csv_to_md(path) table = f"_Table {table_number}: {caption}_\n\n{md_table}\n" return table -def load_table(filepath: str): +def csv_to_md(filepath: str): + """Load a table from a csv and return as markdown.""" df = pd.read_csv(filepath) return df.to_markdown() def center_text(text: list[str]): + """Add html center align tags.""" return "\n" + f"""
{_join_by_newline(text)}
""" def _join_by_newline(text: list[str]): + """Join a list of strings by newline.""" return "\n\n".join(text) if __name__ == "__main__": - with open(REPORT_PATH / "report.md", "r") as f: + with open(REPORT_PATH / "report.md") as f: # pylint: disable=unspecified-encoding report = f.readlines() - md = [] - fig_counter = 1 - table_counter = 1 + mdown_in_process = [] + FIG_COUNT = 1 + TABLE_COUNT = 1 + for line in report: if "@title" in line: line = line.replace("@title", TITLE) @@ -70,16 +75,19 @@ def _join_by_newline(text: list[str]): line = line.replace("@authors", center_text(AUTHORS)) elif line.startswith("{"): if "figs" in line: - line = insert_figure(line, fig_number=fig_counter) - fig_counter += 1 + line = insert_figure(line, fig_number=FIG_COUNT) + FIG_COUNT += 1 if "tables" in line: - line = insert_table(line, table_number=table_counter) - table_counter += 1 - md.append(line) + line = insert_table(line, table_number=TABLE_COUNT) + TABLE_COUNT += 1 + mdown_in_process.append(line) - md = "".join(md) + MDOWN_OUT = "".join(mdown_in_process) # pandoc_format = pandoc.read(md) # pandoc.write(pandoc_format, file=str(REPORT_PATH / "auto_report.docx")) - with open(REPORT_PATH / "auto_report.md", "w") as f: - f.write(md) + with open( # pylint: disable=unspecified-encoding + REPORT_PATH / "auto_report.md", + "w", + ) as f: + f.write(MDOWN_OUT) diff --git a/src/psycopt2d/about.py b/src/psycopt2d/about.py index a316d8fc..99a76d8f 100644 --- a/src/psycopt2d/about.py +++ b/src/psycopt2d/about.py @@ -1,3 +1,4 @@ +# pylint: disable-all import pkg_resources __version__ = pkg_resources.get_distribution("psycop-t2d").version diff --git a/src/psycopt2d/data/generate_synthetic_dataset_for_eval.py b/src/psycopt2d/data/generate_synthetic_dataset_for_eval.py index d7f4ea09..2f199b6d 100644 --- a/src/psycopt2d/data/generate_synthetic_dataset_for_eval.py +++ b/src/psycopt2d/data/generate_synthetic_dataset_for_eval.py @@ -1,3 +1,4 @@ +"""Generate synthetic data for evaluation of the model.""" import datetime as dt from typing import Any, Optional @@ -18,7 +19,8 @@ def years_to_seconds(years): return years * 365 * 24 * 60 * 60 -def return_0_with_prob(prob): +def return_0_with_prob(prob: float): + """Return 0 with a given probability.""" return 0 if np.random.random() < prob else 1 @@ -72,14 +74,14 @@ def overwrite_prop_with_null( if __name__ == "__main__": msg = Printer(timestamp=True) base = pd.Timestamp.today() - n_rows = 100_000 + N_ROWS = 100_000 df = pd.DataFrame() - df["dw_ek_borger"] = [np.random.randint(0, 100_000) for n in range(n_rows)] + df["dw_ek_borger"] = [np.random.randint(0, 100_000) for _ in range(N_ROWS)] # Generate timestamps - df["timestamp"] = [base] * n_rows + df["timestamp"] = [base] * N_ROWS msg.info("Adding differences") df["time_differences"] = [ @@ -89,12 +91,12 @@ def overwrite_prop_with_null( years_to_seconds(years=10), ), ) - for n in range(n_rows) + for _ in range(N_ROWS) ] df["timestamp"] = df["timestamp"] + df["time_differences"] df.drop("time_differences", axis=1, inplace=True) - df["pred_prob"] = [(np.random.random() - 0.45) for n in range(n_rows)] + df["pred_prob"] = [(np.random.random() - 0.45) for _ in range(N_ROWS)] df["pred_prob"] = df["pred_prob"].clip(0, 1) df["pred"] = df["pred_prob"].clip(0, 1).round() diff --git a/src/psycopt2d/evaluate_saved_model_predictions.py b/src/psycopt2d/evaluate_saved_model_predictions.py index 5fae4c72..0505ff86 100644 --- a/src/psycopt2d/evaluate_saved_model_predictions.py +++ b/src/psycopt2d/evaluate_saved_model_predictions.py @@ -9,26 +9,27 @@ from pathlib import Path import pandas as pd -from omegaconf.dictconfig import dictConfig +from omegaconf.dictconfig import DictConfig from psycopt2d.utils import PROJECT_ROOT, read_pickle from psycopt2d.visualization import plot_auc_by_time_from_first_visit -def infer_outcome_col_name(df: pd.DataFrame): - outcome_name = [c for c in df.columns if c.startswith("outc")] +def infer_outcome_col_name(df: pd.DataFrame, prefix: str = "outc_") -> str: + """Infer the outcome column name from the dataframe.""" + outcome_name = [c for c in df.columns if c.startswith(prefix)] if len(outcome_name) == 1: return outcome_name[0] else: raise ValueError("More than one outcome inferred") -def infer_predictor_col_names(df: pd.DataFrame, cfg: dictConfig) -> list[str]: +def infer_predictor_col_names(df: pd.DataFrame, cfg: DictConfig) -> list[str]: """Get the predictors that are used in the model. Args: df (pd.Dataframe): Dataframe with model predictions - cfg (dictConfig): Config file + cfg (DictConfig): Config file Returns: list[str]: list of predictors @@ -36,7 +37,7 @@ def infer_predictor_col_names(df: pd.DataFrame, cfg: dictConfig) -> list[str]: return [c for c in df.columns if c.startswith(cfg.data.pred_col_name_prefix)] -def load_model_predictions_and_cfg(path: Path) -> tuple[pd.DataFrame, dictConfig]: +def load_model_predictions_and_cfg(path: Path) -> tuple[pd.DataFrame, DictConfig]: """Load model predictions and config file from a pickle file. Args: @@ -57,7 +58,9 @@ def load_model_predictions_and_cfg(path: Path) -> tuple[pd.DataFrame, dictConfig train_col_names = infer_predictor_col_names(eval_df, cfg) y_col_name = infer_outcome_col_name(eval_df) - y_hat_prob_col_name = "y_hat_prob" # change to 'y_hat_prob_oof' if using cv + + Y_HAT_PROB_COL_NAME = "y_hat_prob" # change to 'y_hat_prob_oof' if using cv + first_visit_timestamp = eval_df.groupby(cfg.data.id_col_name)[ cfg.data.pred_timestamp_col_name ].transform("min") @@ -65,7 +68,7 @@ def load_model_predictions_and_cfg(path: Path) -> tuple[pd.DataFrame, dictConfig # Do whatever extra evaluation you want to here p = plot_auc_by_time_from_first_visit( labels=eval_df[y_col_name], - y_hat_probs=eval_df[y_hat_prob_col_name], + y_hat_probs=eval_df[Y_HAT_PROB_COL_NAME], first_visit_timestamps=first_visit_timestamp, prediction_timestamps=eval_df[cfg.data.pred_timestamp_col_name], ) diff --git a/src/psycopt2d/evaluation.py b/src/psycopt2d/evaluation.py index f3505ecb..6640087d 100644 --- a/src/psycopt2d/evaluation.py +++ b/src/psycopt2d/evaluation.py @@ -6,7 +6,7 @@ import pandas as pd from sklearn.metrics import f1_score, roc_auc_score from sklearn.pipeline import Pipeline -from wandb.sdk.wandb_run import Run as wandb_run +from wandb.sdk.wandb_run import Run as wandb_run # pylint: disable=no-name-in-module from psycopt2d.tables import generate_feature_importances_table from psycopt2d.tables.performance_by_threshold import ( diff --git a/src/psycopt2d/feature_transformers.py b/src/psycopt2d/feature_transformers.py index bf318af5..5886d6dd 100644 --- a/src/psycopt2d/feature_transformers.py +++ b/src/psycopt2d/feature_transformers.py @@ -1,24 +1,26 @@ """Custom transformers for data preprocessing.""" from datetime import datetime -from typing import Optional, list +from typing import Optional from sklearn.base import BaseEstimator, TransformerMixin +# pylint: disable=missing-function-docstring + class ConvertToBoolean(BaseEstimator, TransformerMixin): """Convert all cells with a value to True, otherwise false.""" def __init__( self, - columns_to_include: Optional[list[str]] = None, - columns_to_skip: Optional[list[str]] = ["age_in_years", "sex_female"], - ignore_dtypes: Optional[set] = {"datetime64[ns]", " None: """ Args: columns_to_include (list[str], optional): Columns to convert to boolean. Acts as a whitelist, skipping all columns not in the list. - columns_to_skip (list[str], optional): Columns to not convert to boolean. + columns_to_skip (Union(tuple[str], None) : Columns to not convert to boolean. Acts as a blacklist. Defaults to ["age_in_years", "male"]. Default to None in which case all columns are included. @@ -27,12 +29,12 @@ def __init__( """ self.columns_to_skip = columns_to_skip self.columns_to_include = columns_to_include - self.ignore_dtypes = ignore_dtypes + self.ignore_dtypes = set(ignore_dtypes) if ignore_dtypes else None - def fit(self, X, y=None): + def fit(self, _, y=None): # pylint: disable=unused-argument return self - def transform(self, X, y=None): + def transform(self, X, y=None): # pylint: disable=unused-argument columns = X.columns if self.columns_to_include: @@ -41,7 +43,7 @@ def transform(self, X, y=None): cols_to_round = [ c for c in columns - if (X[c].dtype not in self.ignore_dtype) or c in self.columns_to_skip + if (X[c].dtype not in self.ignore_dtypes) or c in self.columns_to_skip ] for col in cols_to_round: @@ -51,6 +53,8 @@ def transform(self, X, y=None): class DateTimeConverter(BaseEstimator, TransformerMixin): + """Convert datetime columns to integers.""" + valid_types = {"ordinal"} datetime_dtypes = {"datetime64[ns]", " pd.DataFrame: """Load dataset from directory. Finds any .csv with the split name in its @@ -136,7 +137,7 @@ def load_dataset_from_dir( Args: split_name (str): Name of split, allowed are ["train", "test", "val"] - dir (Path): Directory of the dataset. + dir_path (Path): Directory of the dataset. nrows (Optional[int]): Number of rows to load. Defaults to None, in which case all rows are loaded. @@ -144,6 +145,6 @@ def load_dataset_from_dir( pd.DataFrame: The dataset """ # Use glob to find the file - path = list(dir.glob(f"*{split_name}*.csv"))[0] + path = list(dir_path.glob(f"*{split_name}*.csv"))[0] return pd.read_csv(filepath_or_buffer=path, nrows=nrows) diff --git a/src/psycopt2d/models.py b/src/psycopt2d/models.py index b54af345..a5a7868e 100644 --- a/src/psycopt2d/models.py +++ b/src/psycopt2d/models.py @@ -1,3 +1,4 @@ +"""Specifications of models to be evaluated.""" import numpy as np # from interpret.glassbox import ExplainableBoostingClassifier @@ -6,13 +7,14 @@ from xgboost import XGBClassifier -def InitLogisticRegression(**kwargs): +def init_logistic_regression(**kwargs): + """Initialize LogisticRegression model.""" if "penalty_solver" in kwargs: kwargs["penalty"], kwargs["solver"] = kwargs.pop("penalty_solver").split("_") return LogisticRegression(**kwargs) -logistic = {"model": InitLogisticRegression, "static_hyperparameters": {}} +logistic = {"model": init_logistic_regression, "static_hyperparameters": {}} xgboost = {"model": XGBClassifier, "static_hyperparameters": {"missing": np.nan}} nb = {"model": GaussianNB, "static_hyperparameters": {}} diff --git a/src/psycopt2d/synth_data_generator/synth_data_generator.py b/src/psycopt2d/synth_data_generator/synth_data_generator.py index ae42ac45..defac04d 100644 --- a/src/psycopt2d/synth_data_generator/synth_data_generator.py +++ b/src/psycopt2d/synth_data_generator/synth_data_generator.py @@ -1,4 +1,10 @@ -# TODO: Refactor this to use only be an application of module in psycop-ml-utils instead. +"""Refactor this to be an application of the module in psycop-ml-utils. + +Generator of synthetic data. +""" + +# pylint: disable=too-many-locals,invalid-name,missing-function-docstring + from pathlib import Path from typing import Optional, Union @@ -12,11 +18,11 @@ def generate_synth_data( outcome_column_name: str, n_samples: int, logistic_outcome_model: str, - intercept: Optional[Union[int, float, complex, str, bytes]] = 0, - na_prob: Optional[float] = 0.01, - na_ignore_cols: list[str] = [], - prob_outcome: Optional[float] = 0.08, - noise_mean_sd: Optional[tuple[float, float]] = (0, 1), + intercept: Union[int, float, complex, str, bytes] = 0, + na_prob: float = 0.01, + na_ignore_cols: Optional[tuple[str]] = None, + prob_outcome: float = 0.08, + noise_mean_sd: tuple[float, float] = (0, 1), ) -> pd.DataFrame: """Takes a dict and generates synth data from it. @@ -72,8 +78,9 @@ def generate_synth_data( df_ = df.mask(mask) # ignore nan values for non-nan columns. - for col in na_ignore_cols: - df_[col] = df[col] + if na_ignore_cols: + for col in na_ignore_cols: + df_[col] = df[col] # Sigmoid it to get probabilities with mean = 0.5 df[outcome_column_name] = 1 / (1 + np.exp(y_)) diff --git a/src/psycopt2d/tables/performance_by_threshold.py b/src/psycopt2d/tables/performance_by_threshold.py index 1f3cca26..30e4d51f 100644 --- a/src/psycopt2d/tables/performance_by_threshold.py +++ b/src/psycopt2d/tables/performance_by_threshold.py @@ -1,4 +1,6 @@ -from typing import Iterable, Optional, Union +"""Get performance by which threshold is used to classify positive.""" +from collections.abc import Iterable +from typing import Optional, Union import numpy as np import pandas as pd @@ -7,8 +9,8 @@ def generate_performance_by_positive_rate_table( - labels: Iterable[Union[int, float]], - pred_probs: Iterable[Union[int, float]], + labels: Iterable[int], + pred_probs: Iterable[float], positive_rate_thresholds: Iterable[Union[int, float]], pred_proba_thresholds: Iterable[float], ids: Iterable[Union[int, float]], @@ -20,8 +22,8 @@ def generate_performance_by_positive_rate_table( object. Args: - labels (Iterable[int, float]): True labels. - pred_probs (Iterable[int, float]): Predicted probabilities. + labels (Iterable[int]): True labels. + pred_probs (Iterable[float]): Predicted probabilities. positive_rate_thresholds (Iterable[float]): Positive_rate_thresholds to add to the table, e.g. 0.99, 0.98 etc. Calculated so that the Xth percentile of predictions are classified as the positive class. pred_proba_thresholds (Iterable[float]): Thresholds above which predictions are classified as positive. @@ -48,7 +50,9 @@ def generate_performance_by_positive_rate_table( positive_threshold=threshold_value, ) - threshold_metrics["total_warning_days"] = days_from_first_positive_to_diagnosis( + threshold_metrics[ # pylint: disable=unsupported-assignment-operation + "total_warning_days" + ] = days_from_first_positive_to_diagnosis( ids=ids, pred_probs=pred_probs, pred_timestamps=pred_timestamps, @@ -57,7 +61,9 @@ def generate_performance_by_positive_rate_table( aggregation_method="sum", ) - threshold_metrics["mean_warning_days"] = round( + threshold_metrics[ # pylint: disable=unsupported-assignment-operation + "mean_warning_days" + ] = round( days_from_first_positive_to_diagnosis( ids=ids, pred_probs=pred_probs, @@ -87,7 +93,7 @@ def generate_performance_by_positive_rate_table( raise ValueError("Output format does not match anything that is allowed") -def performance_by_threshold( +def performance_by_threshold( # pylint: disable=too-many-locals labels: Iterable[int], pred_probs: Iterable[float], positive_threshold: float, @@ -107,30 +113,30 @@ def performance_by_threshold( """ preds = np.where(pred_probs > positive_threshold, 1, 0) - CM = confusion_matrix(labels, preds) + conf_matrix = confusion_matrix(labels, preds) - TN = CM[0][0] - FN = CM[1][0] - TP = CM[1][1] - FP = CM[0][1] + true_neg = conf_matrix[0][0] + false_neg = conf_matrix[1][0] + true_pos = conf_matrix[1][1] + false_pos = conf_matrix[0][1] - n_total = TN + FN + TP + FP + n_total = true_neg + false_neg + true_pos + false_pos - true_prevalence = round((TP + FN) / n_total, round_to) + true_prevalence = round((true_pos + false_neg) / n_total, round_to) - positive_rate = round((TP + FP) / n_total, round_to) - negative_rate = round((TN + FN) / n_total, round_to) + positive_rate = round((true_pos + false_pos) / n_total, round_to) + negative_rate = round((true_neg + false_neg) / n_total, round_to) - PPV = round(TP / (TP + FP), round_to) - NPV = round(TN / (TN + FN), round_to) + pos_pred_val = round(true_pos / (true_pos + false_pos), round_to) + neg_pred_val = round(true_neg / (true_neg + false_neg), round_to) - Sensitivity = round(TP / (TP + FN), round_to) - Specificity = round(TN / (TN + FP), round_to) + sens = round(true_pos / (true_pos + false_neg), round_to) + spec = round(true_neg / (true_neg + false_pos), round_to) - FPR = round(FP / (TN + FP), round_to) - FNR = round(FN / (TP + FN), round_to) + false_pos_rate = round(false_pos / (true_neg + false_pos), round_to) + neg_pos_rate = round(false_neg / (true_pos + false_neg), round_to) - Accuracy = round((TP + TN) / n_total, round_to) + acc = round((true_pos + true_neg) / n_total, round_to) # Must return lists as values, otherwise pd.Dataframe requires setting indeces metrics_matrix = pd.DataFrame( @@ -138,17 +144,17 @@ def performance_by_threshold( "positive_rate": [positive_rate], "negative_rate": [negative_rate], "true_prevalence": [true_prevalence], - "PPV": [PPV], - "NPV": [NPV], - "sensitivity": [Sensitivity], - "specificity": [Specificity], - "FPR": [FPR], - "FNR": [FNR], - "accuracy": [Accuracy], - "true_positives": [TP], - "true_negatives": [TN], - "false_positives": [FP], - "false_negatives": [FN], + "PPV": [pos_pred_val], + "NPV": [neg_pred_val], + "sensitivity": [sens], + "specificity": [spec], + "FPR": [false_pos_rate], + "FNR": [neg_pos_rate], + "accuracy": [acc], + "true_positives": [true_pos], + "true_negatives": [true_neg], + "false_positives": [false_pos], + "false_negatives": [false_neg], }, ) diff --git a/src/psycopt2d/train_model.py b/src/psycopt2d/train_model.py index d60bb630..1feea6ae 100644 --- a/src/psycopt2d/train_model.py +++ b/src/psycopt2d/train_model.py @@ -77,14 +77,14 @@ def load_dataset_from_config(cfg) -> tuple[pd.DataFrame, pd.DataFrame]: train = load_dataset( split_names="train", - dir=path, + dir_path=path, n_training_samples=cfg.data.n_training_samples, drop_patient_if_outcome_before_date=cfg.data.drop_patient_if_outcome_before_date, min_lookahead_days=cfg.data.min_lookahead_days, ) val = load_dataset( split_names="val", - dir=path, + dir_path=path, n_training_samples=cfg.data.n_training_samples, drop_patient_if_outcome_before_date=cfg.data.drop_patient_if_outcome_before_date, min_lookahead_days=cfg.data.min_lookahead_days, @@ -200,7 +200,7 @@ def main(cfg): print( f"Performance on train: {round(roc_auc_score(y_train, y_train_hat_prob), 3)}", - ) # TODO log to wandb + ) # ? log to wandb eval_dataset = val eval_dataset["y_hat_prob"] = y_val_hat_prob diff --git a/src/psycopt2d/utils.py b/src/psycopt2d/utils.py index eb6601f2..dfbe6a62 100644 --- a/src/psycopt2d/utils.py +++ b/src/psycopt2d/utils.py @@ -1,12 +1,16 @@ +"""Misc. + +utilities. +""" import time -from collections.abc import MutableMapping +from collections.abc import Iterable, MutableMapping from pathlib import Path -from typing import Any, Iterable, Union, dict, list +from typing import Any, Union import dill as pkl import numpy as np import pandas as pd -from omegaconf.dictconfig import dictConfig +from omegaconf.dictconfig import DictConfig from wasabi import msg from psycopt2d.model_performance import ModelPerformance @@ -183,13 +187,13 @@ def bin_continuous_data(series: pd.Series, bins: list[int]) -> pd.Series: 8 51+ """ labels = [] - for i, bin in enumerate(bins): + for i, bin_v in enumerate(bins): if i == 0: - labels.append(f"{bin}-{bins[i+1]}") + labels.append(f"{bin_v}-{bins[i+1]}") elif i < len(bins) - 2: - labels.append(f"{bin+1}-{bins[i+1]}") + labels.append(f"{bin_v+1}-{bins[i+1]}") elif i == len(bins) - 2: - labels.append(f"{bin+1}+") + labels.append(f"{bin_v+1}+") else: continue @@ -247,13 +251,13 @@ def read_pickle(path: str) -> Any: return pkl.load(f) -def prediction_df_with_metadata_to_disk(df: pd.DataFrame, cfg: dictConfig) -> None: +def prediction_df_with_metadata_to_disk(df: pd.DataFrame, cfg: DictConfig) -> None: """Saves prediction dataframe with and hydra config to disk. Stored as a dict with keys "df" and "cfg". Args: df (pd.DataFrame): Dataframe to save. - cfg (dictConfig): Hydra config. + cfg (DictConfig): Hydra config. """ model_args = format_dict_for_printing(cfg.model) diff --git a/src/psycopt2d/visualization/__init__.py b/src/psycopt2d/visualization/__init__.py index 69378691..d9d6b419 100644 --- a/src/psycopt2d/visualization/__init__.py +++ b/src/psycopt2d/visualization/__init__.py @@ -1,3 +1,4 @@ +"""Visualisations.""" from .feature_importance import plot_feature_importances from .performance_over_time import ( plot_auc_by_time_from_first_visit, diff --git a/src/psycopt2d/visualization/altair_utils.py b/src/psycopt2d/visualization/altair_utils.py index b99e7245..539f985b 100644 --- a/src/psycopt2d/visualization/altair_utils.py +++ b/src/psycopt2d/visualization/altair_utils.py @@ -1,3 +1,4 @@ +# pylint: skip-file from pathlib import Path from typing import Union diff --git a/src/psycopt2d/visualization/base_charts.py b/src/psycopt2d/visualization/base_charts.py index a9ed10d4..47adbccd 100644 --- a/src/psycopt2d/visualization/base_charts.py +++ b/src/psycopt2d/visualization/base_charts.py @@ -1,4 +1,6 @@ -from typing import Iterable, Optional +"""Base charts.""" +from collections.abc import Iterable +from typing import Optional import altair as alt import pandas as pd diff --git a/src/psycopt2d/visualization/feature_importance.py b/src/psycopt2d/visualization/feature_importance.py index 70ea625e..99156d66 100644 --- a/src/psycopt2d/visualization/feature_importance.py +++ b/src/psycopt2d/visualization/feature_importance.py @@ -1,4 +1,7 @@ -from typing import Iterable, Union, list +"""Generate feature importances chart.""" + +from collections.abc import Iterable +from typing import Union import altair as alt import numpy as np diff --git a/src/psycopt2d/visualization/performance_over_time.py b/src/psycopt2d/visualization/performance_over_time.py index 16a3cbc2..89e4b060 100644 --- a/src/psycopt2d/visualization/performance_over_time.py +++ b/src/psycopt2d/visualization/performance_over_time.py @@ -3,7 +3,8 @@ 2. AUC by time from first visit 3. AUC by time until diagnosis """ -from typing import Callable, Iterable, Optional, list +from collections.abc import Callable, Iterable +from typing import Optional import altair as alt import numpy as np @@ -27,7 +28,7 @@ def _calc_performance(df: pd.DataFrame, metric: Callable) -> float: """ if df.empty: return np.nan - elif metric == roc_auc_score and len(df["y"].unique()) == 1: + elif metric is roc_auc_score and len(df["y"].unique()) == 1: msg.info("Only 1 class present in bin. AUC undefined. Returning np.nan") return np.nan else: @@ -105,7 +106,7 @@ def create_performance_by_time_from_event_df( prediction_timestamps: Iterable[pd.Timestamp], metric_fn: Callable, direction: str, - bins: list[int], + bins: Iterable[float], pretty_bins: Optional[bool] = True, drop_na_events: Optional[bool] = True, ) -> pd.DataFrame: @@ -120,7 +121,7 @@ def create_performance_by_time_from_event_df( metric_fn (Callable): Which performance metric function to use (e.g. roc_auc_score) direction (str): Which direction to calculate time difference. Can either be 'prediction-event' or 'event-prediction'. - bins (list): Bins to group by. + bins (Iterable[float]): Bins to group by. pretty_bins (bool, optional): Whether to prettify bin names. I.e. make bins look like "1-7" instead of "[1-7)". Defaults to True. drop_na_events (bool, optional): Whether to drop rows where the event is NA. Defaults to True. @@ -172,7 +173,7 @@ def plot_auc_by_time_from_first_visit( y_hat_probs: Iterable[int], first_visit_timestamps: Iterable[pd.Timestamp], prediction_timestamps: Iterable[pd.Timestamp], - bins=[0, 28, 182, 365, 730, 1825], + bins: tuple = (0, 28, 182, 365, 730, 1825), pretty_bins: Optional[bool] = True, ) -> alt.Chart: """Plot AUC as a function of time to first visit. @@ -217,7 +218,7 @@ def plot_metric_by_time_until_diagnosis( y_hat: Iterable[int], diagnosis_timestamps: Iterable[pd.Timestamp], prediction_timestamps: Iterable[pd.Timestamp], - bins=[ + bins: Iterable[int] = ( -1825, -730, -365, @@ -230,7 +231,7 @@ def plot_metric_by_time_until_diagnosis( 365, 730, 1825, - ], + ), pretty_bins: Optional[bool] = True, metric_fn: Callable = f1_score, y_title: str = "F1", diff --git a/src/psycopt2d/visualization/prob_over_time.py b/src/psycopt2d/visualization/prob_over_time.py index 0f69e487..7481a497 100644 --- a/src/psycopt2d/visualization/prob_over_time.py +++ b/src/psycopt2d/visualization/prob_over_time.py @@ -1,7 +1,8 @@ """Code for creating probabilities over time plots.""" +from collections.abc import Iterable from datetime import datetime -from typing import Iterable, Optional, Union +from typing import Optional, Union import altair as alt import pandas as pd diff --git a/src/psycopt2d/visualization/sens_over_time.py b/src/psycopt2d/visualization/sens_over_time.py index b5623b3e..4b5f5895 100644 --- a/src/psycopt2d/visualization/sens_over_time.py +++ b/src/psycopt2d/visualization/sens_over_time.py @@ -1,5 +1,6 @@ +"""Generate a plot of sensitivity by time to outcome.""" +from collections.abc import Iterable from functools import partial -from typing import Iterable, list import altair as alt import numpy as np @@ -14,7 +15,7 @@ def create_sensitivity_by_time_to_outcome_df( pred_proba_threshold: float, outcome_timestamps: Iterable[pd.Timestamp], prediction_timestamps: Iterable[pd.Timestamp], - bins=[0, 1, 7, 14, 28, 182, 365, 730, 1825], + bins: Iterable = (0, 1, 7, 14, 28, 182, 365, 730, 1825), ) -> pd.DataFrame: """Calculate sensitivity by time to outcome. @@ -99,7 +100,7 @@ def plot_sensitivity_by_time_to_outcome( pred_proba_thresholds: list[float], outcome_timestamps: Iterable[pd.Timestamp], prediction_timestamps: Iterable[pd.Timestamp], - bins: list[int] = [0, 28, 182, 365, 730, 1825], + bins: Iterable[int] = (0, 28, 182, 365, 730, 1825), ): """Plot sensitivity by time to outcome. diff --git a/tests/conftest.py b/tests/conftest.py index cb836b2d..169b8907 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -8,6 +8,7 @@ @pytest.fixture def synth_data(): + """Synthetic data.""" df = pd.read_csv(Path("tests") / "test_data" / "synth_eval_data.csv") df = add_age_gender(df) return df diff --git a/tests/test_auc_by_group_table.py b/tests/test_auc_by_group_table.py index 0cccd349..b4103307 100644 --- a/tests/test_auc_by_group_table.py +++ b/tests/test_auc_by_group_table.py @@ -1,4 +1,5 @@ """table_test_auc_by_group_table.""" +# pylint: disable=missing-function-docstring from psycopt2d.tables import auc_by_group_table from psycopt2d.utils import bin_continuous_data diff --git a/tests/test_calculate_performance_metrics.py b/tests/test_calculate_performance_metrics.py index 50be5f79..db630a4f 100644 --- a/tests/test_calculate_performance_metrics.py +++ b/tests/test_calculate_performance_metrics.py @@ -2,17 +2,17 @@ # from psycopt2d.utils import calculate_performance_metrics -def test_log_performance_metrics(synth_data): - pass - # # wandb.init(project="test") - # perf = calculate_performance_metrics( - # synth_data, - # outcome_col_name="label", - # prediction_probabilities_col_name="pred_prob", - # id_col_name="dw_ek_borger", - # ) - # # stupid test - is actested in psycop-ml-utils - # # mainly used to test wandb but doesn't work GH actions - # assert type(perf) == dict - # # wandb.log(perf) - # # wandb.finish() +# def test_log_performance_metrics(synth_data): +# pass +# # wandb.init(project="test") +# perf = calculate_performance_metrics( +# synth_data, +# outcome_col_name="label", +# prediction_probabilities_col_name="pred_prob", +# id_col_name="dw_ek_borger", +# ) +# # stupid test - is actested in psycop-ml-utils +# # mainly used to test wandb but doesn't work GH actions +# assert type(perf) == dict +# # wandb.log(perf) +# # wandb.finish() diff --git a/tests/test_performance_by_threshold.py b/tests/test_performance_by_threshold.py index 111c2528..6d3b0630 100644 --- a/tests/test_performance_by_threshold.py +++ b/tests/test_performance_by_threshold.py @@ -1,3 +1,10 @@ +"""Generate performance by positive threshold. + +E.g. if predicted probability is .4, and threshold is .5, resolve to 0. +""" + +# pylint: disable=missing-function-docstring + from pathlib import Path import pandas as pd @@ -12,6 +19,7 @@ @pytest.fixture(scope="function") def synth_data(): + """Load synthetic data.""" csv_path = Path("tests") / "test_data" / "synth_eval_data.csv" df = pd.read_csv(csv_path) @@ -32,7 +40,7 @@ def test_generate_performance_by_threshold_table(synth_data): positive_rate_thresholds=positive_rate_thresholds, ) - t = generate_performance_by_positive_rate_table( + table = generate_performance_by_positive_rate_table( labels=df["label"], pred_probs=df["pred_prob"], ids=df["dw_ek_borger"], @@ -66,8 +74,8 @@ def test_generate_performance_by_threshold_table(synth_data): }, ) - for col in t.columns: - t[col].equals(expected_df[col]) + for col in table.columns: + table[col].equals(expected_df[col]) def test_time_from_flag_to_diag(synth_data): @@ -82,7 +90,7 @@ def test_time_from_flag_to_diag(synth_data): positive_rate_threshold=0.5, ) - assert val > 290_000 and val < 292_000 + assert 290_000 < val < 292_000 # Threshold = 0.2 val = days_from_first_positive_to_diagnosis( @@ -93,4 +101,4 @@ def test_time_from_flag_to_diag(synth_data): positive_rate_threshold=0.2, ) - assert val > 1_875_000 and val < 1_885_000 + assert 1_875_000 < val < 1_885_000 diff --git a/tests/test_sens_over_time.py b/tests/test_sens_over_time.py index 34761406..5ae3ede6 100644 --- a/tests/test_sens_over_time.py +++ b/tests/test_sens_over_time.py @@ -1,3 +1,5 @@ +"""Tests of sens over time.""" +# pylint: disable=missing-function-docstring from pathlib import Path import pandas as pd @@ -20,24 +22,24 @@ def df(): return df -def test_plot_sensitivity_by_time_to_outcome(df): - # Disabled because of errors with altair. We're migrating away, re-enable when we're done. +# def test_plot_sensitivity_by_time_to_outcome(df): +# Disabled because of errors with altair. We're migrating away, re-enable when we're done. - # positive_rates = [0.95, 0.99, 0.999, 0.9999] +# positive_rates = [0.95, 0.99, 0.999, 0.9999] - # pred_proba_thresholds = positive_rate_to_pred_probs( - # pred_probs=df["pred_prob"], - # positive_rate_thresholds=positive_rates, - # ) +# pred_proba_thresholds = positive_rate_to_pred_probs( +# pred_probs=df["pred_prob"], +# positive_rate_thresholds=positive_rates, +# ) - # plt = plot_sensitivity_by_time_to_outcome( - # labels=df["label"], - # y_hat_probs=df["pred_prob"], - # pred_proba_thresholds=pred_proba_thresholds, - # outcome_timestamps=df["timestamp_t2d_diag"], - # prediction_timestamps=df["timestamp"], - # bins=[0, 28, 182, 365, 730, 1825], - # ) +# plt = plot_sensitivity_by_time_to_outcome( +# labels=df["label"], +# y_hat_probs=df["pred_prob"], +# pred_proba_thresholds=pred_proba_thresholds, +# outcome_timestamps=df["timestamp_t2d_diag"], +# prediction_timestamps=df["timestamp"], +# bins=[0, 28, 182, 365, 730, 1825], +# ) - # plt.save("test_plot_sensitivity_by_time_to_outcome.png") - pass +# plt.save("test_plot_sensitivity_by_time_to_outcome.png") +# pass diff --git a/tests/test_train_model.py b/tests/test_train_model.py index 14a8fbe8..f30cc85f 100644 --- a/tests/test_train_model.py +++ b/tests/test_train_model.py @@ -1,3 +1,4 @@ +"""Test that the model trains correctly.""" import platform import pytest diff --git a/tests/test_utils.py b/tests/test_utils.py index 29fa10ed..b3ddf1fe 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,3 +1,5 @@ +"""Testing of the utils module.""" +# pylint: disable=missing-function-docstring import numpy as np import pandas as pd from utils_for_testing import str_to_df diff --git a/tests/test_visualizations.py b/tests/test_visualizations.py index 95abef3c..10ebd6a8 100644 --- a/tests/test_visualizations.py +++ b/tests/test_visualizations.py @@ -1,3 +1,8 @@ +"""Tests for all our visualisations. + +Mainly tests that they run without errors. +""" +# pylint: disable=missing-function-docstring from pathlib import Path import altair as alt diff --git a/tests/utils_for_testing.py b/tests/utils_for_testing.py index 6768dcad..dc75446a 100644 --- a/tests/utils_for_testing.py +++ b/tests/utils_for_testing.py @@ -1,11 +1,26 @@ +"""Misc. + +utils for testing. +""" import numpy as np import pandas as pd -def str_to_df(str, convert_timestamp_to_datetime: bool = True) -> pd.DataFrame: +def str_to_df(string, convert_timestamp_to_datetime: bool = True) -> pd.DataFrame: + """Convert a string to a dataframe. + + Args: + string (str): String to convert to a dataframe. String should be a csv. + convert_timestamp_to_datetime (bool, optional): Whether to convert + timestamp columns to datetime. Defaults to True. + + Returns: + pd.DataFrame: The dataframe + """ + from io import StringIO - df = pd.read_table(StringIO(str), sep=",", index_col=False) + df = pd.read_table(StringIO(string), sep=",", index_col=False) if convert_timestamp_to_datetime: df = convert_cols_with_matching_colnames_to_datetime(df, "timestamp") @@ -36,6 +51,12 @@ def convert_cols_with_matching_colnames_to_datetime( def add_age_gender(df): + """Add age and gender columns to dataframe. + + Args: + df (pd.DataFrame): The dataframe to add age + """ + ids = pd.DataFrame({"dw_ek_borger": df["dw_ek_borger"].unique()}) ids["age"] = np.random.randint(17, 95, len(ids)) ids["gender"] = np.where(ids["dw_ek_borger"] > 30_000, "F", "M") From 3e80894fc7365ab24c3e7bbe2baba4310c96fc40 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Tue, 4 Oct 2022 14:10:45 +0200 Subject: [PATCH 76/77] ci: add python version to setup-python --- .github/workflows/pre-commit.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index fdf3492d..cecce73a 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -13,4 +13,6 @@ jobs: steps: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 + with: + python-version: 3.9 - uses: pre-commit/action@v3.0.0 \ No newline at end of file From 5e9d61d60e30b18b278985c592a622b51b39c71d Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 4 Oct 2022 12:51:42 +0000 Subject: [PATCH 77/77] 0.3.1 Automatically generated by python-semantic-release --- CHANGELOG.md | 5 +++++ pyproject.toml | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ce858a6..57e1ed0d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ +## v0.3.1 (2022-10-04) +### Fix +* More linting, enable pylint pre-commit hook ([`03a0be1`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/03a0be1772737379cdcb2088934f6e7666d54013)) +* Some extra linting ([`de621e8`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/de621e8bbdb22addae980822f0926cfd733d1e3a)) + ## v0.3.0 (2022-10-03) ### Feature * Try decomposing actions ([`316e643`](https://github.com/Aarhus-Psychiatry-Research/psycop-t2d/commit/316e64335ee1b14aaf1c0a02fc7aad474af7a09a)) diff --git a/pyproject.toml b/pyproject.toml index c135d610..7319bb72 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "psycopt2d" -version = "0.3.0" +version = "0.3.1" description = "Training scripts for the psycop-t2d project" authors = ["Your Name "]