format-multiple-errors 0.0.3__py3-none-any.whl → 0.0.4__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.
@@ -43,6 +43,10 @@ def format_multiple_errors(
43
43
  with `significant_figures` significant figures.
44
44
  "central": The central `value` is printed
45
45
  with `significant_figures` significant figures.
46
+ "largest": The largest uncertainty is printed
47
+ with `significant_figures` significant figures.
48
+ "decimal_places": Values are truncated to `significant_figures`
49
+ decimal places.
46
50
 
47
51
  significant_figures (default: 2):
48
52
  The number of significant figures to format.
@@ -68,14 +72,23 @@ def format_multiple_errors(
68
72
  normalised_value, normalised_errors
69
73
  )
70
74
 
71
- length_value = _get_length_value(
72
- normalised_value, normalised_errors, length_control
73
- )
74
- first_digit_index, decimal_places = _get_rounding_indices(
75
- length_value, significant_figures
76
- )
75
+ if length_control == "decimal_places":
76
+ if significant_figures < 0:
77
+ raise ValueError("Number of decimal places must be non-negative")
78
+ decimal_places = significant_figures
79
+ decimals_required = decimal_places > 0
80
+ else:
81
+ length_value = _get_length_value(
82
+ normalised_value, normalised_errors, length_control
83
+ )
84
+ first_digit_index, decimal_places = _get_rounding_indices(
85
+ length_value, significant_figures
86
+ )
87
+ decimals_required = _decimals_required(
88
+ first_digit_index, significant_figures, exponential
89
+ )
77
90
 
78
- if _decimals_required(first_digit_index, significant_figures, exponential):
91
+ if decimals_required:
79
92
  formatted_numbers = [f"{normalised_value:.0{decimal_places}f}"] + list(
80
93
  _format_errors_only(normalised_errors, decimal_places, abbreviate)
81
94
  )
@@ -202,10 +215,16 @@ def _get_length_value(value: float, errors: Errors, length_control: str) -> floa
202
215
  return value
203
216
 
204
217
  return length
218
+ if length_control == "largest":
219
+ length = _get_largest(errors)
220
+ if length is None:
221
+ return value
222
+
223
+ return length
205
224
 
206
225
  raise ValueError(
207
- f"{length_control} is not a value option for length_control."
208
- '(Available options are "smallest", "central".)'
226
+ f"{length_control} is not a value option for length_control. "
227
+ '(Available options are "smallest", "central", "largest".)'
209
228
  )
210
229
 
211
230
 
@@ -219,6 +238,16 @@ def _get_smallest(errors: Errors) -> float | None:
219
238
  return min(flat_errors)
220
239
 
221
240
 
241
+ def _get_largest(errors: Errors) -> float | None:
242
+ """Given a list of errors (number or tuples of two numbers),
243
+ find the largest finite number."""
244
+ flat_errors = _flatten_errors(errors, exclude=[math.inf])
245
+ if not flat_errors:
246
+ return None
247
+
248
+ return max(flat_errors)
249
+
250
+
222
251
  def _flatten_errors(errors: Errors, exclude: Set | Sequence = frozenset()) -> list:
223
252
  """Given a list of errors (number or tuples of two numbers),
224
253
  flatten it to a list of numbers."""
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: format_multiple_errors
3
- Version: 0.0.3
3
+ Version: 0.0.4
4
4
  Summary: A small widget to be able to format multiple, asymmetric errors easily.
5
5
  Author-email: Ed Bennett <e.j.bennett@swansea.ac.uk>
6
6
  Project-URL: Homepage, https://github.com/edbennett/format_multiple_errors
@@ -12,13 +12,14 @@ Requires-Python: >=3.9
12
12
  Description-Content-Type: text/markdown
13
13
  License-File: LICENSE
14
14
  Provides-Extra: tables
15
- Requires-Dist: pandas ; extra == 'tables'
16
- Requires-Dist: jinja2 ; extra == 'tables'
15
+ Requires-Dist: pandas; extra == "tables"
16
+ Requires-Dist: jinja2; extra == "tables"
17
+ Dynamic: license-file
17
18
 
18
19
  # format_multiple_errors
19
20
 
20
21
  [![Run tests](https://github.com/edbennett/format_multiple_errors/actions/workflows/pytest.yaml/badge.svg)](https://github.com/edbennett/format_multiple_errors/actions/workflows/pytest.yaml)
21
- [![Code quality](https://github.com/edbennett/format_multiple_errors/actions/workflows/codequality.yaml/badge.svg)](https://github.com/edbennett/format_multiple_errors/actions/workflows/codequality.yaml)
22
+ [![pre-commit.ci status](https://results.pre-commit.ci/badge/github/edbennett/format_multiple_errors/main.svg)](https://results.pre-commit.ci/latest/github/edbennett/format_multiple_errors/main)
22
23
 
23
24
  A small library intended to make it easy to format numbers like
24
25
 
@@ -103,6 +104,12 @@ These options may be combined:
103
104
  >>> format_multiple_errors(123.45, 3.14, (2.82, 12.91), length_control="central", significant_figures=5, latex=True, abbreviate=True, exponential=True)
104
105
  '1.2345(314)({}^{282}_{1291}) \\times 10^{2}'
105
106
 
107
+ Other options for `length_control` are:
108
+
109
+ - `"largest"`: controls the significant digits of the largest uncertainty
110
+ - `"decimal_places"`: instead sets the absolute number of decimal places,
111
+ which must be non-negative.
112
+
106
113
 
107
114
  ### Formatting DataFrames
108
115
 
@@ -0,0 +1,11 @@
1
+ format_multiple_errors/__init__.py,sha256=ZLtmZ1Pe3zyxnic-b4nhtuajNj8llWykspVPpFaN7Rc,460
2
+ format_multiple_errors/__main__.py,sha256=Jiy0F5VlGLfzkPfvAFpuZluNevVITxXrxvTf6ztH5pI,6157
3
+ format_multiple_errors/formatter.py,sha256=ypxkaUhmf8TgICk7ysUm2li_4XgZJ-02avvu5gnZOc8,11798
4
+ format_multiple_errors/pandas.py,sha256=S_-ThiTlbItx_lUngFYY547Abp5fJaNGoQGXwwHK0i4,7689
5
+ format_multiple_errors/typing.py,sha256=k0p3GDaHGXHd3zmBtNg0-cvcMzEupzN4RHaLdNvxX6U,342
6
+ format_multiple_errors-0.0.4.dist-info/licenses/LICENSE,sha256=G3SZheaYJW8JV0Njnnyfi7QwUJWh9evcPRQ-nAXi8Ro,1086
7
+ format_multiple_errors-0.0.4.dist-info/METADATA,sha256=hj6mtoIYOCPXVDCSd5Wijj0xqtooLyg9mDAf4VoCsNM,6811
8
+ format_multiple_errors-0.0.4.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
9
+ format_multiple_errors-0.0.4.dist-info/entry_points.txt,sha256=PeHYlzbvQciSJX3DWuM-Y5Xwi9Is0jO-LlUgdSkUTp4,79
10
+ format_multiple_errors-0.0.4.dist-info/top_level.txt,sha256=I_xD5oYbrw0qjNhbzAlj_sqNhLrkoJsTE_ozCqnlaZc,23
11
+ format_multiple_errors-0.0.4.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.1.0)
2
+ Generator: setuptools (82.0.1)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,11 +0,0 @@
1
- format_multiple_errors/__init__.py,sha256=ZLtmZ1Pe3zyxnic-b4nhtuajNj8llWykspVPpFaN7Rc,460
2
- format_multiple_errors/__main__.py,sha256=Jiy0F5VlGLfzkPfvAFpuZluNevVITxXrxvTf6ztH5pI,6157
3
- format_multiple_errors/formatter.py,sha256=GnfJjP4HbYXxTq-Yx1E8DhbviPqRj0t3_icPTYgQ2P0,10744
4
- format_multiple_errors/pandas.py,sha256=S_-ThiTlbItx_lUngFYY547Abp5fJaNGoQGXwwHK0i4,7689
5
- format_multiple_errors/typing.py,sha256=k0p3GDaHGXHd3zmBtNg0-cvcMzEupzN4RHaLdNvxX6U,342
6
- format_multiple_errors-0.0.3.dist-info/LICENSE,sha256=G3SZheaYJW8JV0Njnnyfi7QwUJWh9evcPRQ-nAXi8Ro,1086
7
- format_multiple_errors-0.0.3.dist-info/METADATA,sha256=-Eb_lvnUvvHl9aQTsg8Ge1GTyVLcBJ_FPe70uyFUkoQ,6580
8
- format_multiple_errors-0.0.3.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
9
- format_multiple_errors-0.0.3.dist-info/entry_points.txt,sha256=PeHYlzbvQciSJX3DWuM-Y5Xwi9Is0jO-LlUgdSkUTp4,79
10
- format_multiple_errors-0.0.3.dist-info/top_level.txt,sha256=I_xD5oYbrw0qjNhbzAlj_sqNhLrkoJsTE_ozCqnlaZc,23
11
- format_multiple_errors-0.0.3.dist-info/RECORD,,