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

Differentiate when to use assertions vs exceptions #25

Open
GuillaumeQuenneville opened this issue Aug 31, 2022 · 0 comments
Open

Differentiate when to use assertions vs exceptions #25

GuillaumeQuenneville opened this issue Aug 31, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@GuillaumeQuenneville
Copy link

GuillaumeQuenneville commented Aug 31, 2022

Hi,

I really liked your talk on test & code, and I'm working through the book at the moment.

One comment/question I have is that I found your suggestions when to assert vs raise an exception were a little vague. From my understanding, assertions are great in tests (its the main mechanism to implement them) but should not be in production code. Production code should raise a ValueError, NotImplementedError, SomeCustomError... Something more representative than AssertionError.

For example, the exercise

codebook/testing.md

Lines 433 to 435 in 083bf38

```{admonition} 5-minute exercise
Find a commented out `print` statement in your code and transform it into an `assert`.
```

Might lead us to believe that you should have asserts in your production code vs a more appropriate exception.

In the testing to maintain your sanity section you mix tests at runtime (the data is bad) and tests that can be done at implementation time (you're loading the data incorrectlly) which add to the vagueness of when to put asserts.

codebook/testing.md

Lines 29 to 33 in 083bf38

- the data is bad
- you're loading the data incorrectly
- your model is incorrectly implemented
- your model is inappropriate for the data
- the statistical test you used is inappropriate for the data distribution

Thanks again for the ideas, ill be implementing some of them!

@patrickmineault patrickmineault added the enhancement New feature or request label Nov 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants