- 
                Notifications
    You must be signed in to change notification settings 
- Fork 35
Remove year 0 ticks if generated #50
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
Conversation
Towards fixing SciTools#44. Is there a way to write tests for this? I did not quite understand how that would be done.
| Disclaimer: I'm not a maintainer of this package so take my suggestion with a grain of salt :). @trexfeathers was kind enough to review my recent (closed) PR; perhaps he'd be willing to weigh in here. My two cents: if maintainers agree with this fix, I think adding some unit tests of  nc-time-axis/nc_time_axis/tests/unit/test_NetCDFTimeDateLocator.py Lines 81 to 115 in 531dd0d 
 | 
| Ah sorry. I didn't do my research. Just associated you with the package. I'll take a look in a bit. | 
| @trexfeathers are you generally ok with this fix? It is not a really sleek solution, but this problem has been popping up in many of my workflows: I work with long control runs of climate models which start in year 1, but the logic tends to try and 'pad' the axis limits a little bit and this cause a tick at year 0. | 
| 
 @jbusecke I only looked at nc-time-axis for the first time two weeks ago 😆, so I'd be uncomfortable passing judgement without doing some background reading first. I'm hopeful that I or another in my team will be permitted the time to give this the attention it deserves next week. | 
| @jbusecke it is also important that you sign the SciTools CLA (see the Governance notes for more detail), otherwise this PR cannot be merged even after it has been reviewed. | 
| Thanks for the instructions. Just signed the form. | 
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.
OK @jbusecke, I've stared and prodded at this for a while and I'm confident that your methodology is the right one - the Matplotlib API for mticker.MaxNLocator() is such that there's no good way of forecasting what will be generated, especially with all the specific resolution handling that nc_time_axis does, so it's definitely best to go for a retrospective modification as you have.
As for testing, I suggest:
- Copying Test_tick_values.test_yearly(), to make a new test
 (Obviously if one of the other existing tests makes for a better starting template then feel free to use whatever is appropriate)
- Adapt the new test to generate an example of what you are trying to fix, and assert for a range of ticks that does not include the tick that your code should remove
- Give the new test a name that is descriptive of the scenario it is testing for
I've also commented with a specific suggested change to your proposed code. Thanks!
Co-authored-by: Martin Yeo <[email protected]>
| Hi @trexfeathers, super sorry for the long delay. I have added a test, but I am quite unsure about the format (have only used pytest so far). My basic idea was to create ticks that would default to year 0 and loop over every calendar type. I also checked that none of the ticks has the  Happy to change this any way you see fit. | 
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.
@jbusecke thanks for persevering, especially having to use unittest 🤢 - we all want pytest too, when there's time!
And sorry for the gradual pace of this; I'm regularly pushing for more time to look at nc-time-axis.
I reckon you're nearly there, but have some suggestions for improved coverage and good setup practice.
| 
 I had a similar thought, but the few extra lines we are working on make it much clearer what we're aiming for. | 
| Ok I think I have implemented all the changes you requested (and reversed the automatic formatting introduced by my editor). Many thanks for the patient review! | 
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 job, LGTM!
Towards fixing #44.
@spencerkclark I was not sure how to add tests for this. Is there an example that you could point me to?