Skip to content

Commit

Permalink
Add spacer keyword argument to Quantity.{render,fixed,binary}
Browse files Browse the repository at this point in the history
  • Loading branch information
Ken Kundert authored and Ken Kundert committed Jun 23, 2024
1 parent 899d099 commit 2f6aa2e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion doc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
SPHINXBUILD = sphinx-build -j 4
PAPER =
BUILDDIR = .build

Expand Down
6 changes: 6 additions & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,3 +289,9 @@ def predicate(self, name, attr, *args, **kwargs):
attr.__doc__
and not name.startswith('__')
)


suppress_warnings = [
'misc.highlighting_failure',
# suppress warning about the inability to parse a literal text block
]
6 changes: 5 additions & 1 deletion doc/releases.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ Latest development release
| Version: 2.20
| Released: 2024-04-27
- Remove % from *tight_units* list.
- Add spacer keyword argument to :meth:`Quantity.render`,
:meth:`Quantity.fixed` and :meth:`Quantity.binary`.


2.20 (2024-04-27)
-----------------
Expand Down Expand Up @@ -86,7 +90,7 @@ Latest development release
----------------
- Added *negligible*, *tight_units*, *nan*, and *inf* preferences.
- Added *negligible* argument to render.
- Added *infinity_symbol* attribute.
- Added :attr:`Quantity.infinity_symbol` attribute.
- Changed the return values for :meth:`Quantity.is_nan()` and :meth:`Quantity.is_infinite()`.


Expand Down
17 changes: 10 additions & 7 deletions quantiphy/quantiphy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1876,8 +1876,8 @@ def add(self, addend, check_units=False):
def render(
self,
*,
form=None, show_units=None, prec=None, show_label=None,
strip_zeros=None, strip_radix=None, scale=None, negligible=None
form=None, show_units=None, prec=None, show_label=None, strip_zeros=None,
strip_radix=None, spacer=None, scale=None, negligible=None
):
# description {{{3
"""Convert quantity to a string.
Expand Down Expand Up @@ -1992,6 +1992,7 @@ def render(
show_units = self.show_units if show_units is None else show_units
strip_zeros = self.strip_zeros if strip_zeros is None else strip_zeros
strip_radix = self.strip_radix if strip_radix is None else strip_radix
spacer = self.spacer if spacer is None else spacer
negligible = self.negligible if negligible is None else negligible
units = self._preferred_units.get(self.units, self.units) if show_units else ''
if prec is None:
Expand Down Expand Up @@ -2114,15 +2115,15 @@ def render(
# combine mantissa, scale factor, and units and return the result {{{3
if sf_is_exp == 'unk':
sf_is_exp = (sf == eexp)
value = self._combine(mantissa, sf, units, self.spacer, sf_is_exp)
value = self._combine(mantissa, sf, units, spacer, sf_is_exp)
return self._label(value, show_label)

# fixed() {{{2
def fixed(
self,
*,
show_units=None, prec=None, show_label=None, show_commas=None,
strip_zeros=None, strip_radix=None, scale=None,
strip_zeros=None, strip_radix=None, spacer=None, scale=None,
):
# description {{{3
"""Convert quantity to fixed-point string.
Expand Down Expand Up @@ -2224,6 +2225,7 @@ def fixed(
show_commas = self.show_commas if show_commas is None else show_commas
strip_zeros = self.strip_zeros if strip_zeros is None else strip_zeros
strip_radix = self.strip_radix if strip_radix is None else strip_radix
spacer = self.spacer if spacer is None else spacer
units = self._preferred_units.get(self.units, self.units) if show_units else ''
if prec is None:
prec = self.prec
Expand Down Expand Up @@ -2286,13 +2288,13 @@ def fixed(
mantissa += '0'

# combine mantissa, scale factor and units and return result {{{3
value = self._combine(mantissa, '', units, self.spacer)
value = self._combine(mantissa, '', units, spacer)
return self._label(value, show_label)

# binary() {{{2
def binary(
self, *, show_units=None, prec=None, show_label=None,
strip_zeros=None, strip_radix=None, scale=None,
strip_zeros=None, strip_radix=None, spacer=None, scale=None,
):
# description {{{3
"""Convert quantity to string using binary scale factors.
Expand Down Expand Up @@ -2377,6 +2379,7 @@ def binary(
show_units = self.show_units if show_units is None else show_units
strip_zeros = self.strip_zeros if strip_zeros is None else strip_zeros
strip_radix = self.strip_radix if strip_radix is None else strip_radix
spacer = self.spacer if spacer is None else spacer
units = self._preferred_units.get(self.units, self.units) if show_units else ''
if prec is None:
prec = self.prec
Expand Down Expand Up @@ -2442,7 +2445,7 @@ def binary(
mantissa += '0'

# combine mantissa, scale factor and units and return result {{{3
value = self._combine(mantissa, sf, units, self.spacer, sf_is_exp)
value = self._combine(mantissa, sf, units, spacer, sf_is_exp)
return self._label(value, show_label)

# is_close() {{{2
Expand Down

0 comments on commit 2f6aa2e

Please sign in to comment.