sciform 0.28.1__py3-none-any.whl → 0.29.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
sciform/format_options.py CHANGED
@@ -54,8 +54,8 @@ ExpReplaceDict = dict[int, Union[str, None]]
54
54
  class FormatOptions:
55
55
  # TODO: __repr__
56
56
  """
57
- :class:`FormatOptions` stores all the configuration options used to
58
- format numbers and number/uncertainty pairs. See
57
+ :class:`FormatOptions` instances store all the configuration options
58
+ used to format numbers and number/uncertainty pairs. See
59
59
  :ref:`formatting_options` for more details on the available options.
60
60
  :class:`FormatOptions` instances are used to create
61
61
  :class:`Formatter` instances and to modify the global default
@@ -87,8 +87,8 @@ class FormatOptions:
87
87
  * ``lower_separator`` may only be :class:`GroupingSeparator.NONE`,
88
88
  :class:`GroupingSeparator.SPACE`, or
89
89
  :class:`GroupingSeparator.UNDERSCORE`
90
- * ``ndigits=None`` or ``ndigits=AutoDigits`` if
91
- ``pdg_sig_figs=True``
90
+ * if ``pdg_sig_figs=True`` then ``ndigits=None`` or
91
+ ``ndigits=AutoDigits``.
92
92
 
93
93
  :param exp_mode: :class:`ExpMode` indicating the formatting
94
94
  mode to be used.
@@ -138,33 +138,35 @@ class FormatOptions:
138
138
  mapping additional exponent values to "parts-per" forms. Entries
139
139
  overwrite default values. A value of ``None`` means that exponent
140
140
  will not be converted.
141
- :param capitalize: :class:`bool` indicating whether the exponentiation
142
- symbol should be upper- or lower-case.
143
- :param superscript_exp: :class:`bool` indicating if the exponent string
144
- should be converted into superscript notation. E.g. ``'1.23e+02'``
145
- is converted to ``'1.23×10²'``
146
- :param latex: :class:`bool` indicating if the resulting string should be
147
- converted into a latex parseable code, e.g.
141
+ :param capitalize: :class:`bool` indicating whether the
142
+ exponentiation symbol should be upper- or lower-case.
143
+ :param superscript_exp: :class:`bool` indicating if the exponent
144
+ string should be converted into superscript notation. E.g.
145
+ ``'1.23e+02'`` is converted to ``'1.23×10²'``
146
+ :param latex: :class:`bool` indicating if the resulting string
147
+ should be converted into a latex parseable code, e.g.
148
148
  ``'\\left(1.23 \\pm 0.01\\right)\\times 10^{2}'``.
149
- :param nan_inf_exp: :class:`bool` indicating whether non-finite numbers
150
- such as ``float('nan')`` or ``float('inf')`` should be formatted
151
- with exponent symbols when exponent modes including exponent
152
- symbols are selected.
153
- :param bracket_unc: :class:`bool` indicating if bracket uncertainty mode
154
- (e.g. ``12.34(82)`` instead of ``12.34 +/- 0.82``) should be used.
149
+ :param nan_inf_exp: :class:`bool` indicating whether non-finite
150
+ numbers such as ``float('nan')`` or ``float('inf')`` should be
151
+ formatted with exponent symbols when exponent modes including
152
+ exponent symbols are selected.
153
+ :param bracket_unc: :class:`bool` indicating if bracket uncertainty
154
+ mode (e.g. ``12.34(82)`` instead of ``12.34 +/- 0.82``) should be
155
+ used.
155
156
  :param pdg_sig_figs: :class:`bool` indicating whether the
156
157
  particle-data-group conventions should be used to automatically
157
158
  determine the number of significant figures to use for
158
159
  uncertainty.
159
- :param val_unc_match_widths: :class:`bool` indicating if the value or
160
- uncertainty should be left padded to ensure they are both left
160
+ :param val_unc_match_widths: :class:`bool` indicating if the value
161
+ or uncertainty should be left padded to ensure they are both left
161
162
  padded to the same digits place.
162
- :param bracket_unc_remove_seps: :class:`bool` indicating if separator
163
- symbols should be removed from the uncertainty when using bracket
164
- uncertainty mode. E.g. expressing ``123.4 +/- 2.3`` as
165
- ``123.4(23)`` instead of ``123.4(2.3)``.
166
- :param unicode_pm: :class:`bool` indicating if the '+/-' separator should
167
- be replaced with the unicode plus minus symbol '±'.
163
+ :param bracket_unc_remove_seps: :class:`bool` indicating if
164
+ separator symbols should be removed from the uncertainty when
165
+ using bracket uncertainty mode. E.g. expressing ``123.4 +/- 2.3``
166
+ as ``123.4(23)`` instead of ``123.4(2.3)``.
167
+ :param unicode_pm: :class:`bool` indicating if the ``'+/-'``
168
+ separator should be replaced with the unicode plus minus symbol
169
+ ``'±'``.
168
170
  :param unc_pm_whitespace: :class:`bool` indicating if there should be
169
171
  whitespace surrounding the ``'+/-'`` symbols when formatting. E.g.
170
172
  ``123.4+/-2.3`` compared to ``123.4 +/- 2.3``.
@@ -238,11 +240,11 @@ class FormatOptions:
238
240
  """
