-
Notifications
You must be signed in to change notification settings - Fork 9
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
Fix FIMSFrame #641
Fix FIMSFrame #641
Conversation
Instructions for code reviewerHello reviewer, thanks for taking the time to review this PR!
Checklist
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #641 +/- ##
==========================================
+ Coverage 78.56% 78.88% +0.32%
==========================================
Files 36 36
Lines 1945 1975 +30
Branches 141 141
==========================================
+ Hits 1528 1558 +30
Misses 374 374
Partials 43 43 ☔ View full report in Codecov by Sentry. |
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.
Nice work @kellijohnson-NOAA.
I like the new validate_data_colnames()
function, and the extra format checks within FIMSFrame()
. It's probably useful that the bug cropped up because this system of error checks will surely pay off in the future by being more robust (as you noted in the 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.
The column names of the S4@data object were being checked with the
validation function but there was no check in FIMSFrame and to do the
calculations within FIMSFrame all of the columns need to be present.
Right now we are checking it twice, once in FIMSFrame and once in the
validator of the FIMSFrame class. We might need a different class like an
input data class and we could check the class upon input to FIMSFrame but
this works for right now. @k-doering-NOAA do you have any ideas here?
From reading on the validate function in the advanced R book, it sounds like checking should be done in the validation function; however, if it means the user will not get a helpful error, that does seem like a problem. Maybe we should be a little unconventional (I think) and just do the checking when putting together the dataframe? Or is there a reason we should be checking the columns names twice?
Just an idea, though, and I think your solution is fine for now!
The column names of the S4@data object were being checked with the validation function but there was no check in FIMSFrame and to do the calculations within FIMSFrame all of the columns need to be present. Right now we are checking it twice, once in FIMSFrame and once in the validator of the FIMSFrame class. We might need a different class like an input data class and we could check the class upon input to FIMSFrame but this works for right now. @k-doering-NOAA do you have any ideas here? Had to change the test of a data frame without the proper columns to just error out because no warnings are given just a stop() command.
When writing a data frame to a csv and reading it back in, the date formatting can be lost, e.g., 0001-01-01 turns into 1-1-1. FIMS requires a yyyy-mm-dd format. Now the use of the as.Date() function will create a date object from a character object but only if it is in the correct format. If it is in the wrong format, e.g., yyyy/mm/dd, then the function will error out. Right now the start_year and end_year are formatted as integers because for plotting, I thought it would be better to have year 1 versus year 0001 but we can change this. @ian-taylor-NOAA what do you think?
Thanks @iantaylor-NOAA and @k-doering-NOAA for the review and comments. I have been thinking about the best way forward (hence the delay in my response) and I think we should leave the check in there twice for right now because we have multiple developers working on the methods and checking in the validity function for the column names of the output to be correct saves us from writing an additional formal test in the testthat code. So, in the future we might need to remove it but the extra precaution it provides right now appears to be a good thing. |
fd3bb80
to
624714f
Compare
What is the feature?
type.convert()
is reformatting date to character without leading zeros in data_mile1 #639 where the leading zeros of the year if using fake years of single-digit integers are removed when saving to a csv file and reading the data back in. Instead of worrying about always having leading zeros, I have created a feature that ensures FIMSFrame creates date objects.How have you implemented the solution?
Using as.Date() for datestart and dateend to ensure the leading zeros are present. And, the format portion of as.Date() ensures that the dates are formatted with dashes instead of slashes and will give users an error if they are not.
Does the PR impact any other area of the project?
Objects from FIMSFrame are not really being used in the code right now so it is not a well-spread problem. We just noticed it in the data group when we started using the slots of FIMSFrame for things.
How to test this change
The change is tested in the automated tests.
Developer pre-PR checklist
This PR is broken up into two commits (that should later be squashed) but I would like comments from @k-doering-NOAA on the first commit and comments from @iantaylor-NOAA on the second commit. Thank you.
Closes #639