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

Good errors #12

Merged
merged 13 commits into from
Sep 28, 2018
Merged

Good errors #12

merged 13 commits into from
Sep 28, 2018

Conversation

ErikPartridge
Copy link
Owner

@ErikPartridge ErikPartridge commented Sep 21, 2018

This implements the use of Result<f32, LengthError> for all public functions

Effectively, whenever any of the top-level functions are called, a check is done on the arrays, and they may return a LengthError if actual.len() and pred.len() differ.

The goal of this is to not panic when receiving different lengths and instead let the user handle it. This is in relation to #7

Doc tests and unit tests were also updated to reflect this—doc tests primarily using .unwrap(). The error criteria also has unit tests.

@coveralls
Copy link

coveralls commented Sep 21, 2018

Pull Request Test Coverage Report for Build 66

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 19 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-3.4%) to 87.742%

Files with Coverage Reduction New Missed Lines %
lib.rs 19 87.74%
Totals Coverage Status
Change from base Build 50: -3.4%
Covered Lines: 136
Relevant Lines: 155

💛 - Coveralls

Copy link
Collaborator

@Enet4 Enet4 left a comment

Choose a reason for hiding this comment

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

It is mostly OK, but there are a few concerns worth addressing. Most importantly, we should not be using unwrap() in documentation. Doctests should be relying on the ? operator instead. C-QUESTION-MARK explains how you can do this.

Not quite important yet, but it might also be worth thinking whether we'll have other kinds of errors to consider in the future. Each change in the error type counts as a breaking change, after all.

src/lib.rs Outdated
use std::fmt;

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct LengthError;
Copy link
Collaborator

Choose a reason for hiding this comment

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

We could make this type more useful by including the lengths of both predictions and ground truth. The implementation of Display could then be improved accordingly.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Cleaned up, adds the two variables to the struct and to the display.

src/lib.rs Outdated Show resolved Hide resolved
@ErikPartridge
Copy link
Owner Author

I also switched LengthError in results to Box<Error> I suspect we may need different errors down the road, and that seems to be the standard.

@Enet4
Copy link
Collaborator

Enet4 commented Sep 21, 2018

that seems to be the standard.

Well, not for libraries, actually. Those should be clear at compile time what kinds of errors can emerge from an operation, and we cannot do that with a Box<Error>. We can instead keep one or more error enum types to sum multiple types of errors.

Reverts LengthError to Box<Error>
@ErikPartridge
Copy link
Owner Author

Got it, reverted 👍

Copy link
Collaborator

@Enet4 Enet4 left a comment

Choose a reason for hiding this comment

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

Hmm sorry for the delay, I thought I had posted these sooner. Just a few more tweaks and it's good to go.

src/lib.rs Outdated

impl fmt::Display for LengthError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "The lengths of the predicted and actual datasets must be equal.\nInstead, the predicted length was found to be {} while the ground truth was found to be {}", self.0, self.1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you make this one a bit more concise? (stick to lowercase and one short line of text)

src/lib.rs Outdated

impl Error for LengthError {
fn description(&self) -> &str {
"The lengths of the predicted and actual datasets must be equal."
Copy link
Collaborator

Choose a reason for hiding this comment

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

Likewise, this text can also be shortened. Its usefulness is limited anyway.

src/lib.rs Outdated
where
T: Eq,
{
1.0 - categorical_accuracy(pred, actual)
let cat_acc = categorical_accuracy(pred, actual);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Or maybe just:

let cat_acc = categorical_accuracy(pred, actual)?;
Ok(1. - cat_acc)

@ErikPartridge
Copy link
Owner Author

All resolved!

Copy link
Collaborator

@Enet4 Enet4 left a comment

Choose a reason for hiding this comment

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

🤔

src/lib.rs Outdated

impl Error for LengthError {
fn description(&self) -> &str {
"Dataset lengths are do not match"
Copy link
Collaborator

Choose a reason for hiding this comment

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

"are do not match"?

@ErikPartridge
Copy link
Owner Author

Fixed that.. Thank you.. What's more concerning is I somehow proofread that and thought it looked okay

Copy link
Collaborator

@Enet4 Enet4 left a comment

Choose a reason for hiding this comment

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

All right! Thank you for keeping up with my nitpicks.

@ErikPartridge
Copy link
Owner Author

Thank you for the feedback and help!

Merged, bumped to 0.3.0 and published.

@ErikPartridge ErikPartridge merged commit 35cd1a0 into master Sep 28, 2018
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.

None yet

3 participants