@@ -19,27 +19,25 @@ class DateConverter(units.ConversionInterface):
19
19
20
20
@staticmethod
21
21
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."
23
23
return dates.date2num(value)
24
24
25
25
@staticmethod
26
26
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
29
30
majloc = dates.AutoDateLocator()
30
31
majfmt = dates.AutoDateFormatter(majloc)
31
- return AxisInfo(majloc=majloc,
32
- majfmt=majfmt,
33
- label='date')
32
+ return AxisInfo(majloc=majloc, majfmt=majfmt, label='date')
34
33
35
34
@staticmethod
36
35
def default_units(x, axis):
37
- ' Return the default unit for x or None'
36
+ " Return the default unit for x or None."
38
37
return 'date'
39
38
40
39
# Finally we register our object type with the Matplotlib units registry.
41
40
units.registry[datetime.date] = DateConverter()
42
-
43
41
"""
44
42
45
43
from decimal import Decimal
@@ -165,25 +163,15 @@ def convert(value, unit, axis):
165
163
value : decimal.Decimal or iterable
166
164
Decimal or list of Decimal need to be converted
167
165
"""
168
- # If value is a Decimal
169
166
if isinstance (value , Decimal ):
170
167 return float (value )
168
+ # value is Iterable[Decimal]
169
+ elif isinstance (value , ma .MaskedArray ):
170
+ return ma .asarray (value , dtype = float )
171
171
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 )
182
173
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.
187
175
188
176
189
177
class Registry (dict ):
0 commit comments