Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving readability/consistency of errors/exceptions in gempyor (second batch) #387

Open
wants to merge 34 commits into
base: dev
Choose a base branch
from

Conversation

emprzy
Copy link
Collaborator

@emprzy emprzy commented Nov 6, 2024

Describe your changes.

This pull request adjusts syntax, clarity, and formatting of errors/exceptions in gempyor's model_info.py, outcomes.py, seeding.py, seir.py, and simulation_component.py. This is the second of many sequential PR's to address the lack of consistency in formatting and style in gempyor errors/exceptions.

This pull request does NOT attempt to narrow or refine which type of errors are thrown, nor does it address the poor practice of using print() statements (as opposed to a logger) for stray warnings or errors. See GH- #310.

What does your pull request address? Tag relevant issues.

This pull request addresses GH- #281 .

By splitting this up into multiple PR's, hopefully it will make it easier to review, and also make it easier for me to be dynamic in the solutions I implement if anyone has any suggestions for the way I am doing this.

emprzy and others added 2 commits November 1, 2024 11:26
Includes model_info.py, outcomes.py, seeding.py, seir.py, and simulation_component.py (this last one didn't require any edits).
@emprzy
Copy link
Collaborator Author

emprzy commented Nov 6, 2024

Creating this PR so that I can easily see the conflicts that need to be resolved. This is not ready for review yet!

@pearsonca
Copy link
Contributor

Creating this PR so that I can easily see the conflicts that need to be resolved. This is not ready for review yet!

Fine for this go round, but consider using the "draft PR" functionality in the future.

@emprzy
Copy link
Collaborator Author

emprzy commented Nov 8, 2024

Creating this PR so that I can easily see the conflicts that need to be resolved. This is not ready for review yet!

Fine for this go round, but consider using the "draft PR" functionality in the future.

Ah, had no idea this functionality existed. Great, thank you!!

@TimothyWillard
Copy link
Contributor

Can we modify this PR to merge into the dev branch instead of main? I don't see any breaking changes for main at a glance, but I would like to move us towards merging feature branches into the dev branch. I think this will be a great addition to the December release!

@emprzy emprzy changed the base branch from main to dev November 8, 2024 20:15
Copy link
Contributor

@TimothyWillard TimothyWillard left a comment

Choose a reason for hiding this comment

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

I tried to make all of the quick things suggestions to make it a breeze to get through everything this time. Like before, mostly nit-picky things relating to shortening messages and removing awkward punctuation, so hopefully quick to get through. One thing that is not in the code is this warning that came from the CI:

=============================== warnings summary ===============================
tests/parameters/test_parameters_class.py:286
tests/parameters/test_parameters_class.py:286
  /home/runner/work/flepiMoP/flepiMoP/flepimop/gempyor_pkg/tests/parameters/test_parameters_class.py:286: DeprecationWarning: invalid escape sequence '\:'
    f"Provided file dates span '{timeseries_start_date}( 00\:00\:00)?' to '{timeseries_end_date}( 00\:00\:00)?', "

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
================= 410 passed, 2 warnings in 217.92s (0:03:37) ==================

This may have snuck in with GH-313, but can we fix here? See: https://github.com/HopkinsIDD/flepiMoP/actions/runs/11748501992/job/32732711221.

flepimop/gempyor_pkg/src/gempyor/model_info.py Outdated Show resolved Hide resolved
flepimop/gempyor_pkg/src/gempyor/model_info.py Outdated Show resolved Hide resolved
flepimop/gempyor_pkg/src/gempyor/model_info.py Outdated Show resolved Hide resolved
flepimop/gempyor_pkg/src/gempyor/model_info.py Outdated Show resolved Hide resolved
flepimop/gempyor_pkg/src/gempyor/model_info.py Outdated Show resolved Hide resolved
flepimop/gempyor_pkg/src/gempyor/seir.py Outdated Show resolved Hide resolved
flepimop/gempyor_pkg/src/gempyor/seir.py Outdated Show resolved Hide resolved
flepimop/gempyor_pkg/src/gempyor/seir.py Outdated Show resolved Hide resolved
flepimop/gempyor_pkg/tests/seir/test_seir.py Outdated Show resolved Hide resolved
flepimop/gempyor_pkg/src/gempyor/model_info.py Outdated Show resolved Hide resolved
the function `test_raises_not_implemented_error()` in test file `test_read_df.py` on account that it was receiving a `ValueError` when it expected a `NotImplementedError`. I switched the error within `utils.py:read_df()` to be an expected `NotImplementedError`.
There were not that many changes in the final batch of error improvements, so I went ahead and lumped them in with batch two.
@emprzy
Copy link
Collaborator Author

emprzy commented Nov 20, 2024

Progress update: there were not that many changes in the final batch of error improvements, so I went ahead and put them in this PR.

Copy link
Contributor

@pearsonca pearsonca left a comment

Choose a reason for hiding this comment

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

Seems generally good, but a few errors seem to have crept in.

flepimop/gempyor_pkg/src/gempyor/model_info.py Outdated Show resolved Hide resolved
flepimop/gempyor_pkg/src/gempyor/model_info.py Outdated Show resolved Hide resolved
flepimop/gempyor_pkg/src/gempyor/model_info.py Outdated Show resolved Hide resolved
flepimop/gempyor_pkg/src/gempyor/model_info.py Outdated Show resolved Hide resolved
flepimop/gempyor_pkg/src/gempyor/model_info.py Outdated Show resolved Hide resolved
@@ -44,7 +44,10 @@ def test_ModelInfo_init_tf_is_ahead_of_ti_fail(self):
config.read(user=False)
config.set_file(f"{DATA_DIR}/config_test.yml")
config["start_date"] = "2022-01-02"
with pytest.raises(ValueError, match=r"tf.*is less than or equal to ti.*"):
with pytest.raises(
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd prefer this match to the error-causing values (to verify that the error contains the offending values for the user to see), rather than the precise wording of the message.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Note to self: need to find how ti and tf are referenced in this file

with pytest.raises(
ValueError, match=rf"^Unsupported regularization\: {unsupported_name}$"
):
with pytest.raises(ValueError, match=r"^Unsupported regularization \[received:.*$"):
Copy link
Contributor

Choose a reason for hiding this comment

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

Again, prefer this matches the offending value offered rather than the precise message.

rf"the same shape\: model\_data\.shape\=\({model_rows}\, {model_cols}\) "
rf"\!\= gt\_data\.shape\=\({gt_rows}\, {gt_cols}\)$"
)
expected_match = rf".*do not have the same shape:.*"
Copy link
Contributor

Choose a reason for hiding this comment

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

ibid, though a bit more complicated.

@@ -14,15 +14,15 @@ class TestRandomDistributionSampler:
def test_not_implemented_error_exception(self, distribution: str) -> None:
with pytest.raises(
NotImplementedError,
match=rf"^unknown distribution \[got\: {distribution}\]$",
match=rf"^Unknown distribution \[received.*",
Copy link
Contributor

Choose a reason for hiding this comment

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

prefer match bad argument value rather than message

@@ -38,13 +38,13 @@ def test_raises_not_implemented_error(self) -> None:
"""
with pytest.raises(
expected_exception=NotImplementedError,
match="Invalid extension txt. Must be 'csv' or 'parquet'.",
match=r".*Supported extensions are `.csv` or `.parquet`.",
Copy link
Contributor

Choose a reason for hiding this comment

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

prefer match bad argument value rather than message (though also worth matching the supported argument values, to confirm we're informing users).

Copy link
Contributor

Choose a reason for hiding this comment

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

(this comment repeats for a few more changes here and in test_utils)

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

Successfully merging this pull request may close these issues.

4 participants