Skip to content
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

Pyudunits2 #1118

Draft
wants to merge 5 commits into
base: develop
Choose a base branch
from
Draft

Pyudunits2 #1118

wants to merge 5 commits into from

Conversation

ocefpaf
Copy link
Member

@ocefpaf ocefpaf commented Nov 5, 2024

Possible alternative for #1094

TODO:

  • add tests for optional cf-units
  • remove all the workarounds in compliance_checker/cfutil.py (_CCUnits and _units) when pyudunits2 is released.

@ocefpaf
Copy link
Member Author

ocefpaf commented Nov 7, 2024

@pelson Windows failures apart due to the micromamba bug, and the hacks I made to get the dates to work, this is great! Pyudunits2 can replace cf-units with just a few minor tweaks IMO.

@ocefpaf
Copy link
Member Author

ocefpaf commented Nov 7, 2024

This is a bit worrying. The test run time increased a lot with pyudunits2, that may be some of my hacks though.

Develop branch:

python -m pytest -s -rxs -v -k "not integration" compliance_checker  13.12s user 0.30s system 73% cpu 18.220 total

This branch:

python -m pytest -s -rxs -v -k "not integration" compliance_checker  529.36s user 0.62s system 99% cpu 8:54.87 total

Copy link

codecov bot commented Nov 12, 2024

Codecov Report

Attention: Patch coverage is 35.00000% with 39 lines in your changes missing coverage. Please review.

Project coverage is 71.25%. Comparing base (066a826) to head (5165974).
Report is 1 commits behind head on develop.

Files with missing lines Patch % Lines
compliance_checker/cfutil.py 31.91% 32 Missing ⚠️
compliance_checker/cf/util.py 42.85% 4 Missing ⚠️
compliance_checker/ioos.py 0.00% 2 Missing ⚠️
compliance_checker/cf/cf_1_6.py 75.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           develop    #1118       +/-   ##
============================================
- Coverage    81.91%   71.25%   -10.66%     
============================================
  Files           25       25               
  Lines         5224     5263       +39     
  Branches      1163     1169        +6     
============================================
- Hits          4279     3750      -529     
- Misses         644     1166      +522     
- Partials       301      347       +46     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -1864,8 +1865,7 @@ def check_time_coordinate(self, ds):
ret_val.append(result)
# IMPLEMENTATION CONFORMANCE 4.4 RECOMMENDED 2/2
# catch non-recommended months or years time interval
unit = Unit(variable.units)
if unit.is_long_time_interval():
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@benjwadams this is deprecated in cf-units and the change below should be implemented regardless of this PR. I'll open a new one just for this soon.

@@ -2066,9 +2066,6 @@ def _units(units: str):
# FIXME: cf_units.Unit(None) -> Unit('unknown')
if units is None:
units = ""
# FIXME: Syntax Error when HH:MM:SS is present in time reference.
if "T00:00:00" in units:
units = units.replace("T00:00:00", "")
Copy link
Member Author

@ocefpaf ocefpaf Nov 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pelson worked like a charm! All tests passing.

except (SyntaxError, UnresolvableUnitException) as err:
raise ValueError from err
# FIXME: cf_units defined .is_time_reference for time reference units.
u.is_time_reference = False
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pelson cf-units has a .is_time_reference() method to differentiate time units from reference time units (the COARDS format "time since date + a calendar") . Would something like this make sense in pyudunits2? It is easy enough for us to implement it. I guess that the question is: Will pyudunits2 be a replacement for cf-units or will cf-units use it under the hood and these methods should remain in cf-units.

# FIXME: hasattr should return None in that case.
# pyudunits2/_expr_graph.py:27, in Node.__getattr__(self, name)
# 25 def __getattr__(self, name):
# 26 # Allow the dictionary to raise KeyError if the key doesn't exist.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pelson I would expect pyudunits2 to return False instead of raising here. Does that make sense?

@ocefpaf ocefpaf force-pushed the pyudunits2 branch 6 times, most recently from a5f04cc to 54fbfc8 Compare November 15, 2024 08:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants