@@ -19,27 +19,25 @@ class DateConverter(units.ConversionInterface):
1919
2020 @staticmethod
2121 def convert(value, unit, axis):
22- ' Convert a datetime value to a scalar or array'
22+ " Convert a datetime value to a scalar or array."
2323 return dates.date2num(value)
2424
2525 @staticmethod
2626 def axisinfo(unit, axis):
27- 'Return major and minor tick locators and formatters'
28- if unit!='date': return None
27+ "Return major and minor tick locators and formatters."
28+ if unit != 'date':
29+ return None
2930 majloc = dates.AutoDateLocator()
3031 majfmt = dates.AutoDateFormatter(majloc)
31- return AxisInfo(majloc=majloc,
32- majfmt=majfmt,
33- label='date')
32+ return AxisInfo(majloc=majloc, majfmt=majfmt, label='date')
3433
3534 @staticmethod
3635 def default_units(x, axis):
37- ' Return the default unit for x or None'
36+ " Return the default unit for x or None."
3837 return 'date'
3938
4039 # Finally we register our object type with the Matplotlib units registry.
4140 units.registry[datetime.date] = DateConverter()
42-
4341"""
4442
4543from decimal import Decimal
@@ -165,25 +163,15 @@ def convert(value, unit, axis):
165163 value : decimal.Decimal or iterable
166164 Decimal or list of Decimal need to be converted
167165 """
168- # If value is a Decimal
169166 if isinstance (value , Decimal ):
170167 return float (value )
168+ # value is Iterable[Decimal]
169+ elif isinstance (value , ma .MaskedArray ):
170+ return ma .asarray (value , dtype = float )
171171 else :
172- # assume x is a list of Decimal
173- converter = np .asarray
174- if isinstance (value , ma .MaskedArray ):
175- converter = ma .asarray
176- return converter (value , dtype = float )
177-
178- @staticmethod
179- def axisinfo (unit , axis ):
180- # Since Decimal is a kind of Number, don't need specific axisinfo.
181- return AxisInfo ()
172+ return np .asarray (value , dtype = float )
182173
183- @staticmethod
184- def default_units (x , axis ):
185- # Return None since Decimal is a kind of Number.
186- return None
174+ # axisinfo and default_units can be inherited as Decimals are Numbers.
187175
188176
189177class Registry (dict ):
0 commit comments