From 2f6aa2eabfa1a4b3bf3aafe0c5b5cdaa9dc8a5a3 Mon Sep 17 00:00:00 2001 From: Ken Kundert Date: Sun, 23 Jun 2024 14:46:34 -0700 Subject: [PATCH] Add spacer keyword argument to Quantity.{render,fixed,binary} --- doc/Makefile | 2 +- doc/conf.py | 6 ++++++ doc/releases.rst | 6 +++++- quantiphy/quantiphy.py | 17 ++++++++++------- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/doc/Makefile b/doc/Makefile index 776bd02..f55dcdf 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -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 diff --git a/doc/conf.py b/doc/conf.py index ea3d13c..62da770 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -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 +] diff --git a/doc/releases.rst b/doc/releases.rst index 04c6e00..0a3d07c 100644 --- a/doc/releases.rst +++ b/doc/releases.rst @@ -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) ----------------- @@ -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()`. diff --git a/quantiphy/quantiphy.py b/quantiphy/quantiphy.py index 2339a50..d8cb76d 100644 --- a/quantiphy/quantiphy.py +++ b/quantiphy/quantiphy.py @@ -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. @@ -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: @@ -2114,7 +2115,7 @@ 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 @@ -2122,7 +2123,7 @@ 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. @@ -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 @@ -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. @@ -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 @@ -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