sciform 0.32.3__py3-none-any.whl → 0.34.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sciform
3
- Version: 0.32.3
3
+ Version: 0.34.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
@@ -21,13 +21,17 @@ Description-Content-Type: text/x-rst
21
21
  License-File: LICENSE
22
22
  Provides-Extra: dev
23
23
  Requires-Dist: ruff ; extra == 'dev'
24
+ Requires-Dist: coverage ; extra == 'dev'
24
25
  Requires-Dist: sphinx ; extra == 'dev'
25
26
  Requires-Dist: sphinx-rtd-theme ; extra == 'dev'
26
27
  Requires-Dist: sphinx-toolbox ; extra == 'dev'
27
28
  Requires-Dist: numpy ; extra == 'dev'
28
- Requires-Dist: scipy ; extra == 'dev'
29
- Requires-Dist: matplotlib ; extra == 'dev'
30
- Requires-Dist: tabulate ; extra == 'dev'
29
+ Provides-Extra: examples
30
+ Requires-Dist: numpy ; extra == 'examples'
31
+ Requires-Dist: scipy ; extra == 'examples'
32
+ Requires-Dist: matplotlib ; extra == 'examples'
33
+ Requires-Dist: tabulate ; extra == 'examples'
34
+ Requires-Dist: jupyter ; extra == 'examples'
31
35
 
32
36
  .. image:: https://www.repostatus.org/badges/latest/wip.svg
33
37
  :target: https://www.repostatus.org/#wip
@@ -128,18 +132,22 @@ You can view the on-going review
128
132
  Usage
129
133
  =====
130
134
 
135
+ Here we provide a few key usage examples.
136
+ For many more details see
137
+ `Usage <https://sciform.readthedocs.io/en/stable/usage.html>`_.
138
+
131
139
  ``sciform`` provides a wide variety of formatting options which can be
132
140
  controlled when constructing ``Formatter`` objects which are then used
133
141
  to format numbers into strings according to the selected options.
134
142
 
135
143
  >>> from sciform import Formatter
