Skip to content

Commit 62903b4

Browse files
committed
Change units() units kwarg --> dest
1 parent daf786f commit 62903b4

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

proplot/utils.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@
1616

1717
__all__ = ['arange', 'edges', 'edges2d', 'units']
1818

19-
BENCHMARK = False # change this to turn on benchmarking
20-
NUMBER = re.compile('^([-+]?[0-9._]+([eE][-+]?[0-9_]+)?)(.*)$')
19+
# Change this to turn on benchmarking
20+
BENCHMARK = False
21+
22+
# Units regex
23+
NUMBER = re.compile('^([-+]?[0-9._]+(?:[eE][-+]?[0-9_]+)?)(.*)$')
2124

2225

2326
class _benchmark(object):
@@ -239,7 +242,7 @@ def edges2d(Z):
239242
return Zb
240243

241244

242-
def units(value, units='in', axes=None, figure=None, width=True):
245+
def units(value, dest='in', axes=None, figure=None, width=True):
243246
"""
244247
Convert values and lists of values between arbitrary physical units. This
245248
is used internally all over ProPlot, permitting flexible units for various
@@ -249,7 +252,7 @@ def units(value, units='in', axes=None, figure=None, width=True):
249252
----------
250253
value : float or str or list thereof
251254
A size specifier or *list thereof*. If numeric, nothing is done.
252-
If string, it is converted to `units` units. The string should look
255+
If string, it is converted to the units `dest`. The string should look
253256
like ``'123.456unit'``, where the number is the magnitude and
254257
``'unit'`` is one of the following.
255258
@@ -274,12 +277,12 @@ def units(value, units='in', axes=None, figure=None, width=True):
274277
``'ly'`` Light years ;)
275278
========= =========================================================================================
276279
277-
units : str, optional
280+
dest : str, optional
278281
The destination units. Default is inches, i.e. ``'in'``.
279282
axes : `~matplotlib.axes.Axes`, optional
280-
The axes to use for scaling units that look like ``0.1ax``.
283+
The axes to use for scaling units that look like ``'0.1ax'``.
281284
figure : `~matplotlib.figure.Figure`, optional
282-
The figure to use for scaling units that look like ``0.1fig``. If
285+
The figure to use for scaling units that look like ``'0.1fig'``. If
283286
``None`` we try to get the figure from ``axes.figure``.
284287
width : bool, optional
285288
Whether to use the width or height for the axes and figure relative
@@ -330,10 +333,10 @@ def units(value, units='in', axes=None, figure=None, width=True):
330333
unit_dict['fig'] = figure.get_size_inches()[1 - int(width)]
331334
# Scale for converting inches to arbitrary other unit
332335
try:
333-
scale = unit_dict[units]
336+
scale = unit_dict[dest]
334337
except KeyError:
335338
raise ValueError(
336-
f'Invalid destination units {units!r}. Valid units are '
339+
f'Invalid destination units {dest!r}. Valid units are '
337340
+ ', '.join(map(repr, unit_dict.keys())) + '.'
338341
)
339342

@@ -355,10 +358,11 @@ def units(value, units='in', axes=None, figure=None, width=True):
355358
f'Invalid size spec {val!r}. Valid units are '
356359
+ ', '.join(map(repr, unit_dict.keys())) + '.'
357360
)
358-
number, _, units = regex.groups() # second group is exponential
361+
number, units = regex.groups() # second group is exponential
359362
try:
360363
result.append(
361-
float(number) * (unit_dict[units] / scale if units else 1))
364+
float(number) * (unit_dict[units] / scale if units else 1)
365+
)
362366
except (KeyError, ValueError):
363367
raise ValueError(
364368
f'Invalid size spec {val!r}. Valid units are '

0 commit comments

Comments
 (0)