Skip to content

Commit

Permalink
fix another issue in format()
Browse files Browse the repository at this point in the history
  • Loading branch information
Ken Kundert authored and Ken Kundert committed Mar 2, 2024
1 parent 3492579 commit 9019549
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
14 changes: 6 additions & 8 deletions quantiphy/quantiphy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2576,6 +2576,7 @@ def format(self, template=''):
scale = units if units else None
prec = int(prec) if prec else None
ftype = ftype if ftype else ''
alt_form = dict(strip_zeros=False, strip_radix=False) if alt_form else {}
if ftype and ftype in 'dnu':
if ftype == 'u':
value = scale if scale else self.units
Expand All @@ -2591,30 +2592,27 @@ def format(self, template=''):
if ftype in 's': # note that ftype = '' matches this case
label = label if ftype else None
value = self.render(
prec=prec, show_label=label, scale=scale,
strip_zeros=not alt_form, strip_radix=not alt_form
prec=prec, show_label=label, scale=scale, **alt_form
)
elif ftype == 'q':
value = self.render(
form='si', prec=prec, show_units=True, show_label=label,
strip_zeros=not alt_form, strip_radix=not alt_form, scale=scale
scale=scale, **alt_form
)
elif ftype == 'r':
value = self.render(
form='si', prec=prec, show_units=False, show_label=label,
strip_zeros=not alt_form, strip_radix=not alt_form, scale=scale
scale=scale, **alt_form
)
elif ftype == 'p':
value = self.fixed(
prec=prec, show_units=True, show_label=label,
show_commas=bool(comma), strip_zeros=not alt_form,
strip_radix=not alt_form, scale=scale
show_commas=bool(comma), scale=scale, **alt_form
)
elif ftype == 'b':
value = self.binary(
prec=prec, show_units=True, show_label=label,
strip_zeros=not alt_form, strip_radix=not alt_form,
scale=scale
scale=scale, **alt_form
)
else:
if prec is None:
Expand Down
8 changes: 4 additions & 4 deletions tests/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,10 +399,10 @@ def test_format_method():
assert q.format('G') == 'f = 1.4204e+09'
assert q.format('n') == 'f'
assert q.format('d') == 'frequency of hydrogen line'
assert q.format('p') == '1420405751.786 Hz'
assert q.format(',p') == '1,420,405,751.786 Hz'
assert q.format('P') == 'f = 1420405751.786 Hz'
assert q.format(',P') == 'f = 1,420,405,751.786 Hz'
assert q.format('p') == '1420405751.7860 Hz'
assert q.format(',p') == '1,420,405,751.7860 Hz'
assert q.format('P') == 'f = 1420405751.7860 Hz'
assert q.format(',P') == 'f = 1,420,405,751.7860 Hz'
assert q.format('#p') == '1420405751.7860 Hz'
assert q.format('#,p') == '1,420,405,751.7860 Hz'
assert q.format('#P') == 'f = 1420405751.7860 Hz'
Expand Down

0 comments on commit 9019549

Please sign in to comment.