-
Notifications
You must be signed in to change notification settings - Fork 14
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 warning if no time coords found with decode_times
#409
Conversation
xcdat/dataset.py
Outdated
try: | ||
ds = decode_time(ds) | ||
except KeyError as e: | ||
logger.warning(e) |
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.
This is the key fix – if decode_time
fails then ds
remains as is and a warning is printed. No need to update the decode_times
boolean. This makes sense to me.
516e9ef
to
adcb28d
Compare
Codecov ReportBase: 100.00% // Head: 100.00% // No change to project coverage 👍
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more Additional details and impacted files@@ Coverage Diff @@
## main #409 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 14 14
Lines 1254 1260 +6
=========================================
+ Hits 1254 1260 +6
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
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.
This looks good to me.
I just had one question about where logger warnings go – I think they are generally unseen in the conda version (unless you specifically try to capture it). Is that right?
xcdat/dataset.py
Outdated
try: | ||
ds_new = decode_time(ds_new) | ||
except KeyError as e: | ||
logger.warning(e) |
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.
I looked at this issue and it prints out the following in my xcdat_dev
environment:
2023-01-25 14:39:40,142 [WARNING]: dataset.py(open_dataset:106) >> "No time coordinates were found in this dataset to decode. Make sure time coordinates exist and their CF 'axis' or 'standard_name' attribute is set (e.g., ds['time'].attrs['axis'] = 'T' or ds['time'].attrs['standard_name'] = 'time'). Afterwards, try decoding with
decode_time()
again."
This is what we wanted...but as a user I don't want this printed to the console...does this print to the console in the conda version or is this only evident in the developer environment?
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.
We can change the level to .debug
if we want to avoid printing these warnings to the console. This is reasonable if the default behavior is decode_times=True
and we expect decode_times=True
to work in most cases.
One scenario to consider is if the dataset has time coordinates without CF attributes (e.g., axis
or standard_name
) but the user expects the coordinates to be decodable. In this case, the message won't be raised unless the user sets the xcdat logger level to .debug
, or if they try to run temporal averaging operations which will throw the KeyError
.
Let me know what you think about the above scenario and how frequent you think that might occur.
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.
I think you've convinced me we should keep the code as you have it. @lee1043 - thoughts?
@tomvothecoder below is what I see when I open the example data in #396 from terminal. It is great that data opened with no problem.
I understand @pochedls prefers error message to not shown in console and I agree. In parallel, I think revising the error message slightly may be helpful for clarifying. I suggest something like below: |
Thank you for your input @lee1043. @pochedls is actually in agreement with my revision to raise a warning instead of silencing it. A warning is raised if time coordinates cannot be detected with If we expect
Good suggestion. I agree with revising the warning message to make it clearer. |
"No time coordinates were found in this dataset to decode. If time " | ||
"coordinates were expected to exist, make sure they are detectable by " | ||
"setting the CF 'axis' or 'standard_name' attribute (e.g., " | ||
"ds['time'].attrs['axis'] = 'T' or " | ||
"ds['time'].attrs['standard_name'] = 'time'). Afterwards, try decoding " | ||
"again with `xcdat.decode_time`." |
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 updated KeyError
in decode_time()
, which is raised as a logger warning in open_dataset()
and open_mfdataset()
d331ccf
to
7b8e93d
Compare
Merging this PR |
Description
Checklist
If applicable: