sciform 0.38.0__tar.gz → 0.38.1__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.38.0 → sciform-0.38.1}/CHANGELOG.rst +16 -2
- {sciform-0.38.0/src/sciform.egg-info → sciform-0.38.1}/PKG-INFO +1 -1
- {sciform-0.38.0 → sciform-0.38.1}/docs/source/examples.rst +118 -1
- {sciform-0.38.0 → sciform-0.38.1/src/sciform.egg-info}/PKG-INFO +1 -1
- {sciform-0.38.0 → sciform-0.38.1}/.github/workflows/python-package.yml +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/.github/workflows/python-publish.yml +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/.gitignore +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/.pre-commit-config.yaml +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/.readthedocs.yaml +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/CODE_OF_CONDUCT.rst +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/CONTRIBUTING.rst +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/LICENSE +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/README.rst +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/coverage_feature.toml +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/coverage_unit.toml +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/docs/Makefile +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/docs/make.bat +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/docs/requirements.txt +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/docs/source/_static/css/custom.css +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/docs/source/api.rst +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/docs/source/conf.py +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/docs/source/exp replacement.rst +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/docs/source/fsml.rst +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/docs/source/index.rst +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/docs/source/options.rst +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/docs/source/project.rst +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/docs/source/usage.rst +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/examples/__init__.py +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/examples/data/fit_data.json +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/examples/fit_plot_no_sciform.py +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/examples/fit_plot_with_sciform.py +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/examples/jupyter_output_example.ipynb +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/examples/outputs/fit_plot_no_sciform.png +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/examples/outputs/fit_plot_no_sciform_table.txt +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/examples/outputs/fit_plot_with_sciform.png +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/examples/outputs/fit_plot_with_sciform_table.txt +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/examples/outputs/jupyter_output.png +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/pyproject.toml +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/ruff.toml +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/setup.cfg +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/src/sciform/__init__.py +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/src/sciform/api/__init__.py +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/src/sciform/api/formatted_number.py +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/src/sciform/api/formatter.py +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/src/sciform/api/global_configuration.py +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/src/sciform/api/scinum.py +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/src/sciform/format_utils/__init__.py +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/src/sciform/format_utils/exp_translations.py +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/src/sciform/format_utils/exponents.py +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/src/sciform/format_utils/grouping.py +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/src/sciform/format_utils/make_strings.py +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/src/sciform/format_utils/numbers.py +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/src/sciform/format_utils/rounding.py +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/src/sciform/formatting/__init__.py +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/src/sciform/formatting/fsml.py +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/src/sciform/formatting/number_formatting.py +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/src/sciform/formatting/output_conversion.py +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/src/sciform/formatting/parser.py +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/src/sciform/options/__init__.py +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/src/sciform/options/conversion.py +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/src/sciform/options/finalized_options.py +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/src/sciform/options/global_options.py +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/src/sciform/options/input_options.py +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/src/sciform/options/option_types.py +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/src/sciform/options/populated_options.py +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/src/sciform/options/validation.py +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/src/sciform.egg-info/SOURCES.txt +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/src/sciform.egg-info/dependency_links.txt +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/src/sciform.egg-info/requires.txt +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/src/sciform.egg-info/top_level.txt +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/tests/__init__.py +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/tests/feature/__init__.py +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/tests/feature/test_global_config.py +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/tests/feature/test_options_printout.py +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/tests/feature/test_output_conversion.py +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/tests/feature/test_sci_num.py +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/tests/feature/test_separators.py +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/tests/feature/test_string_parser.py +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/tests/feature/test_val_formatter.py +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/tests/feature/test_val_fsml.py +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/tests/feature/test_val_unc_formatter.py +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/tests/feature/test_val_unc_fsml.py +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/tests/test_docstrings.py +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/tests/unit/__init__.py +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/tests/unit/format_utils/__init__.py +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/tests/unit/format_utils/test_exp_translations.py +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/tests/unit/format_utils/test_exponent_utils.py +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/tests/unit/format_utils/test_grouping.py +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/tests/unit/format_utils/test_make_strings.py +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/tests/unit/format_utils/test_number_utils.py +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/tests/unit/format_utils/test_rounding_utils.py +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/tests/unit/test_invalid_options.py +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/tests/unit/test_options_strings.py +0 -0
- {sciform-0.38.0 → sciform-0.38.1}/tests/unit/test_validation.py +0 -0
@@ -9,8 +9,22 @@ Unreleased
|
|
9
9
|
----------
|
10
10
|
|
11
11
|
* Any unreleased changes can be viewed in the latest version
|
12
|
-
|
13
|
-
|
12
|
+
documentation
|
13
|
+
`changelog <https://sciform.readthedocs.io/en/latest/project.html#changelog>`_.
|
14
|
+
|
15
|
+
0.38.1 (2024-11-02)
|
16
|
+
-------------------
|
17
|
+
|
18
|
+
Added
|
19
|
+
-----
|
20
|
+
|
21
|
+
* Documented examples demonstrating the interplay between ``sciform``
|
22
|
+
formatting the ``decimal`` module configuration.
|
23
|
+
[`#183 <https://github.com/jagerber48/sciform/issues/183>`_]
|
24
|
+
* Added an example demonstrating how users can implement a "fallback"
|
25
|
+
formatter for cases when users want different formatting behavior
|
26
|
+
applied when the uncertainty is invalid or not present.
|
27
|
+
[`#177 <https://github.com/jagerber48/sciform/issues/177>`_]
|
14
28
|
|
15
29
|
----
|
16
30
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: sciform
|
3
|
-
Version: 0.38.
|
3
|
+
Version: 0.38.1
|
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
|
@@ -352,7 +352,7 @@ makes this easy.
|
|
352
352
|
['7.000(30) M' '8.000(20) M' '9.000(10) M']]
|
353
353
|
|
354
354
|
Appending Units
|
355
|
-
|
355
|
+
===============
|
356
356
|
|
357
357
|
The :mod:`sciform` :ref:`SI prefix mode<exp_str_replacement>` allows
|
358
358
|
exponent strings such as ``'e+03'`` to be replaced with their SI
|
@@ -416,3 +416,120 @@ At this point it would be recommended to, instead, directly calculate
|
|
416
416
|
the unit, rescale the numerical inputs to :mod:`sciform` formatting, and
|
417
417
|
append the entire unit without utilizing the :mod:`sciform` SI prefix
|
418
418
|
mode.
|
419
|
+
|
420
|
+
Interactions with the Decimal Module
|
421
|
+
====================================
|
422
|
+
|
423
|
+
Numbers passed into :mod:`sciform` are always converted into
|
424
|
+
:class:`Decimal` instances during formatting.
|
425
|
+
Various options exposed by the
|
426
|
+
`Decimal module <https://docs.python.org/3/library/decimal.html>`_
|
427
|
+
will (desirably or undesirably) modify :mod:`sciform` formatting
|
428
|
+
behavior.
|
429
|
+
|
430
|
+
>>> import decimal
|
431
|
+
>>> from sciform import SciNum
|
432
|
+
>>>
|
433
|
+
>>> # We calculate 1/9 in a high precision decimal context
|
434
|
+
>>> with decimal.localcontext() as ctx:
|
435
|
+
... ctx.prec = 100
|
436
|
+
... num = decimal.Decimal(1)/decimal.Decimal(9)
|
437
|
+
>>> # Formatted in the default decimal context
|
438
|
+
>>> print(format(SciNum(num), "Af"))
|
439
|
+
0.1111111111111111111111111111
|
440
|
+
>>>
|
441
|
+
>>> # Formatted in a low precision decimal context
|
442
|
+
>>> with decimal.localcontext() as ctx:
|
443
|
+
... ctx.prec = 5
|
444
|
+
... print(format(SciNum(num), "Af"))
|
445
|
+
0.11111
|
446
|
+
>>>
|
447
|
+
>>> # Formatted in a high precision decimal context
|
448
|
+
>>> with decimal.localcontext() as ctx:
|
449
|
+
... ctx.prec = 50
|
450
|
+
... print(format(SciNum(num), "Af"))
|
451
|
+
0.11111111111111111111111111111111111111111111111111
|
452
|
+
>>>
|
453
|
+
>>> # Formatted in a decimal context with a different rounding rule
|
454
|
+
>>> with decimal.localcontext() as ctx:
|
455
|
+
... ctx.rounding = decimal.ROUND_CEILING
|
456
|
+
... print(format(SciNum(num), "Af"))
|
457
|
+
0.1111111111111111111111111112
|
458
|
+
|
459
|
+
We see that the number of digits shown in the ``"all"`` round mode can
|
460
|
+
be modified using the decimal context precision.
|
461
|
+
We also see that the rounding mode can be adjusted away from the default
|
462
|
+
round-to-even rounding.
|
463
|
+
|
464
|
+
When working on high precision applications, recall that :class:`float`
|
465
|
+
instances will always be converted to :class:`Decimal` instances with 17
|
466
|
+
digits of precision or fewer.
|
467
|
+
So, if you desire higher precision you should use :class:`Decimal`
|
468
|
+
rather than :class:`float` inputs, otherwise you may observe undesirable
|
469
|
+
behavior.
|
470
|
+
See :ref:`dec_and_float`.
|
471
|
+
|
472
|
+
Fallback Formatters
|
473
|
+
===================
|
474
|
+
|
475
|
+
Sometimes values and value/uncertainty pairs with various properties may
|
476
|
+
appear together in the same context.
|
477
|
+
It may be inappropriate to use a single formatter for all of these
|
478
|
+
inputs.
|
479
|
+
For example
|
480
|
+
|
481
|
+
>>> from sciform import Formatter
|
482
|
+
>>> sform = Formatter(round_mode="pdg", paren_uncertainty=True)
|
483
|
+
>>> print(sform(123456, 0.0789))
|
484
|
+
123456.00(8)
|
485
|
+
>>> print(sform(123456, float("nan")))
|
486
|
+
120000(nan)
|
487
|
+
>>> print(sform(123456))
|
488
|
+
120000
|
489
|
+
|
490
|
+
In both the cases when the uncertainty was invalid for rounding and when
|
491
|
+
the uncertainty wasn't present the rounding got applied to the value
|
492
|
+
directly.
|
493
|
+
However, it may be inappropriate to apply PDG rounding, which is usually
|
494
|
+
used for uncertainty, to the value.
|
495
|
+
Instead, the user may want to retain more significant figures when
|
496
|
+
rounding is applied to the value instead of the uncertainty.
|
497
|
+
Users can resolve this by defining two formatters and a simple helper
|
498
|
+
function to cover these cases.
|
499
|
+
|
500
|
+
>>> from math import isfinite
|
501
|
+
>>> from sciform import Formatter
|
502
|
+
>>>
|
503
|
+
>>> def generate_multi_formatter(
|
504
|
+
... val_unc_formatter=None,
|
505
|
+
... val_formatter=None
|
506
|
+
... ):
|
507
|
+
... if val_unc_formatter is None:
|
508
|
+
... val_unc_formatter = Formatter()
|
509
|
+
... if val_formatter is None:
|
510
|
+
... val_formatter = Formatter()
|
511
|
+
... def multi_formatter(val, unc=None):
|
512
|
+
... if unc is None or not isfinite(unc):
|
513
|
+
... return val_formatter(val, unc)
|
514
|
+
... else:
|
515
|
+
... return val_unc_formatter(val, unc)
|
516
|
+
... return multi_formatter
|
517
|
+
>>>
|
518
|
+
>>> multi_formatter = generate_multi_formatter(
|
519
|
+
... val_unc_formatter = Formatter(
|
520
|
+
... round_mode="pdg",
|
521
|
+
... paren_uncertainty=True,
|
522
|
+
... ),
|
523
|
+
... val_formatter=Formatter(
|
524
|
+
... round_mode="sig_fig",
|
525
|
+
... ndigits=6,
|
526
|
+
... paren_uncertainty=True,
|
527
|
+
... ),
|
528
|
+
... )
|
529
|
+
>>>
|
530
|
+
>>> print(multi_formatter(123456, 0.0789))
|
531
|
+
123456.00(8)
|
532
|
+
>>> print(multi_formatter(123456, float("nan")))
|
533
|
+
123456(nan)
|
534
|
+
>>> print(multi_formatter(123456))
|
535
|
+
123456
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: sciform
|
3
|
-
Version: 0.38.
|
3
|
+
Version: 0.38.1
|
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
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|