Skip to content

Commit

Permalink
Merge pull request #214 from harmsm/np2_repr
Browse files Browse the repository at this point in the history
add as_float, change repr(x) -> str(x)
  • Loading branch information
tshead2 committed Jul 12, 2024
2 parents 93ab5d6 + cce091b commit f32537e
Show file tree
Hide file tree
Showing 12 changed files with 248 additions and 201 deletions.
10 changes: 6 additions & 4 deletions features/steps/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import toyplot.require
import toyplot.svg

from toyplot.require import as_float

try:
import toyplot.pdf
except:
Expand Down Expand Up @@ -146,7 +148,7 @@ def attribute_mismatch(tag, key, avalue, bvalue):

def optional_float(value):
try:
return float(value)
return as_float(value)
except:
return value

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


def assert_points_equal(tag, key, avalue, bvalue):
alist = [float(value) for pair in avalue.split() for value in pair.split(",")]
blist = [float(value) for pair in bvalue.split() for value in pair.split(",")]
alist = [as_float(value) for pair in avalue.split() for value in pair.split(",")]
blist = [as_float(value) for pair in bvalue.split() for value in pair.split(",")]
assert_mixed_list_equal(alist, blist, tag, key, avalue, bvalue)


Expand Down Expand Up @@ -205,7 +207,7 @@ def assert_dom_equal(a, b, exceptions):
continue

if exception.get("type", None) == "float":
if not numpy.allclose(float(avalue), float(bvalue)):
if not numpy.allclose(as_float(avalue), as_float(bvalue)):
attribute_mismatch(a.tag, akey, avalue, bvalue)
elif exception.get("type", None) == "path":
assert_path_equal(a.tag, akey, avalue, bvalue)
Expand Down
3 changes: 2 additions & 1 deletion features/steps/tick-locator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import numpy
import sys
import toyplot.locator
from toyplot.require import as_float

import testing

Expand Down Expand Up @@ -223,7 +224,7 @@ def step_impl(context):

@given(u'a {count} {units} interval')
def step_impl(context, count, units):
context.timestamp_interval = (float(count), units)
context.timestamp_interval = (as_float(count), units)

@given(u'an interval of days')
def step_impl(context):
Expand Down
12 changes: 6 additions & 6 deletions toyplot/color.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import numpy

import toyplot.projection

from toyplot.require import as_float

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

match = css.rgb_percent(value)
if match:
r, g, b = [float(group) / 100.0 for group in match.groups()]
r, g, b = [as_float(group) / 100.0 for group in match.groups()]
return rgba(r, g, b, 1)

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

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

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

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

Expand Down
2 changes: 1 addition & 1 deletion toyplot/font.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def __init__(self, family, size):
self._descent = toyplot.units.convert(descent, target="px", default="pt")

def __repr__(self): # pragma: no cover
return "<toyplot.font.ReportlabFont family=%r size=%r ascent=%r descent=%r>" % (self._family, self._size, self.ascent, self.descent)
return "<toyplot.font.ReportlabFont family=%s size=%s ascent=%s descent=%s>" % (self._family, self._size, self.ascent, self.descent)

@property
def ascent(self):
Expand Down
Loading

0 comments on commit f32537e

Please sign in to comment.