Skip to content

Commit

Permalink
Convert Model In README To Notebook (#55)
Browse files Browse the repository at this point in the history
* add notebook

* pre-commit action

* update pre-commit config

* minor edit to pyproject file

* small update to notebook

* update quarto notebook further

* verify notebook works; add docstrings to data
  • Loading branch information
AFg6K7h4fhy2 authored Dec 16, 2024
1 parent a17005b commit a1a8530
Show file tree
Hide file tree
Showing 8 changed files with 571 additions and 28 deletions.
16 changes: 0 additions & 16 deletions .github/actions/pre-commit/action.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/pre-commit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ jobs:
run: pip install poetry
- name: Install packages
run: poetry install --with dev
- uses: ./.github/actions/pre-commit
- uses: pre-commit/[email protected]
52 changes: 49 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,48 @@ repos:
- id: end-of-file-fixer
- id: mixed-line-ending
- id: trailing-whitespace

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
# prevent giant files from being committed.
- id: check-added-large-files
args: ["--maxkb=10000"]
# simply check whether files parse as valid
# python
- id: check-ast
# check for files with names that would
# conflict on a case-insensitive filesystem
# like MacOS HFS+ or Windows FAT.
- id: check-case-conflict
# checks for a common error of placing
# code before the docstring.
- id: check-docstring-first
# attempts to load all yaml files to
# verify syntax.
- id: check-yaml
# allow yaml files which use the
# multi-document syntax
args: ["--allow-multiple-documents"]
# attempts to load all TOML files to
# verify syntax.
- id: check-toml
# makes sure files end in a newline and
# only a newline.
- id: end-of-file-fixer
# replaces or checks mixed line ending.
- id: mixed-line-ending
# verifies that test files are named
# correctly.
- id: name-tests-test
# ensure tests match test_.*\.py
args: ["--pytest-test-first"]
# trims trailing whitespace.
- id: trailing-whitespace
# checks that non-binary executables have
# a proper shebang.
- id: check-executables-have-shebangs
files: \.sh$
################################################################################
# QUARTO README RENDERING
################################################################################
Expand All @@ -39,7 +81,7 @@ repos:
- id: isort
args: ["--profile", "black", "--line-length", "79"]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.2
rev: v0.8.3
hooks:
- id: ruff
args: ["--ignore=E741", "--ignore=E731", "--fix"]
Expand All @@ -54,15 +96,19 @@ repos:
# SPELLING
################################################################################
- repo: https://github.com/crate-ci/typos
rev: v1.27.0
rev: typos-dict-v0.11.37
hooks:
- id: typos
args: ["--force-exclude"]
################################################################################
# COMMIT MESSAGES
################################################################################
- repo: https://github.com/commitizen-tools/commitizen
rev: v3.30.0
rev: v4.1.0
hooks:
- id: commitizen
- repo: https://github.com/jorisroovers/gitlint
rev: v0.19.1
hooks:
- id: gitlint
################################################################################
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ Install `forecasttools-py` via:
Submission](https://github.com/CDCgov/forecasttools-py/blob/main/notebooks/flusight_from_idata.qmd)
- [Community Meeting Utilities Demonstration
(2024-11-19)](https://github.com/CDCgov/forecasttools-py/blob/main/notebooks/forecasttools_community_demo_2024-11-19.qmd)
- [Creating InferenceData Objects and Using Forecasttools
Datasets](https://github.com/CDCgov/forecasttools-py/blob/main/notebooks/datasets_and_idata_creation.qmd)

*Coming soon as webpages, once [Issue
26](https://github.com/CDCgov/forecasttools-py/issues/26) is completed*.
Expand Down
1 change: 1 addition & 0 deletions README.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ pip3 install git+https://github.com/CDCgov/forecasttools-py@main

* [Format Arviz Forecast Output For FluSight Submission](https://github.com/CDCgov/forecasttools-py/blob/main/notebooks/flusight_from_idata.qmd)
* [Community Meeting Utilities Demonstration (2024-11-19)](https://github.com/CDCgov/forecasttools-py/blob/main/notebooks/forecasttools_community_demo_2024-11-19.qmd)
* [Creating InferenceData Objects and Using Forecasttools Datasets](https://github.com/CDCgov/forecasttools-py/blob/main/notebooks/datasets_and_idata_creation.qmd)

_Coming soon as webpages, once [Issue 26](https://github.com/CDCgov/forecasttools-py/issues/26) is completed_.

Expand Down
29 changes: 22 additions & 7 deletions forecasttools/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,15 @@ def check_url(url: str) -> bool:
example FluSight submission and the
US 2020 Census data.
url
Parameters
----------
url : str
The url to be checked.
Returns
-------
bool
Whether the URL is valid.
"""
try:
response = request.urlopen(url)
Expand All @@ -40,7 +47,9 @@ def check_file_save_path(
"""
Checks whether a file path is valid.
file_save_path
Parameters
----------
file_save_path : str
The file path to be checked.
"""
directory = os.path.dirname(file_save_path)
Expand All @@ -61,7 +70,9 @@ def make_census_dataset(
saves the dataset as a csv in a given
directory, if it does not already exist.
file_save_path
Parameters
----------
file_save_path : str
The path for where to save the output file.
"""
# check that file and directory paths are valid
Expand Down Expand Up @@ -103,12 +114,14 @@ def make_nshn_fitting_dataset(
NOT use the API endpoint, and instead expects
a CSV.
dataset
Parameters
----------
dataset : str
Name of the dataset to create. Either
"COVID" or "flu".
nhsn_dataset_path
nhsn_dataset_path : str
Path to the NHSN dataset (csv file).
file_save_path
file_save_path : str
The path for where to save the output file.
"""
# check that dataset parameter is possible
Expand Down Expand Up @@ -178,7 +191,9 @@ def get_and_save_flusight_submission(
"""
Saves an example FluSight submission as a csv.
file_save_path
Parameters
----------
file_save_path : str
The path for where to save the output file.
"""
# check if the save file exists
Expand Down
Loading

0 comments on commit a1a8530

Please sign in to comment.