22
33import operator
44
5+ from matplotlib import cbook
6+
57
68class UnitDbl :
79 """Class UnitDbl in development.
@@ -45,8 +47,7 @@ def __init__(self, value, units):
4547 - value The numeric value of the UnitDbl.
4648 - units The string name of the units the value is in.
4749 """
48- self .checkUnits (units )
49-
50+ cbook ._check_in_list (self .allowed , units = units )
5051 data = self .allowed [units ]
5152 self ._value = float (value * data [0 ])
5253 self ._units = data [1 ]
@@ -66,17 +67,13 @@ def convert(self, units):
6667 """
6768 if self ._units == units :
6869 return self ._value
69-
70- self .checkUnits (units )
71-
70+ cbook ._check_in_list (self .allowed , units = units )
7271 data = self .allowed [units ]
7372 if self ._units != data [1 ]:
74- msg = "Error trying to convert to different units.\n " \
75- " Invalid conversion requested.\n " \
76- " UnitDbl: %s\n " \
77- " Units: %s\n " % (str (self ), units )
78- raise ValueError (msg )
79-
73+ raise ValueError (f"Error trying to convert to different units.\n "
74+ f" Invalid conversion requested.\n "
75+ f" UnitDbl: { self } \n "
76+ f" Units: { units } \n " )
8077 return self ._value / data [0 ]
8178
8279 def __abs__ (self ):
@@ -236,6 +233,7 @@ def range(start, stop, step=None):
236233
237234 return elems
238235
236+ @cbook .deprecated ("3.2" )
239237 def checkUnits (self , units ):
240238 """Check to see if some units are valid.
241239
@@ -262,7 +260,6 @@ def checkSameUnits(self, rhs, func):
262260 - func The name of the function doing the check.
263261 """
264262 if self ._units != rhs ._units :
265- msg = "Cannot %s units of different types.\n " \
266- "LHS: %s\n " \
267- "RHS: %s" % (func , self ._units , rhs ._units )
268- raise ValueError (msg )
263+ raise ValueError (f"Cannot { func } units of different types.\n "
264+ f"LHS: { self ._units } \n "
265+ f"RHS: { rhs ._units } " )
0 commit comments