-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Raise error for invalid reference date for encoding time units #5288
Conversation
Looks good, thanks. As usual a test would be superb! You can add a new test in xarray/xarray/tests/test_coding_times.py Line 816 in 44f4ae1
It can be as easy as with pytest.raises(ValueError, match="invalid reference date"):
xr.coding.times.encode_cf_datetime([1, 2, 3], units='days since NO_YEAR') |
6d3eaa6
to
a46936f
Compare
Done :) Since it was very little effort, I've also added a test for the other related error raising. |
a46936f
to
eab4fa8
Compare
Sorry I wasn't entirely clear - I meant "the tests belong in this general vicinity" - could you put them in their own function? You can also give yourself credit by adding something to whats-new (up to you). |
…e_units * upstream/master: combine keep_attrs and combine_attrs in apply_ufunc (pydata#5041) Explained what a deprecation cycle is (pydata#5289) Code cleanup (pydata#5234) FacetGrid docstrings (pydata#5293) Add whats new for dataset interpolation with non-numerics (pydata#5297) Allow dataset interpolation with different datatypes (pydata#5008) Flexible indexes: add Index base class and xindexes properties (pydata#5102)
Thanks @gcaria! |
Hi @dcherian, thanks for the merge, however I think there was one last edit left for this PR, i.e. put the tests in their own function. How should I go about this? |
@gcaria no problem at all to submit another PR — the more the merrier |
pre-commit run --all-files
whats-new.rst
Although the error raised by this commit does not include the whole units string, I believe it is actually more useful and specific since it focuses on the part (reference date) that's actually causing the problem.
Also, the reference date is the only information available in
coding.times._ensure_padded_year
, so this is the simplest way of raising an error.I had a look in
tests/test_coding_times.py
and could not find a test for this related error raising (since I'd put a test for this commit around there)xarray/xarray/coding/times.py
Lines 127 to 129 in 234b40a
Have I missed it?
EDIT: I've tried to substitute the error raise on line 129 with a
pass
and all the tests passed anyway.