Issue #498: Implement a simple print function for forecast objects.#592
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #592 +/- ##
==========================================
+ Coverage 85.77% 85.88% +0.10%
==========================================
Files 21 21
Lines 1758 1771 +13
==========================================
+ Hits 1508 1521 +13
Misses 250 250 ☔ View full report in Codecov by Sentry. |
|
Nice! Thanks so much and apologies for taking so long to get back to you. I think the following line The reason is that the object is still of class To make sure we have that covered in the future we should in addition add a test to We have a similar issue in when running the following piece of code from the scoringutils.Rmd Vignette: The issue here is that the output of Update: This is done and merged into main. The current suggestion defines an extra function, and etc. Probably even better, we should consider introducing a super-class, I would personally prefer to keep the protected columns out of the printing method for now and introduce them later. I think it is generally nice to inform about protected columns. However, I would prefer to add them at a later point in time because we don't really have written guidance on what a protected column actually is. At the moment it is "something that functions aren't allowed to touch and where you need to be careful to rename them". But there are a lot of uncertainties. What are our protected columns exactly? Is a score a protected column? I think we need something written down that explains what a protected column actually is before we can inform users about the protected columns. Summarising this wall of text, my suggestions are
What do others think? I think the overall PR is really good, as always lots of tiny details to deal with. Thanks a lot again. |
i.e. no action needed here for you @toshiakiasakura
Yeah I think getting something simple off the ground makes sense and then thinking about merging in a future issue/PR would be good. I can see a good argument for why we would want a meta-class or classes (for example for categorical forecasts (which have nominal, ordinal, and binary in them) etc.) but again yes a problem for another day IMO. So for @toshiakiasakura / this PR we have:
Really excited to get this in as I think it is really useful functionality. |
|
@toshiakiasakura How are you feeling about this at the moment? Happy to help get this PR over the finish line! |
|
Thanks for a lot of suggestions. I will try to work on following the checklist. I agree with most. One reason I separately prepare `print_forecast_info' is that in my mind, in the later phase, I am thinking of introducing the validating results in the print result. For that purpose, we need a bit different implementation for each print object, and then allow the code to be extended differently. For the simplicity, should I still at this stage amend the code to remove |
Yes I think that makes sense for this PR |
In this commit, I edited - Remove print_forecast_info() and directly assigned the code into the methods. - Remove the protected columns from the print. - Use nextMethod instead of print(as.data.table)
|
I've almost done with the updates.
For testing
Added the simple test to check the print function outputs the "Forecast type" and "Forecast units". Currently output is like this. example_quantile %>%
set_forecast_unit(c("location", "target_end_date", "target_type", "horizon", "model")) %>%
as_forecast() %>%
add_coverage() %>%
print
#> Forecast type:
#> [1] "quantile"
#>
#> Score columns:
#> [1] "interval_coverage" "interval_coverage_deviation"
#> [3] "quantile_coverage" "quantile_coverage_deviation"
#>
#> Forecast units:
#> [1] "location" "target_end_date" "target_type" "horizon"
#> [5] "model"
#>
#> observed quantile predicted location target_end_date target_type horizon
#> 1: 127300 NA NA DE 2021-01-02 Cases NA
|
nikosbosse
left a comment
There was a problem hiding this comment.
Nice! Thanks so much, @toshiakiasakura. This is looking really good and I think we're nearly there. I made some minor suggestions, but those are mostly housekeeping things (it helps running the check in RStudio or R CMD check in the terminal regularly to catch these early)
Two additional things:
- could you please add yourself to the contributors in the DESCRIPTION file? It is well deserved :)
- we should maybe add something to NEWS.md / updating the current News file saying that diagnostic messages are now printed directly.
Co-authored-by: Nikos Bosse <37978797+nikosbosse@users.noreply.github.com>
Co-authored-by: Nikos Bosse <37978797+nikosbosse@users.noreply.github.com>
Co-authored-by: Nikos Bosse <37978797+nikosbosse@users.noreply.github.com>
|
Thanks for correcting me. Now, I checked the code by the I have reflected your suggestions in the code, added me as a contributor, and added an item to NEWS.md! |
|
Thanks a lot, @toshiakiasakura! I'm not sure why the snapshot tests are failing. I checked out the code locally and tests passed there. Did they pass locally on your end? I'll investigate. As an aside, we might also want to think about
|
|
Sure, I will check later the linting problem. For testing, I implemented a very simple test in db0323f . |
Co-authored-by: Nikos Bosse <37978797+nikosbosse@users.noreply.github.com>
Yes, the test is unfortunately passed even though there is one trailing white space...
I added.
@nikosbosse For this part, there is also a possibility that res <- try(validate_forecast(x[, c("observed")] ), silent=TRUE)
if (class(res) == "try-error"){
message(res)
} else {
# current print contents.
}or cause the error (and stop the flow) by putting However, once any error occurs, this does not tell us any information about the |
|
For failing gracefully, I am wondering what case you expect the breakage of the |
|
@toshiakiasakura What I mean is that, for example, the following produces an error, because the object can't get printed anymore because Ideally, there should be something like an error (or a warning), but the data.table would still print. @seabbs any thoughts on whether this should be part of this PR or a separate PR? I lean towards addressing it in this PR as it seems quite important to me that users can still print their output even if something is wrong. But I appreciate that this would mean adding even more to this PR, for which I apologise, @toshiakiasakura! |
I am leaning towards addressing this in its own issue/PR as the suggestion above is already functional and we have had a fair few rounds of review already and I imagine everyone would like to see this on |
seabbs
left a comment
There was a problem hiding this comment.
LGTM. Thanks for this @toshiakiasakura !! I suggest we also open another issue to think about if we could make this even prettier using {cli}.
|
Perfect, merging now. Thanks a lot @toshiakiasakura! I think this is a really visible and important improvement to users. |
Description
This PR closes #498, and a refresh version of the PR from #584.
The updated simple print function behaviour becomes like the following.
get_protected_columnsfunction returns columns including "scores columns" and then I excluded score columns fromprotected columnsfield to avoid redunduncy.and
Checklist
lintr::lint_package()to check for style issues introduced by my changes.