Skip to content

Commit 3a0c513

Browse files
committed
add as_float, change repr(x) -> str(x)
1 parent 45e9ceb commit 3a0c513

File tree

11 files changed

+222
-175
lines changed

11 files changed

+222
-175
lines changed

features/steps/testing.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import toyplot.require
2121
import toyplot.svg
2222

23+
from toyplot.require import as_float
24+
2325
try:
2426
import toyplot.pdf
2527
except:
@@ -146,7 +148,7 @@ def attribute_mismatch(tag, key, avalue, bvalue):
146148

147149
def optional_float(value):
148150
try:
149-
return float(value)
151+
return as_float(value)
150152
except:
151153
return value
152154

@@ -173,8 +175,8 @@ def assert_path_equal(tag, key, avalue, bvalue):
173175

174176

175177
def assert_points_equal(tag, key, avalue, bvalue):
176-
alist = [float(value) for pair in avalue.split() for value in pair.split(",")]
177-
blist = [float(value) for pair in bvalue.split() for value in pair.split(",")]
178+
alist = [as_float(value) for pair in avalue.split() for value in pair.split(",")]
179+
blist = [as_float(value) for pair in bvalue.split() for value in pair.split(",")]
178180
assert_mixed_list_equal(alist, blist, tag, key, avalue, bvalue)
179181

180182

@@ -205,7 +207,7 @@ def assert_dom_equal(a, b, exceptions):
205207
continue
206208

207209
if exception.get("type", None) == "float":
208-
if not numpy.allclose(float(avalue), float(bvalue)):
210+
if not numpy.allclose(as_float(avalue), as_float(bvalue)):
209211
attribute_mismatch(a.tag, akey, avalue, bvalue)
210212
elif exception.get("type", None) == "path":
211213
assert_path_equal(a.tag, akey, avalue, bvalue)

features/steps/tick-locator.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import numpy
88
import sys
99
import toyplot.locator
10+
from toyplot.require import as_float
1011

1112
import testing
1213

@@ -223,7 +224,7 @@ def step_impl(context):
223224

224225
@given(u'a {count} {units} interval')
225226
def step_impl(context, count, units):
226-
context.timestamp_interval = (float(count), units)
227+
context.timestamp_interval = (as_float(count), units)
227228

228229
@given(u'an interval of days')
229230
def step_impl(context):

toyplot/color.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import numpy
1515

1616
import toyplot.projection
17-
17+
from toyplot.require import as_float
1818

1919
black = "#292724"
2020
"""Default color used throughout Toyplot figures."""
@@ -3217,30 +3217,30 @@ def css(value):
32173217

32183218
match = css.rgb_percent(value)
32193219
if match:
3220-
r, g, b = [float(group) / 100.0 for group in match.groups()]
3220+
r, g, b = [as_float(group) / 100.0 for group in match.groups()]
32213221
return rgba(r, g, b, 1)
32223222

32233223
match = css.rgba(value)
32243224
if match:
32253225
r, g, b, a = [
3226-
int(group) / 255.0 for group in match.groups()[:3]] + [float(match.groups()[3])]
3226+
int(group) / 255.0 for group in match.groups()[:3]] + [as_float(match.groups()[3])]
32273227
return rgba(r, g, b, a)
32283228

32293229
match = css.rgba_percent(value)
32303230
if match:
32313231
r, g, b, a = [
3232-
float(group) / 100.0 for group in match.groups()[:3]] + [float(match.groups()[3])]
3232+
as_float(group) / 100.0 for group in match.groups()[:3]] + [as_float(match.groups()[3])]
32333233
return rgba(r, g, b, a)
32343234

32353235
match = css.hsl(value)
32363236
if match:
3237-
h, s, l = [float(group) for group in match.groups()]
3237+
h, s, l = [as_float(group) for group in match.groups()]
32383238
r, g, b = colorsys.hls_to_rgb((h / 360.0) % 1, l / 100.0, s / 100.0)
32393239
return rgba(r, g, b, 1)
32403240

32413241
match = css.hsla(value)
32423242
if match:
3243-
h, s, l, a = [float(group) for group in match.groups()]
3243+
h, s, l, a = [as_float(group) for group in match.groups()]
32443244
r, g, b = colorsys.hls_to_rgb((h / 360.0) % 1, l / 100.0, s / 100.0)
32453245
return rgba(r, g, b, a)
32463246

0 commit comments

Comments
 (0)