136
- >>> sform = Formatter(
144
+ >>> formatter = Formatter(
137
145
  ... round_mode="dec_place", ndigits=6, upper_separator=" ", lower_separator=" "
138
146
  ... )
139
- >>> print(sform(51413.14159265359))
147
+ >>> print(formatter(51413.14159265359))
140
148
  51 413.141 593
141
- >>> sform = Formatter(round_mode="sig_fig", ndigits=4, exp_mode="engineering")
142
- >>> print(sform(123456.78))
149
+ >>> formatter = Formatter(round_mode="sig_fig", ndigits=4, exp_mode="engineering")
150
+ >>> print(formatter(123456.78))
143
151
  123.5e+03
144
152
 
145
153
  Users can also format numbers by constructing ``SciNum`` objects and
@@ -158,11 +166,11 @@ to format pairs of numbers as value/uncertainty pairs.
158
166
  This can be done by passing two numbers into a ``Formatter`` call or by
159
167
  using the ``SciNum`` object.
160
168
 
161
- >>> sform = Formatter(ndigits=2, upper_separator=" ", lower_separator=" ")
162
- >>> print(sform(123456.654321, 0.00345))
169
+ >>> formatter = Formatter(ndigits=2, upper_separator=" ", lower_separator=" ")
170
+ >>> print(formatter(123456.654321, 0.00345))
163
171
  123 456.654 3 ± 0.003 4
164
- >>> sform = Formatter(ndigits=4, exp_mode="engineering")
165
- >>> print(sform(123456.654321, 0.00345))
172
+ >>> formatter = Formatter(ndigits=4, exp_mode="engineering")
173
+ >>> print(formatter(123456.654321, 0.00345))
166
174
  (123.456654321 ± 0.000003450)e+03
167
175
 
168
176
  >>> num = SciNum(123456.654321, 0.00345)
@@ -0,0 +1,23 @@
1
+ sciform/__init__.py,sha256=S6-oZ4wA-h2iFlpUhrRLDSycdn5b8kRd5s5xGI64-a8,844
2
+ sciform/format_utils.py,sha256=JNFlSxxM9K3M1KI5oLyTsPPzAsvgKDQAGgxPN3wqG_I,16545
3
+ sciform/formatter.py,sha256=paVP2I6IO9y7lvkFB7_tMGFikfp7MS9PSlSG5zPWrzQ,15057
4
+ sciform/formatting.py,sha256=Z2jLIeuqMm6JWd_FurJ_-rU0Yr96jT-tb8CYEzjPgZA,12228
5
+ sciform/fsml.py,sha256=r22RiBPrkDaiPgE2VQrtGms9aBmWqolymsmmnp-z57s,3378
6
+ sciform/global_configuration.py,sha256=L3nORbdGOO6ZZk8Xv81lr8S95Od35CgxlpOsdJDxs44,6964
7
+ sciform/grouping.py,sha256=1hZjjVKRUy477LGGFniZwwEHHBDaSb6E0K3SAeCACVY,1641
8
+ sciform/modes.py,sha256=8slohyIPHeAdgq3aszoNq9RJl6ibageFqDMxeC9NhrQ,3893
9
+ sciform/output_conversion.py,sha256=IwylcmSXdfIZlVaa7fplL0E0F6JdtJyoHC_T9ZwGYo8,5489
10
+ sciform/prefix.py,sha256=1rJeKMs8m97V3ZvMzHikqXLDDINp9aEK0AI3YaCcRMw,596
11
+ sciform/scinum.py,sha256=oqbXiENMwELQmhVF7sR6fcnBECqDV8GNyOLNIrNIB9I,1857
12
+ sciform/options/__init__.py,sha256=tw_CZHaNrdixZoQyG6ZD5UMKkQxXok0qBQCxt28Gh20,51
13
+ sciform/options/conversion.py,sha256=ReqASoGNQIfa-r5-HEGZxokENti_NRkAjRP-zrxY0EU,4124
14
+ sciform/options/finalized_options.py,sha256=PNcoAiB_WccbqxRJ5o_WPLnqb_n3J_MDpFTKqJxdSBM,1388
15
+ sciform/options/global_options.py,sha256=8493K2Yu47D8-Dr6rgVWVKAVo-aAVaPzFNEpG7X0IAk,782
16
+ sciform/options/input_options.py,sha256=gGUhuZr_t89IVhHwpEbtzLV9hvjMXVdMCgwe9OghO4k,3788
17
+ sciform/options/populated_options.py,sha256=rVExq0YXzpk9kk-KUVm2oGXQEH56jBDGtZZ2vTqLqqo,4999
18
+ sciform/options/validation.py,sha256=O1UTe5yHA0eN7sTtDsMNBh-1t3C-lbPayGoW9kn7FSU,3527
19
+ sciform-0.34.0.dist-info/LICENSE,sha256=-oyCEZu-6HLrRSfRg44uuNDE0c59GVEdqYIgidqSP70,1056
20
+ sciform-0.34.0.dist-info/METADATA,sha256=wZhvWEVrSkst3jLEYmpX5imgbzg0IatMk861S37M0f4,8002
21
+ sciform-0.34.0.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
22
+ sciform-0.34.0.dist-info/top_level.txt,sha256=mC01YOQ-1u5pDk9BJia-pQKLUMvkreMsldDpFcp7NV8,8
23
+ sciform-0.34.0.dist-info/RECORD,,
sciform/user_options.py DELETED
@@ -1,189 +0,0 @@
1
- """UserOptions Dataclass which stores user input."""
2
-
3
-
4
- from __future__ import annotations
5
-
6
- from dataclasses import InitVar, asdict, dataclass
7
- from typing import get_args
8
-
9
- from sciform import global_options, modes
10
- from sciform.rendered_options import RenderedOptions
11
-
12
-
13
- @dataclass(frozen=True)
14
- class UserOptions:
15
- """Dataclass storing user input."""
16
-
17
- exp_mode: modes.ExpMode | None = None
18
- exp_val: int | type(modes.AutoExpVal) | None = None
19
- round_mode: modes.RoundMode | None = None
20
- ndigits: int | type(modes.AutoDigits) | None = None
21
- upper_separator: modes.UpperSeparators | None = None
22
- decimal_separator: modes.DecimalSeparators | None = None
23
- lower_separator: modes.LowerSeparators | None = None
24
- sign_mode: modes.SignMode | None = None
25
- fill_char: modes.FillChar | None = None
26
- left_pad_dec_place: int | None = None
27
- exp_format: modes.ExpFormat | None = None
28
- extra_si_prefixes: dict[int, str] | None = None
29
- extra_iec_prefixes: dict[int, str] | None = None
30
- extra_parts_per_forms: dict[int, str] | None = None
31
- capitalize: bool | None = None
32
- superscript: bool | None = None
33
- latex: bool | None = None
34
- nan_inf_exp: bool | None = None
35
- paren_uncertainty: bool | None = None
36
- pdg_sig_figs: bool | None = None
37
- left_pad_matching: bool | None = None
38
- paren_uncertainty_separators: bool | None = None
39
- pm_whitespace: bool | None = None
40
-
41
- add_c_prefix: InitVar[bool] = False
42
- add_small_si_prefixes: InitVar[bool] = False
43
- add_ppth_form: InitVar[bool] = False
44
-
45
- def __post_init__(
46
- self: UserOptions,
47
- add_c_prefix: bool, # noqa: FBT001
48
- add_small_si_prefixes: bool, # noqa: FBT001
49
- add_ppth_form: bool, # noqa: FBT001
50
- ) -> None:
51
- self.populate_dicts(
52
- add_c_prefix=add_c_prefix,
53
- add_small_si_prefixes=add_small_si_prefixes,
54
- add_ppth_form=add_ppth_form,
55
- )
56
- self.validate(self)
57
-
58
- def populate_dicts( # noqa: C901
59
- self: UserOptions,
60
- *,
61
- add_c_prefix: bool,
62
- add_small_si_prefixes: bool,
63
- add_ppth_form: bool,
64
- ) -> None:
65
- """Populate extra prefix translations from user input flags."""
66
- if add_c_prefix:
67
- if self.extra_si_prefixes is None:
68
- super().__setattr__("extra_si_prefixes", {})
69
- if -2 not in self.extra_si_prefixes:
70
- self.extra_si_prefixes[-2] = "c"
71
-
72
- if add_small_si_prefixes:
73
- if self.extra_si_prefixes is None:
74
- super().__setattr__("extra_si_prefixes", {})
75
- if -2 not in self.extra_si_prefixes:
76
- self.extra_si_prefixes[-2] = "c"
77
- if -1 not in self.extra_si_prefixes:
78
- self.extra_si_prefixes[-1] = "d"
79
- if +1 not in self.extra_si_prefixes:
80
- self.extra_si_prefixes[+1] = "da"
81
- if +2 not in self.extra_si_prefixes:
82
- self.extra_si_prefixes[+2] = "h"
83
-
84
- if add_ppth_form:
85
- if self.extra_parts_per_forms is None:
86
- super().__setattr__("extra_parts_per_forms", {})
87
- if -3 not in self.extra_parts_per_forms:
88
- self.extra_parts_per_forms[-3] = "ppth"
89
-
90
- @staticmethod
91
- def validate(options: UserOptions | RenderedOptions) -> None:
92
- """Validate user inputs."""
93
- if (
94
- options.round_mode == "sig_fig"
95
- and isinstance(options.ndigits, int)
96
- and options.ndigits < 1
97
- ):
98
- msg = f"ndigits must be >= 1 for sig fig rounding, not {options.ndigits}."
99
- raise ValueError(msg)
100
-
101
- if options.exp_val is not modes.AutoExpVal and options.exp_val is not None:
102
- if options.exp_mode in ["fixed_point", "percent"] and options.exp_val != 0:
103
- msg = (
104
- f"Exponent must must be 0, not exp_val={options.exp_val}, for "
105
- f"fixed point and percent exponent modes."
106
- )
107
- raise ValueError(msg)
108
- if (
109
- options.exp_mode in ["engineering", "engineering_shifted"]
110
- and options.exp_val % 3 != 0
111
- ):
112
- msg = (
113
- f"Exponent must be a multiple of 3, not exp_val={options.exp_val}, "
114
- f"for engineering exponent modes."
115
- )
116
- raise ValueError(msg)
117
- if options.exp_mode == "binary_iec" and options.exp_val % 10 != 0:
118
- msg = (
119
- f"Exponent must be a multiple of 10, not "
120
- f"exp_val={options.exp_val}, for binary IEC exponent mode."
121
- )
122
- raise ValueError(msg)
123
-
124
- UserOptions.validate_separators(options)
125
-
126
- @staticmethod
127
- def validate_separators(options: UserOptions | RenderedOptions) -> None:
128
- """Validate separator user input."""
129
- if options.upper_separator is not None:
130
- if options.upper_separator not in get_args(modes.UpperSeparators):
131
- msg = (
132
- f"upper_separator must be in "
133
- f"{get_args(modes.UpperSeparators)}, not "
134
- f"{options.upper_separator}."
135
- )
136
- raise ValueError(msg)
137
- if options.upper_separator == options.decimal_separator:
138
- msg = (
139
- f"upper_separator and decimal_separator "
140
- f"({options.upper_separator}) cannot be equal."
141
- )
142
- raise ValueError(msg)
143
-
144
- if options.decimal_separator is not None and (
145
- options.decimal_separator not in get_args(modes.DecimalSeparators)
146
- ):
147
- msg = (
148
- f"decimal_separator must be in "
149
- f"{get_args(modes.DecimalSeparators)}, not "
150
- f"{options.decimal_separator}."
151
- )
152
- raise ValueError(msg)
153
-
154
- if options.lower_separator is not None and (
155
- options.lower_separator not in get_args(modes.LowerSeparators)
156
- ):
157
- msg = (
158
- f"lower_separator must be in {get_args(modes.LowerSeparators)}, "
159
- f"not {options.lower_separator}."
160
- )
161
- raise ValueError(msg)
162
-
163
- def render(self: UserOptions) -> RenderedOptions:
164
- """Render UserOptions into RenderedOptions."""
165
- key_to_enum_dict = {
166
- "exp_mode": modes.ExpModeEnum,
167
- "round_mode": modes.RoundModeEnum,
168
- "upper_separator": modes.SeparatorEnum,
169
- "decimal_separator": modes.SeparatorEnum,
170
- "lower_separator": modes.SeparatorEnum,
171
- "sign_mode": modes.SignModeEnum,
172
- "fill_char": modes.FillCharEnum,
173
- "exp_format": modes.ExpFormatEnum,
174
- }
175
-
176
- global_defaults_dict = asdict(global_options.GLOBAL_DEFAULT_OPTIONS)
177
- kwargs = {}
178
- for key, value in asdict(self).items():
179
- if value is None:
180
- rendered_value = global_defaults_dict[key]
181
- elif isinstance(value, str):
182
- enum = key_to_enum_dict[key]
183
- rendered_value = modes.mode_str_to_enum(value, enum)
184
- else:
185
- rendered_value = value
186
- kwargs[key] = rendered_value
187
- rendered_options = RenderedOptions(**kwargs)
188
- self.validate(rendered_options)
189
- return rendered_options
@@ -1,18 +0,0 @@
1
- sciform/__init__.py,sha256=wlDN6uPm7XjcbFzDA9l7m_twcT59DkBWtox_Pss-j0k,558
2
- sciform/format_utils.py,sha256=rLC8o_2c0kGNi5jA2VCZIcw2241onw74OR-2RcTM4X4,18522
3
- sciform/formatter.py,sha256=fh7wVDbcNt6V0oQSufMqo1AYHy6hXNODbU0Yj3WvKh4,11653
4
- sciform/formatting.py,sha256=LXk7DnVnQIR2crCLvrxl0DhnDubGYEgLond5lwIKZxU,9505
5
- sciform/fsml.py,sha256=Q9fSQijNQ0Tjf8HRM3ok9_6xzY-yQuvUDxhlQX6eeTA,3345
6
- sciform/global_configuration.py,sha256=PoLi-ZXtrn4pYTpwo4EFhYSeiTBrQ6eYftWjooudqRE,6826
7
- sciform/global_options.py,sha256=UZXbpGog0CpqUvYaYebfnUWeh3HOobZn65J4H5KU1aw,946
8
- sciform/grouping.py,sha256=1hZjjVKRUy477LGGFniZwwEHHBDaSb6E0K3SAeCACVY,1641
9
- sciform/modes.py,sha256=YADkmk7UVp9egyc3rwiV0UfLD40sGPl0w4yOoIIo1dg,4001
10
- sciform/prefix.py,sha256=1rJeKMs8m97V3ZvMzHikqXLDDINp9aEK0AI3YaCcRMw,596
11
- sciform/rendered_options.py,sha256=gb-RBOth0P7o9L4VH97bkBiD56oZBzQP_BWrf_qJqOA,1582
12
- sciform/scinum.py,sha256=H29BrxPYakGkdAKmrCYnj91g0u6c_fym5Kh-kNsnNy8,1926
13
- sciform/user_options.py,sha256=KnXCMwZZ8np6wLPZ_YlvSZ78m_FzyMOefm6OMwxvtu4,7406
14
- sciform-0.32.3.dist-info/LICENSE,sha256=-oyCEZu-6HLrRSfRg44uuNDE0c59GVEdqYIgidqSP70,1056
15
- sciform-0.32.3.dist-info/METADATA,sha256=GazcbkZ0HyVSgMHKIuIsd1yGOyTMOW2o0Fhy_-pcHLQ,7668
16
- sciform-0.32.3.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
17
- sciform-0.32.3.dist-info/top_level.txt,sha256=mC01YOQ-1u5pDk9BJia-pQKLUMvkreMsldDpFcp7NV8,8
18
- sciform-0.32.3.dist-info/RECORD,,