-
Notifications
You must be signed in to change notification settings - Fork 4
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
base: dev
Are you sure you want to change the base?
Conversation
Includes model_info.py, outcomes.py, seeding.py, seir.py, and simulation_component.py (this last one didn't require any edits).
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!! |
Can we modify this PR to merge into the |
There was a problem hiding this 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.
Co-authored-by: Timothy Willard <[email protected]>
Co-authored-by: Timothy Willard <[email protected]>
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.
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. |
There was a problem hiding this 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.
@@ -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( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:.*$"): |
There was a problem hiding this comment.
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:.*" |
There was a problem hiding this comment.
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.*", |
There was a problem hiding this comment.
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`.", |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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)
Awaiting regex error kickback to adjust the test files.
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
, andsimulation_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.