8000 Merge pull request #20337 from anntzer/uc · matplotlib/matplotlib@bf6de23 · GitHub
[go: up one dir, main page]

Skip to content

Commit bf6de23

Browse files
authored
Merge pull request #20337 from anntzer/uc
Small unit-related cleanups.
2 parents ceb4023 + 85e5db2 commit bf6de23

File tree

1 file changed

+11
-23
lines changed

1 file changed

+11
-23
lines changed

lib/matplotlib/units.py

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -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

4543
from decimal import Decimal
@@ -166,25 +164,15 @@ def convert(value, unit, axis):
166164
value : decimal.Decimal or iterable
167165
Decimal or list of Decimal need to be converted
168166
"""
169-
# If value is a Decimal
170167
if isinstance(value, Decimal):
171168
return float(value)
169+
# value is Iterable[Decimal]
170+
elif isinstance(value, ma.MaskedArray):
171+
return ma.asarray(value, dtype=float)
172172
else:
173-
# assume x is a list of Decimal
174-
converter = np.asarray
175-
if isinstance(value, ma.MaskedArray):
176-
converter = ma.asarray
177-
return converter(value, dtype=float)
178-
179-
@staticmethod
180-
def axisinfo(unit, axis):
181-
# Since Decimal is a kind of Number, don't need specific axisinfo.
182-
return AxisInfo()
173+
return np.asarray(value, dtype=float)
183174

184-
@staticmethod
185-
def default_units(x, axis):
186-
# Return None since Decimal is a kind of Number.
187-
return None
175+
# axisinfo and default_units can be inherited as Decimals are Numbers.
188176

189177

190178
class Registry(dict):

0 commit comments

Comments
 (0)
0