239
241
  Generate a new :class:`FormatOptions` instance from the current
240
242
  instance and another :class:`FormatOptions` instance,
241
- ``other``. The options for the new :class:`FormatOptions` are
242
- constructed by replacing the options from the current instance
243
- by any filled options from ``other``. Note that, even after
244
- merging, the resulting :class:`FormatOptions` may still have
245
- unfilled options.
243
+ ``other``. The options for the new :class:`FormatOptions`
244
+ instance are constructed by replacing the options from the
245
+ current instance by any filled options from ``other``. Note
246
+ that, even after merging, the resulting :class:`FormatOptions`
247
+ may still have unfilled options.
246
248
 
247
249
  :param other: :class:`FormatOptions` instance containing options
248
250
  that will overwrite those of the current instance.
@@ -260,7 +262,7 @@ class FormatOptions:
260
262
  **_merge_dicts(asdict(defaults), asdict(self))
261
263
  )
262
264
  except ValueError as e:
263
- raise ValueError('Invalid format options resuling from merging '
265
+ raise ValueError('Invalid format options resulting from merging '
264
266
  'with default options.') from e
265
267
 
266
268
  return rendered_format_options
@@ -273,7 +275,7 @@ def validate_options(options: Union[FormatOptions, RenderedFormatOptions]):
273
275
  if options.round_mode is RoundMode.SIG_FIG:
274
276
  if isinstance(options.ndigits, int):
275
277
  if options.ndigits < 1:
276
- raise ValueError(f'Precision must be >= 1 for sig fig '
278
+ raise ValueError(f'ndigits must be >= 1 for sig fig '
277
279
  f'rounding, not {options.ndigits}.')
278
280
 
279
281
  if (options.pdg_sig_figs and options.ndigits is not None
sciform/format_utils.py CHANGED
@@ -252,7 +252,7 @@ def get_pdg_round_digit(num: Decimal) -> int:
252
252
  top_digit = get_top_digit(num)
253
253
 
254
254
  # Bring num to be between 100 and 1000.
255
- num_top_three_digs = num * 10 ** (2 - top_digit)
255
+ num_top_three_digs = num * Decimal(10) ** (Decimal(2) - Decimal(top_digit))
256
256
  num_top_three_digs = round(num_top_three_digs, 0)
257
257
  new_top_digit = get_top_digit(num_top_three_digs)
258
258
  num_top_three_digs = num_top_three_digs * 10 ** (2 - new_top_digit)
sciform/formatting.py CHANGED
@@ -86,7 +86,7 @@ def format_num(num: Decimal, unrendered_options: FormatOptions) -> str:
86
86
  mantissa, exp_val, base = get_mantissa_exp_base(rounded_num, exp_mode,
87
87
  exp_val)
88
88
  round_digit = get_round_digit(mantissa, round_mode, ndigits)
89
- mantissa_rounded = Decimal(round(mantissa, -int(round_digit)))
89
+ mantissa_rounded = round(mantissa, -int(round_digit))
90
90
 
91
91
  if mantissa_rounded == 0:
92
92
  '''
@@ -318,7 +318,10 @@ def format_val_unc(val: Decimal, unc: Decimal,
318
318
  extra_iec_prefixes=options.extra_iec_prefixes,
319
319
  extra_parts_per_forms=options.extra_parts_per_forms
320
320
  )
321
- val_unc_exp_str = f'({val_unc_str}){exp_str}'
321
+ if options.bracket_unc and not re.match(r'^[eEbB][+-]\d+$', exp_str):
322
+ val_unc_exp_str = f'{val_unc_str}{exp_str}'
323
+ else:
324
+ val_unc_exp_str = f'({val_unc_str}){exp_str}'
322
325
  else:
323
326
  val_unc_exp_str = val_unc_str
324
327
 
sciform/fsml.py CHANGED
@@ -117,7 +117,7 @@ def format_options_from_fmt_spec(fmt_spec: str) -> 'FormatOptions':
117
117
  if prefix_exp is not None:
118
118
  exp_format = ExpFormat.PREFIX
119
119
  else:
120
- exp_format = ExpFormat.STANDARD
120
+ exp_format = None
121
121
 
122
122
  bracket_unc = match.group('bracket_unc')
123
123
  if bracket_unc is not None:
sciform/scinum.py CHANGED
@@ -8,7 +8,7 @@ from sciform.fsml import format_options_from_fmt_spec
8
8
  class SciNum:
9
9
  """
10
10
  :class:`SciNum` objects are used in combination with the
11
- :mod:`sciform` format specification mini language for scientific
11
+ :mod:`sciform` format specification mini-language for scientific
12
12
  formatting of numbers. Any options not configured by the format
13
13
  specification will be populated with global default settings at
14
14
  format time.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sciform
3
- Version: 0.28.1
3
+ Version: 0.29.0
4
4
  Summary: A package for formatting numbers into scientific formatted strings.
5
5
  Author-email: Justin Gerber <justin.gerber48@gmail.com>
6
6
  Project-URL: homepage, https://github.com/jagerber48/sciform
@@ -77,7 +77,7 @@ continue to change until version ``1.0.0`` is released.
77
77
  API changes will be announced after new releases in the
78
78
  `changelog <https://sciform.readthedocs.io/en/stable/project.html#changelog>`_.
79
79
  If you have an idea or opinion about how ``sciform`` should be designed,
80
- now is a great to
80
+ now is a great time to
81
81
  `post a discussion topic <https://github.com/jagerber48/sciform/discussions>`_
82
82
  about it!
83
83
 
@@ -107,19 +107,6 @@ strings according to the selected options.
107
107
  >>> print(sform(123456.78))
108
108
  123.5e+03
109
109
 
110
- For brevity, the user may consider abbreviating ``FormatOptions`` as
111
- ``Fo``.
112
-
113
- >>> from sciform import (Formatter, FormatOptions, RoundMode,
114
- ... GroupingSeparator, ExpMode)
115
- >>> sform = Formatter(FormatOptions(
116
- ... round_mode=RoundMode.DEC_PLACE,
117
- ... ndigits=6,
118
- ... upper_separator=GroupingSeparator.SPACE,
119
- ... lower_separator=GroupingSeparator.SPACE))
120
- >>> print(sform(51413.14159265359))
121
- 51 413.141 593
122
-
123
110
  Users can also format numbers by constructing ``SciNum`` objects and
124
111
  using string formatting to format the ``SciNum`` instances according
125
112
  to a custom FSML.
@@ -0,0 +1,15 @@
1
+ sciform/__init__.py,sha256=kAgKCR6uDXlmzpUIrHwMG607sTvPc5UEOZGE5zKDJ8s,1104
2
+ sciform/format_options.py,sha256=Yk0Xo-wkremjo0Lw_VoZ_8Fwj31gBIwQxnYm6jif19c,19219
3
+ sciform/format_utils.py,sha256=MGJ0Tsoa6iYHn8PJqa6XDr-cT3bRQwLd0u0sqhQomHE,11599
4
+ sciform/formatter.py,sha256=qLK94AqZQ4vv7fLEYIXEJzL0abfE7vfB62npwmzHveE,2091
5
+ sciform/formatting.py,sha256=82K38NFsgDuO7P5L2hGuVHY44hPm9vfzVLCZPkN-EFY,11704
6
+ sciform/fsml.py,sha256=8IbONNU1pSGRmF6_3t-8go_nLOe0yISAkEEUS2bPWdw,4697
7
+ sciform/grouping.py,sha256=t_M33mUIa0e7y8YuYe395dpOrX0QJiwPHC76NRPMcWs,2324
8
+ sciform/modes.py,sha256=xLeffIzlbNSApoBvl0u0GAQrk92XveLKeP0kjyeiz_c,4105
9
+ sciform/prefix.py,sha256=5JpmaqGpoZ7uApq6YkaGb0txjL-VT1AkEsRO6gihX7Q,1186
10
+ sciform/scinum.py,sha256=bTprldmCgLYPSyM9j8qLt--DqnTfBVfMGoneqby8oFI,2068
11
+ sciform-0.29.0.dist-info/LICENSE,sha256=-oyCEZu-6HLrRSfRg44uuNDE0c59GVEdqYIgidqSP70,1056
12
+ sciform-0.29.0.dist-info/METADATA,sha256=ELJLYio4-4qGbqggyPh-54wG5Ie24BtOl2W-jbvaFXI,5766
13
+ sciform-0.29.0.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
14
+ sciform-0.29.0.dist-info/top_level.txt,sha256=mC01YOQ-1u5pDk9BJia-pQKLUMvkreMsldDpFcp7NV8,8
15
+ sciform-0.29.0.dist-info/RECORD,,
@@ -1,15 +0,0 @@
1
- sciform/__init__.py,sha256=kAgKCR6uDXlmzpUIrHwMG607sTvPc5UEOZGE5zKDJ8s,1104
2
- sciform/format_options.py,sha256=5HDw1pWKHhdRarDQMm7RhWLkEwUlXYB1MlT57Q3n3N8,19176
3
- sciform/format_utils.py,sha256=ZGAIe0Ck6qYaHtBxoLWn6dIOD6o2JJA3s6kEcXYHLAo,11572
4
- sciform/formatter.py,sha256=qLK94AqZQ4vv7fLEYIXEJzL0abfE7vfB62npwmzHveE,2091
5
- sciform/formatting.py,sha256=eRFuPf90jXkJIfV9J3p1Lj7FQLvEDWTQ1SPQ9H7PqsU,11561
6
- sciform/fsml.py,sha256=0J7ovJS9T62w9mqDTYQKdq30ncg1sqf3K8UWTQL9sAU,4711
7
- sciform/grouping.py,sha256=t_M33mUIa0e7y8YuYe395dpOrX0QJiwPHC76NRPMcWs,2324
8
- sciform/modes.py,sha256=xLeffIzlbNSApoBvl0u0GAQrk92XveLKeP0kjyeiz_c,4105
9
- sciform/prefix.py,sha256=5JpmaqGpoZ7uApq6YkaGb0txjL-VT1AkEsRO6gihX7Q,1186
10
- sciform/scinum.py,sha256=mipjJYBzy77HgU5ObXwXHjGj5H3U6Ct6m1HHoAQ8pq8,2068
11
- sciform-0.28.1.dist-info/LICENSE,sha256=-oyCEZu-6HLrRSfRg44uuNDE0c59GVEdqYIgidqSP70,1056
12
- sciform-0.28.1.dist-info/METADATA,sha256=-LZZFN6AeRAyAO91VV0w8LoBFX_CT5WPd9z6UZMlv0o,6233
13
- sciform-0.28.1.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
14
- sciform-0.28.1.dist-info/top_level.txt,sha256=mC01YOQ-1u5pDk9BJia-pQKLUMvkreMsldDpFcp7NV8,8
15
- sciform-0.28.1.dist-info/RECORD,,