Skip to content

Commit

Permalink
Merge pull request #1095 from ocefpaf/remove_duplicate_function
Browse files Browse the repository at this point in the history
Remove duplicated function
  • Loading branch information
benjwadams authored Jul 8, 2024
2 parents 8171958 + e86d886 commit de1c865
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 16 deletions.
4 changes: 2 additions & 2 deletions compliance_checker/cf/cf_1_6.py
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ def _check_valid_standard_units(self, ds, variable_name):
# IMPLEMENTATION CONFORMANCE 4.4 REQUIRED 1/2
elif standard_name == "time":
valid_standard_units.assert_true(
util.units_convertible(units, "seconds since 1970-01-01"),
cfutil.units_convertible(units, "seconds since 1970-01-01"),
"time must be in a valid units format <unit> since <epoch> "
f"not {units}",
)
Expand Down Expand Up @@ -1694,7 +1694,7 @@ def check_dimensional_vertical_coordinate(
"there is no default",
)

if not util.units_convertible("bar", units):
if not cfutil.units_convertible("bar", units):
valid_vertical_coord.assert_true(
positive in ("up", "down"),
f"{name}: vertical coordinates not defining pressure must include "
Expand Down
13 changes: 2 additions & 11 deletions compliance_checker/cf/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from lxml import etree
from netCDF4 import Dataset

from compliance_checker.cfutil import units_convertible

# copied from paegan
# paegan may depend on these later
_possiblet = {
Expand Down Expand Up @@ -325,17 +327,6 @@ def units_known(units):
return True


def units_convertible(units1, units2, reftimeistime=True):
"""Return True if a Unit representing the string units1 can be converted
to a Unit representing the string units2, else False."""
try:
u1 = Unit(units1)
u2 = Unit(units2)
except ValueError:
return False
return u1.is_convertible(u2)


def units_temporal(units):
try:
u = Unit(units)
Expand Down
5 changes: 2 additions & 3 deletions compliance_checker/tests/test_cf.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
download_cf_standard_name_table,
is_time_variable,
is_vertical_coordinate,
units_convertible,
units_temporal,
)
from compliance_checker.suite import CheckSuite
Expand Down Expand Up @@ -1903,8 +1902,8 @@ def test_check_cell_methods(self):
# --------------------------------------------------------------------------------

def test_temporal_unit_conversion(self):
self.assertTrue(units_convertible("hours", "seconds"))
self.assertFalse(units_convertible("hours", "hours since 2000-01-01"))
self.assertTrue(cfutil.units_convertible("hours", "seconds"))
self.assertFalse(cfutil.units_convertible("hours", "hours since 2000-01-01"))

def test_units_temporal(self):
self.assertTrue(units_temporal("hours since 2000-01-01"))
Expand Down

0 comments on commit de1c865

Please sign in to comment.