sciform 0.32.3__tar.gz → 0.34.0__tar.gz
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-0.32.3 → sciform-0.34.0}/.github/workflows/python-package.yml +15 -11
- {sciform-0.32.3 → sciform-0.34.0}/.github/workflows/python-publish.yml +2 -2
- {sciform-0.32.3 → sciform-0.34.0}/CHANGELOG.rst +143 -0
- {sciform-0.32.3/src/sciform.egg-info → sciform-0.34.0}/PKG-INFO +20 -12
- {sciform-0.32.3 → sciform-0.34.0}/README.rst +12 -8
- sciform-0.34.0/docs/source/api.rst +49 -0
- {sciform-0.32.3 → sciform-0.34.0}/docs/source/conf.py +2 -0
- {sciform-0.32.3 → sciform-0.34.0}/docs/source/examples.rst +50 -57
- {sciform-0.32.3 → sciform-0.34.0}/docs/source/exp replacement.rst +3 -3
- {sciform-0.32.3 → sciform-0.34.0}/docs/source/fsml.rst +17 -17
- {sciform-0.32.3 → sciform-0.34.0}/docs/source/options.rst +132 -172
- {sciform-0.32.3 → sciform-0.34.0}/docs/source/usage.rst +346 -67
- sciform-0.34.0/examples/jupyter_output_example.ipynb +50 -0
- sciform-0.34.0/examples/outputs/jupyter_output.png +0 -0
- {sciform-0.32.3 → sciform-0.34.0}/pyproject.toml +12 -0
- sciform-0.34.0/src/sciform/__init__.py +30 -0
- {sciform-0.32.3 → sciform-0.34.0}/src/sciform/format_utils.py +26 -94
- {sciform-0.32.3 → sciform-0.34.0}/src/sciform/formatter.py +154 -56
- {sciform-0.32.3 → sciform-0.34.0}/src/sciform/formatting.py +99 -30
- {sciform-0.32.3 → sciform-0.34.0}/src/sciform/fsml.py +7 -7
- {sciform-0.32.3 → sciform-0.34.0}/src/sciform/global_configuration.py +39 -36
- {sciform-0.32.3 → sciform-0.34.0}/src/sciform/modes.py +3 -10
- sciform-0.34.0/src/sciform/options/__init__.py +1 -0
- sciform-0.34.0/src/sciform/options/conversion.py +120 -0
- sciform-0.32.3/src/sciform/rendered_options.py → sciform-0.34.0/src/sciform/options/finalized_options.py +8 -13
- {sciform-0.32.3/src/sciform → sciform-0.34.0/src/sciform/options}/global_options.py +10 -11
- sciform-0.34.0/src/sciform/options/input_options.py +104 -0
- sciform-0.34.0/src/sciform/options/populated_options.py +136 -0
- sciform-0.34.0/src/sciform/options/validation.py +101 -0
- sciform-0.34.0/src/sciform/output_conversion.py +168 -0
- {sciform-0.32.3 → sciform-0.34.0}/src/sciform/scinum.py +13 -12
- {sciform-0.32.3 → sciform-0.34.0/src/sciform.egg-info}/PKG-INFO +20 -12
- {sciform-0.32.3 → sciform-0.34.0}/src/sciform.egg-info/SOURCES.txt +13 -5
- {sciform-0.32.3 → sciform-0.34.0}/src/sciform.egg-info/requires.txt +5 -0
- {sciform-0.32.3 → sciform-0.34.0}/tests/test_config.py +16 -16
- sciform-0.34.0/tests/test_docstrings.py +13 -0
- {sciform-0.32.3 → sciform-0.34.0}/tests/test_float_formatter.py +26 -69
- {sciform-0.32.3 → sciform-0.34.0}/tests/test_float_fsml.py +5 -6
- {sciform-0.32.3 → sciform-0.34.0}/tests/test_invalid_options.py +29 -19
- {sciform-0.32.3 → sciform-0.34.0}/tests/test_modes_strings.py +2 -2
- sciform-0.34.0/tests/test_options_printout.py +125 -0
- sciform-0.34.0/tests/test_output_conversion.py +478 -0
- {sciform-0.32.3 → sciform-0.34.0}/tests/test_separators.py +6 -6
- {sciform-0.32.3 → sciform-0.34.0}/tests/test_val_unc_formatter.py +27 -56
- {sciform-0.32.3 → sciform-0.34.0}/tests/test_val_unc_fsml.py +7 -7
- sciform-0.32.3/docs/source/api.rst +0 -34
- sciform-0.32.3/examples/requirements.txt +0 -4
- sciform-0.32.3/src/sciform/__init__.py +0 -22
- sciform-0.32.3/src/sciform/user_options.py +0 -189
- sciform-0.32.3/tests/test_print.py +0 -71
- {sciform-0.32.3 → sciform-0.34.0}/.gitignore +0 -0
- {sciform-0.32.3 → sciform-0.34.0}/.pre-commit-config.yaml +0 -0
- {sciform-0.32.3 → sciform-0.34.0}/.readthedocs.yaml +0 -0
- {sciform-0.32.3 → sciform-0.34.0}/CODE_OF_CONDUCT.rst +0 -0
- {sciform-0.32.3 → sciform-0.34.0}/CONTRIBUTING.rst +0 -0
- {sciform-0.32.3 → sciform-0.34.0}/LICENSE +0 -0
- {sciform-0.32.3 → sciform-0.34.0}/docs/Makefile +0 -0
- {sciform-0.32.3 → sciform-0.34.0}/docs/make.bat +0 -0
- {sciform-0.32.3 → sciform-0.34.0}/docs/requirements.txt +0 -0
- {sciform-0.32.3 → sciform-0.34.0}/docs/source/_static/css/custom.css +0 -0
- {sciform-0.32.3 → sciform-0.34.0}/docs/source/index.rst +0 -0
- {sciform-0.32.3 → sciform-0.34.0}/docs/source/project.rst +0 -0
- {sciform-0.32.3 → sciform-0.34.0}/examples/__init__.py +0 -0
- {sciform-0.32.3 → sciform-0.34.0}/examples/data/fit_data.json +0 -0
- {sciform-0.32.3 → sciform-0.34.0}/examples/fit_plot_no_sciform.py +0 -0
- {sciform-0.32.3 → sciform-0.34.0}/examples/fit_plot_with_sciform.py +0 -0
- {sciform-0.32.3 → sciform-0.34.0}/examples/outputs/fit_plot_no_sciform.png +0 -0
- {sciform-0.32.3 → sciform-0.34.0}/examples/outputs/fit_plot_no_sciform_table.txt +0 -0
- {sciform-0.32.3 → sciform-0.34.0}/examples/outputs/fit_plot_with_sciform.png +0 -0
- {sciform-0.32.3 → sciform-0.34.0}/examples/outputs/fit_plot_with_sciform_table.txt +0 -0
- {sciform-0.32.3 → sciform-0.34.0}/setup.cfg +0 -0
- {sciform-0.32.3 → sciform-0.34.0}/src/sciform/grouping.py +0 -0
- {sciform-0.32.3 → sciform-0.34.0}/src/sciform/prefix.py +0 -0
- {sciform-0.32.3 → sciform-0.34.0}/src/sciform.egg-info/dependency_links.txt +0 -0
- {sciform-0.32.3 → sciform-0.34.0}/src/sciform.egg-info/top_level.txt +0 -0
- {sciform-0.32.3 → sciform-0.34.0}/tests/__init__.py +0 -0
- {sciform-0.32.3 → sciform-0.34.0}/tests/test_sci_num.py +0 -0
@@ -19,27 +19,31 @@ jobs:
|
|
19
19
|
python-version: ["3.9", "3.10", "3.11", "3.12"]
|
20
20
|
|
21
21
|
steps:
|
22
|
-
- uses: actions/checkout@
|
22
|
+
- uses: actions/checkout@v4
|
23
23
|
- name: Set up Python ${{ matrix.python-version }}
|
24
|
-
uses: actions/setup-python@
|
24
|
+
uses: actions/setup-python@v5
|
25
25
|
with:
|
26
26
|
python-version: ${{ matrix.python-version }}
|
27
|
+
cache: 'pip'
|
27
28
|
- name: Install dependencies
|
28
29
|
run: |
|
29
30
|
python -m pip install --upgrade pip
|
30
|
-
python -m pip install ruff blackdoc pytest pytest-cov
|
31
31
|
python -m pip install -e .[dev]
|
32
|
-
- name: Lint/format
|
32
|
+
- name: Lint/format source code and docs
|
33
33
|
run: |
|
34
34
|
ruff check .
|
35
35
|
ruff format . --check
|
36
|
-
- name:
|
36
|
+
- name: Test source code and docs
|
37
37
|
run: |
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
38
|
+
coverage run -m unittest
|
39
|
+
coverage report
|
40
|
+
coverage xml
|
41
|
+
python -m sphinx -b doctest docs/source/ docs/build/doctest/
|
42
42
|
- name: Upload coverage reports to Codecov
|
43
43
|
uses: codecov/codecov-action@v3
|
44
|
-
|
45
|
-
|
44
|
+
with:
|
45
|
+
token: ${{ secrets.CODECOV_TOKEN }}
|
46
|
+
flags: ${{ matrix.python-version }}
|
47
|
+
files: coverage.xml
|
48
|
+
fail_ci_if_error: true
|
49
|
+
verbose: true
|
@@ -21,9 +21,9 @@ jobs:
|
|
21
21
|
runs-on: ubuntu-latest
|
22
22
|
|
23
23
|
steps:
|
24
|
-
- uses: actions/checkout@
|
24
|
+
- uses: actions/checkout@v4
|
25
25
|
- name: Set up Python
|
26
|
-
uses: actions/setup-python@
|
26
|
+
uses: actions/setup-python@v5
|
27
27
|
with:
|
28
28
|
python-version: '3.x'
|
29
29
|
- name: Install dependencies
|
@@ -12,6 +12,149 @@ Unreleased
|
|
12
12
|
|
13
13
|
----
|
14
14
|
|
15
|
+
0.34.0 (2024-02-04)
|
16
|
+
-------------------
|
17
|
+
|
18
|
+
Added
|
19
|
+
^^^^^
|
20
|
+
|
21
|
+
* The ``Formatter`` now exposes the ``input_options`` and
|
22
|
+
``populated_options`` attributes.
|
23
|
+
The ``input_options`` attribute holds an ``InputOptions`` object which
|
24
|
+
stores a record of the input options passed into the ``Formatter``.
|
25
|
+
The ``populated_options`` attribute returns a ``PopulatedOptions``
|
26
|
+
object which shows the complete set of populated options which will be
|
27
|
+
used for formatting after merging with the global options.
|
28
|
+
Note that the ``populated_options`` attribute is re-calculated each
|
29
|
+
time it is access so that it reflects the current global options.
|
30
|
+
Both the ``InputOptions`` and ``PopulatedOptions`` objects can be used
|
31
|
+
to provide string representations of the options, or provide
|
32
|
+
programmatic access to the options via either attribute access or the
|
33
|
+
``as_dict()`` methods.
|
34
|
+
[`#110 <https://github.com/jagerber48/sciform/issues/110>`_]
|
35
|
+
* The ``PopulatedOptions`` used during formatting of a given
|
36
|
+
``FormattedNumber`` instance are stored on that instance for future
|
37
|
+
reference.
|
38
|
+
* Added ``get_default_global_options()``.
|
39
|
+
* Now integer ``0`` can be passed into ``left_pad_char`` to get the same
|
40
|
+
behavior as string ``"0"``.
|
41
|
+
* Added tests for docstrings.
|
42
|
+
|
43
|
+
Changed
|
44
|
+
^^^^^^^
|
45
|
+
|
46
|
+
* **[BREAKING]** Renamed functions for configuring global options:
|
47
|
+
|
48
|
+
* ``set_global_defaults()`` -> ``set_global_options()``
|
49
|
+
* ``reset_global_defaults()`` -> ``reset_global_options()``
|
50
|
+
* ``GlobalDefaultsContext()`` -> ``GlobalOptionsContext()``
|
51
|
+
|
52
|
+
* Refactored backend options handling code.
|
53
|
+
Previously, ``UserOptions`` were rendered into ``RenderedOptions``.
|
54
|
+
During rendering the global options were appropriately merged in and
|
55
|
+
some string literal options were replaced with enums for internal use.
|
56
|
+
These two classes were private.
|
57
|
+
Now there are ``InputOptions`` (which try to faithfully record user
|
58
|
+
input), ``PopulatedOptions`` (which capture the result of merging
|
59
|
+
the global options into the input options, but still using
|
60
|
+
user-friendly string representations of all options), and
|
61
|
+
``FinalizedOptions`` (which use the internal enum representations of
|
62
|
+
certain options).
|
63
|
+
The ``InputOptions`` and ``PopulatedOptions`` are now public while the
|
64
|
+
``FinalizedOptions`` is still private to shield the enum
|
65
|
+
representations from the users.
|
66
|
+
This sizable refactor was precipitated by the publicizing of the
|
67
|
+
options.
|
68
|
+
[`#110 <https://github.com/jagerber48/sciform/issues/110>`_]
|
69
|
+
|
70
|
+
Removed
|
71
|
+
^^^^^^^
|
72
|
+
|
73
|
+
* **[BREAKING]** Removed ``print_global_defaults()`` in favor of
|
74
|
+
``get_global_defaults()`` which now returns a ``PopulatedOptions``
|
75
|
+
object which can be printed by the user if desired.
|
76
|
+
|
77
|
+
Fixed
|
78
|
+
^^^^^
|
79
|
+
|
80
|
+
* Fixed a bug where ``SciNum`` formatting resulted in ``str`` objects
|
81
|
+
instead of ``FormattedNumber`` objects.
|
82
|
+
|
83
|
+
----
|
84
|
+
|
85
|
+
0.33.0 (2024-01-31)
|
86
|
+
-------------------
|
87
|
+
|
88
|
+
Added
|
89
|
+
^^^^^
|
90
|
+
|
91
|
+
* Added the ``FormattedNumber`` class.
|
92
|
+
This class is a subclass of ``str`` and is now returned by the
|
93
|
+
``Formatter`` instead of ``str``.
|
94
|
+
The ``FormattedNumber`` class allows post-conversion to ASCII, HTML,
|
95
|
+
and LaTeX formats.
|
96
|
+
[`#114 <https://github.com/jagerber48/sciform/issues/114>`_]
|
97
|
+
* Added separate flags for code coverage reports for each python
|
98
|
+
version.
|
99
|
+
|
100
|
+
Changed
|
101
|
+
^^^^^^^
|
102
|
+
|
103
|
+
* In addition to removing the ``latex`` option from the ``Formatter`` in
|
104
|
+
favor of the introduction of the ``FormattedNumber`` class, the
|
105
|
+
LaTeX conversion algorithm has been slightly modified.
|
106
|
+
|
107
|
+
* Left and right parentheses are no longer converted to ``"\left("``
|
108
|
+
and ``"\right)"`` due to introducing strange spacing issues.
|
109
|
+
See
|
110
|
+
`Spacing around \\left and \\right <https://tex.stackexchange.com/questions/2607/spacing-around-left-and-right>`_.
|
111
|
+
* Previously spaces within the ``sciform`` output were handled
|
112
|
+
inconsistently and occasionally required confusing extra handling.
|
113
|
+
Now any spaces in the input string are directly and explicitly
|
114
|
+
converted into math mode medium spaces: ``"\:"``.
|
115
|
+
* ``"μ"`` is now included in the math mode ``\text{}`` environment
|
116
|
+
and converted to ``"\textmu"``.
|
117
|
+
|
118
|
+
* **[BREAKING]** Renamed ``fill_char`` to ``left_pad_char``.
|
119
|
+
[`#126 <https://github.com/jagerber48/sciform/issues/126>`_]
|
120
|
+
* Slimmed down ``[dev]`` optional dependencies and created
|
121
|
+
``[examples]`` optional dependencies.
|
122
|
+
The former includes development tools, while the latter includes
|
123
|
+
the heavy-weight requirements needed to run all the examples,
|
124
|
+
including, e.g. ``jupyter``, ``scipy``, etc.
|
125
|
+
* Cleaned up and improved github actions for testing and
|
126
|
+
linting/formatting.
|
127
|
+
[`#136 <https://github.com/jagerber48/sciform/issues/136>`_]
|
128
|
+
|
129
|
+
* Use ``unittest`` and ``coverage`` instead of ``pytest``.
|
130
|
+
* The requirements to run the automation match the ``[dev]``
|
131
|
+
optional dependencies.
|
132
|
+
* Cache ``pip`` requirements to avoid unnecessarily downloading
|
133
|
+
dependencies.
|
134
|
+
* Remove a defunct ``blackdoc`` test.
|
135
|
+
Hopefully this can be replaced when ``ruff`` provides
|
136
|
+
functionality for formatting ``.rst`` files.
|
137
|
+
|
138
|
+
Fixed
|
139
|
+
^^^^^
|
140
|
+
|
141
|
+
* Fixed a bug where value/uncertainty pairs formatted in the
|
142
|
+
``"parts_per"`` format with zero exponent would appear with redundant
|
143
|
+
parentheses, e.g. ``"(1.2 ± 0.1)"``.
|
144
|
+
[`#130 <https://github.com/jagerber48/sciform/issues/130>`_]
|
145
|
+
|
146
|
+
Removed
|
147
|
+
^^^^^^^
|
148
|
+
|
149
|
+
* **[BREAKING]** Removed the ``latex`` option in favor of the
|
150
|
+
introduction of the ``FormattedNumber.as_latex()`` method.
|
151
|
+
This removal simplifies the formatting algorithm by separating LaTeX
|
152
|
+
formatting from other tasks like exponent string resolution.
|
153
|
+
The ``latex`` option also introduced a potential confusion with the
|
154
|
+
``superscript`` option, which had no effect when ``latex=True``.
|
155
|
+
|
156
|
+
----
|
157
|
+
|
15
158
|
0.32.3 (2024-01-11)
|
16
159
|
-------------------
|
17
160
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: sciform
|
3
|
-
Version: 0.
|
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
|
-
|
29
|
-
Requires-Dist:
|
30
|
-
Requires-Dist:
|
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
|
-
>>>
|
144
|
+
>>> formatter = Formatter(
|
137
145
|
... round_mode="dec_place", ndigits=6, upper_separator=" ", lower_separator=" "
|
138
146
|
... )
|
139
|
-
>>> print(
|
147
|
+
>>> print(formatter(51413.14159265359))
|
140
148
|
51 413.141 593
|
141
|
-
>>>
|
142
|
-
>>> print(
|
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
|
-
>>>
|
162
|
-
>>> print(
|
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
|
-
>>>
|
165
|
-
>>> print(
|
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)
|
@@ -97,18 +97,22 @@ You can view the on-going review
|
|
97
97
|
Usage
|
98
98
|
=====
|
99
99
|
|
100
|
+
Here we provide a few key usage examples.
|
101
|
+
For many more details see
|
102
|
+
`Usage <https://sciform.readthedocs.io/en/stable/usage.html>`_.
|
103
|
+
|
100
104
|
``sciform`` provides a wide variety of formatting options which can be
|
101
105
|
controlled when constructing ``Formatter`` objects which are then used
|
102
106
|
to format numbers into strings according to the selected options.
|
103
107
|
|
104
108
|
>>> from sciform import Formatter
|
105
|
-
>>>
|
109
|
+
>>> formatter = Formatter(
|
106
110
|
... round_mode="dec_place", ndigits=6, upper_separator=" ", lower_separator=" "
|
107
111
|
... )
|
108
|
-
>>> print(
|
112
|
+
>>> print(formatter(51413.14159265359))
|
109
113
|
51 413.141 593
|
110
|
-
>>>
|
111
|
-
>>> print(
|
114
|
+
>>> formatter = Formatter(round_mode="sig_fig", ndigits=4, exp_mode="engineering")
|
115
|
+
>>> print(formatter(123456.78))
|
112
116
|
123.5e+03
|
113
117
|
|
114
118
|
Users can also format numbers by constructing ``SciNum`` objects and
|
@@ -127,11 +131,11 @@ to format pairs of numbers as value/uncertainty pairs.
|
|
127
131
|
This can be done by passing two numbers into a ``Formatter`` call or by
|
128
132
|
using the ``SciNum`` object.
|
129
133
|
|
130
|
-
>>>
|
131
|
-
>>> print(
|
134
|
+
>>> formatter = Formatter(ndigits=2, upper_separator=" ", lower_separator=" ")
|
135
|
+
>>> print(formatter(123456.654321, 0.00345))
|
132
136
|
123 456.654 3 ± 0.003 4
|
133
|
-
>>>
|
134
|
-
>>> print(
|
137
|
+
>>> formatter = Formatter(ndigits=4, exp_mode="engineering")
|
138
|
+
>>> print(formatter(123456.654321, 0.00345))
|
135
139
|
(123.456654321 ± 0.000003450)e+03
|
136
140
|
|
137
141
|
>>> num = SciNum(123456.654321, 0.00345)
|
@@ -0,0 +1,49 @@
|
|
1
|
+
API
|
2
|
+
###
|
3
|
+
|
4
|
+
.. module:: sciform
|
5
|
+
:noindex:
|
6
|
+
|
7
|
+
Formatting
|
8
|
+
==========
|
9
|
+
|
10
|
+
.. autoclass:: Formatter(...)
|
11
|
+
:members:
|
12
|
+
|
13
|
+
.. automethod:: __init__(...)
|
14
|
+
.. automethod:: __call__
|
15
|
+
|
16
|
+
.. autoclass:: SciNum
|
17
|
+
|
18
|
+
.. autoclass:: FormattedNumber()
|
19
|
+
:members:
|
20
|
+
:private-members:
|
21
|
+
|
22
|
+
Options
|
23
|
+
=======
|
24
|
+
|
25
|
+
.. autoclass:: InputOptions()
|
26
|
+
:members:
|
27
|
+
|
28
|
+
.. autoclass:: PopulatedOptions()
|
29
|
+
:members:
|
30
|
+
|
31
|
+
Auto Options
|
32
|
+
============
|
33
|
+
|
34
|
+
.. autoclass:: AutoExpVal()
|
35
|
+
|
36
|
+
.. autoclass:: AutoDigits()
|
37
|
+
|
38
|
+
Global Configuration
|
39
|
+
====================
|
40
|
+
|
41
|
+
.. autofunction:: get_default_global_options
|
42
|
+
|
43
|
+
.. autofunction:: get_global_options
|
44
|
+
|
45
|
+
.. autofunction:: set_global_options(...)
|
46
|
+
|
47
|
+
.. autofunction:: reset_global_options
|
48
|
+
|
49
|
+
.. autoclass:: GlobalOptionsContext(...)
|
@@ -20,68 +20,66 @@ available formatting options.
|
|
20
20
|
|
21
21
|
>>> from sciform import Formatter
|
22
22
|
>>> num = 12345.54321
|
23
|
-
>>>
|
24
|
-
>>> print(
|
23
|
+
>>> formatter = Formatter(exp_mode="scientific", round_mode="sig_fig", ndigits=4)
|
24
|
+
>>> print(formatter(num))
|
25
25
|
1.235e+04
|
26
|
-
>>>
|
26
|
+
>>> formatter = Formatter(
|
27
27
|
... exp_mode="engineering",
|
28
28
|
... round_mode="dec_place",
|
29
29
|
... ndigits=10,
|
30
30
|
... sign_mode=" ",
|
31
31
|
... superscript=True,
|
32
32
|
... )
|
33
|
-
>>> print(
|
33
|
+
>>> print(formatter(num))
|
34
34
|
12.3455432100×10³
|
35
|
-
>>>
|
35
|
+
>>> formatter = Formatter(
|
36
36
|
... exp_mode="fixed_point",
|
37
37
|
... upper_separator=" ",
|
38
38
|
... decimal_separator=",",
|
39
39
|
... lower_separator="_",
|
40
40
|
... sign_mode="+",
|
41
41
|
... )
|
42
|
-
>>> print(
|
42
|
+
>>> print(formatter(num))
|
43
43
|
+12 345,543_21
|
44
44
|
|
45
45
|
>>> num = 0.076543
|
46
|
-
>>>
|
46
|
+
>>> formatter = Formatter(
|
47
47
|
... exp_mode="scientific", exp_val=-3, exp_format="parts_per", add_ppth_form=True
|
48
48
|
... )
|
49
|
-
>>> print(
|
49
|
+
>>> print(formatter(num))
|
50
50
|
76.543 ppth
|
51
|
-
>>>
|
51
|
+
>>> formatter = Formatter(
|
52
52
|
... exp_mode="scientific", exp_val=-2, exp_format="prefix", add_c_prefix=True
|
53
53
|
... )
|
54
|
-
>>> print(
|
54
|
+
>>> print(formatter(num))
|
55
55
|
7.6543 c
|
56
|
-
>>>
|
57
|
-
>>> print(
|
56
|
+
>>> formatter = Formatter(exp_mode="scientific", exp_val=-6, exp_format="prefix")
|
57
|
+
>>> print(formatter(num))
|
58
58
|
76543 μ
|
59
|
-
>>>
|
60
|
-
>>> print(
|
59
|
+
>>> formatter = Formatter(exp_mode="percent")
|
60
|
+
>>> print(formatter(num))
|
61
61
|
7.6543%
|
62
62
|
|
63
63
|
>>> num = 3141592.7
|
64
64
|
>>> unc = 1618
|
65
|
-
>>>
|
66
|
-
>>> print(
|
65
|
+
>>> formatter = Formatter()
|
66
|
+
>>> print(formatter(num, unc))
|
67
67
|
3141593 ± 1618
|
68
|
-
>>>
|
68
|
+
>>> formatter = Formatter(
|
69
69
|
... exp_mode="engineering",
|
70
70
|
... exp_format="prefix",
|
71
71
|
... pdg_sig_figs=True,
|
72
72
|
... pm_whitespace=False,
|
73
73
|
... )
|
74
|
-
>>> print(
|
74
|
+
>>> print(formatter(num, unc))
|
75
75
|
(3.1416±0.0016) M
|
76
76
|
|
77
77
|
>>> num = 314159.27
|
78
78
|
>>> unc = 1618
|
79
|
-
>>>
|
80
|
-
... exp_mode="engineering_shifted",
|
81
|
-
... pdg_sig_figs=True,
|
82
|
-
... paren_uncertainty=True
|
79
|
+
>>> formatter = Formatter(
|
80
|
+
... exp_mode="engineering_shifted", pdg_sig_figs=True, paren_uncertainty=True
|
83
81
|
... )
|
84
|
-
>>> print(
|
82
|
+
>>> print(formatter(num, unc))
|
85
83
|
(0.3142(16))e+06
|
86
84
|
|
87
85
|
.. _fsml_examples:
|
@@ -115,7 +113,7 @@ has two significant figures.
|
|
115
113
|
The ``()`` indicates that the value/uncertainty pair should be formatted
|
116
114
|
using the parentheses uncertainty format.
|
117
115
|
|
118
|
-
>>> print(f
|
116
|
+
>>> print(f"{SciNum(123):ex-3p}")
|
119
117
|
123000 m
|
120
118
|
|
121
119
|
In the preceding example the ``e`` indicates that scientific notation
|
@@ -123,7 +121,7 @@ should be used.
|
|
123
121
|
The ``x-3`` indicates that the exponent will be forced to equal ``-3``.
|
124
122
|
Finally the ``p`` indicates that the SI prefix mode should be used.
|
125
123
|
|
126
|
-
>>> print(f
|
124
|
+
>>> print(f"{SciNum(123): .-1f}")
|
127
125
|
120
|
128
126
|
|
129
127
|
In this example the leading space indicates a leading space should be
|
@@ -139,52 +137,51 @@ SciNum, and Global Options
|
|
139
137
|
Here are a small selection of examples which demonstrate some of the
|
140
138
|
available string formatting options.
|
141
139
|
Note that many options are not available through the :ref:`fsml`, so
|
142
|
-
these options must be selected by configuring the global
|
143
|
-
|
144
|
-
|
145
|
-
manager, but this could have been done using :func:`set_global_defaults`
|
140
|
+
these options must be selected by configuring the global options.
|
141
|
+
Here this is done using the :class:`GlobalOptionsContext` context
|
142
|
+
manager, but this could have been done using :func:`set_global_options`
|
146
143
|
instead.
|
147
144
|
|
148
|
-
>>> from sciform import SciNum,
|
149
|
-
>>>
|
150
|
-
>>> print(f"{
|
145
|
+
>>> from sciform import SciNum, GlobalOptionsContext
|
146
|
+
>>> num = SciNum(12345.54321)
|
147
|
+
>>> print(f"{num:!4e}")
|
151
148
|
1.235e+04
|
152
|
-
>>> print(f"{
|
149
|
+
>>> print(f"{num: .10r}")
|
153
150
|
12.3455432100e+03
|
154
|
-
>>> with
|
151
|
+
>>> with GlobalOptionsContext(
|
155
152
|
... upper_separator=" ",
|
156
153
|
... decimal_separator=",",
|
157
154
|
... lower_separator="_",
|
158
155
|
... ):
|
159
|
-
... print(f"{
|
156
|
+
... print(f"{num:+}")
|
160
157
|
+12 345,543_21
|
161
158
|
|
162
|
-
>>>
|
163
|
-
>>> with
|
164
|
-
... print(f"{
|
159
|
+
>>> num = SciNum(0.076543)
|
160
|
+
>>> with GlobalOptionsContext(exp_format="parts_per", add_ppth_form=True):
|
161
|
+
... print(f"{num:ex-3}")
|
165
162
|
...
|
166
163
|
76.543 ppth
|
167
|
-
>>> with
|
168
|
-
... print(f"{
|
164
|
+
>>> with GlobalOptionsContext(exp_format="prefix", add_c_prefix=True):
|
165
|
+
... print(f"{num:ex-2}")
|
169
166
|
...
|
170
167
|
7.6543 c
|
171
|
-
>>> with
|
172
|
-
... print(f"{
|
168
|
+
>>> with GlobalOptionsContext(exp_mode="scientific", exp_val=-6, exp_format="prefix"):
|
169
|
+
... print(f"{num:ex-6}")
|
173
170
|
...
|
174
171
|
76543 μ
|
175
|
-
>>> print(f"{
|
172
|
+
>>> print(f"{num:%}")
|
176
173
|
7.6543%
|
177
174
|
|
178
175
|
>>> num_unc = SciNum(3141592.7, 1618)
|
179
176
|
>>> print(f"{num_unc}")
|
180
177
|
3141593 ± 1618
|
181
|
-
>>> with
|
178
|
+
>>> with GlobalOptionsContext(pdg_sig_figs=True, pm_whitespace=False):
|
182
179
|
... print(f"{num_unc:rp}")
|
183
180
|
...
|
184
181
|
(3.1416±0.0016) M
|
185
182
|
|
186
183
|
>>> num_unc = SciNum(314159.27, 1618)
|
187
|
-
>>> with
|
184
|
+
>>> with GlobalOptionsContext(pdg_sig_figs=True):
|
188
185
|
... print(f"{num_unc:#r()}")
|
189
186
|
...
|
190
187
|
(0.3142(16))e+06
|
@@ -298,7 +295,7 @@ lists, arrays, etc.) of numbers.
|
|
298
295
|
|
299
296
|
>>> from sciform import Formatter
|
300
297
|
>>>
|
301
|
-
>>>
|
298
|
+
>>> formatter = Formatter(
|
302
299
|
... exp_mode="engineering",
|
303
300
|
... exp_format="prefix",
|
304
301
|
... pdg_sig_figs=True,
|
@@ -307,11 +304,11 @@ lists, arrays, etc.) of numbers.
|
|
307
304
|
>>> val_list = [1000, 2000, 3000]
|
308
305
|
>>> err_list = [200, 400, 600]
|
309
306
|
>>>
|
310
|
-
>>> val_str_list = list(map(
|
307
|
+
>>> val_str_list = list(map(formatter, val_list))
|
311
308
|
>>> print(val_str_list)
|
312
309
|
['1 k', '2 k', '3 k']
|
313
310
|
>>>
|
314
|
-
>>> val_err_str_list = list(map(
|
311
|
+
>>> val_err_str_list = list(map(formatter, val_list, err_list))
|
315
312
|
>>> print(val_err_str_list)
|
316
313
|
['1.00(20) k', '2.0(4) k', '3.0(6) k']
|
317
314
|
|
@@ -321,20 +318,16 @@ makes this easy.
|
|
321
318
|
|
322
319
|
>>> import numpy as np
|
323
320
|
>>>
|
324
|
-
>>>
|
325
|
-
>>> arr = np.array([[1e6, 2e6, 3e6],
|
326
|
-
... [4e6, 5e6, 6e6],
|
327
|
-
... [7e6, 8e6, 9e6]])
|
321
|
+
>>> vec_formatter = np.vectorize(formatter)
|
322
|
+
>>> arr = np.array([[1e6, 2e6, 3e6], [4e6, 5e6, 6e6], [7e6, 8e6, 9e6]])
|
328
323
|
>>>
|
329
|
-
>>> arr_err = np.array([[9e4, 8e4, 7e4],
|
330
|
-
... [6e4, 5e4, 4e4],
|
331
|
-
... [3e4, 2e4, 1e4]])
|
324
|
+
>>> arr_err = np.array([[9e4, 8e4, 7e4], [6e4, 5e4, 4e4], [3e4, 2e4, 1e4]])
|
332
325
|
>>>
|
333
|
-
>>> print(
|
326
|
+
>>> print(vec_formatter(arr))
|
334
327
|
[['1 M' '2 M' '3 M']
|
335
328
|
['4 M' '5 M' '6 M']
|
336
329
|
['7 M' '8 M' '9 M']]
|
337
|
-
>>> print(
|
330
|
+
>>> print(vec_formatter(arr, arr_err))
|
338
331
|
[['1.00(9) M' '2.00(8) M' '3.00(7) M']
|
339
332
|
['4.00(6) M' '5.00(5) M' '6.00(4) M']
|
340
333
|
['7.000(30) M' '8.000(20) M' '9.000(10) M']]
|
@@ -152,14 +152,14 @@ Note that it is possible, using the ``extra_parts_per_forms`` option to
|
|
152
152
|
override the standard mappings listed above.
|
153
153
|
|
154
154
|
>>> from sciform import Formatter
|
155
|
-
>>>
|
155
|
+
>>> formatter = Formatter(
|
156
156
|
... exp_mode="engineering",
|
157
157
|
... exp_format="parts_per",
|
158
158
|
... extra_parts_per_forms={-9: None, -12: "ppb"},
|
159
159
|
... )
|
160
|
-
>>> print(
|
160
|
+
>>> print(formatter(33e-9))
|
161
161
|
33e-09
|
162
|
-
>>> print(
|
162
|
+
>>> print(formatter(33e-12))
|
163
163
|
33 ppb
|
164
164
|
|
165
165
|
IEC Prefixes
|