sciform 0.38.0__tar.gz → 0.38.2__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.
Files changed (94) hide show
  1. {sciform-0.38.0 → sciform-0.38.2}/CHANGELOG.rst +26 -0
  2. {sciform-0.38.0/src/sciform.egg-info → sciform-0.38.2}/PKG-INFO +1 -1
  3. {sciform-0.38.0 → sciform-0.38.2}/docs/source/examples.rst +118 -1
  4. {sciform-0.38.0 → sciform-0.38.2/src/sciform.egg-info}/PKG-INFO +1 -1
  5. {sciform-0.38.0 → sciform-0.38.2}/.github/workflows/python-package.yml +0 -0
  6. {sciform-0.38.0 → sciform-0.38.2}/.github/workflows/python-publish.yml +0 -0
  7. {sciform-0.38.0 → sciform-0.38.2}/.gitignore +0 -0
  8. {sciform-0.38.0 → sciform-0.38.2}/.pre-commit-config.yaml +0 -0
  9. {sciform-0.38.0 → sciform-0.38.2}/.readthedocs.yaml +0 -0
  10. {sciform-0.38.0 → sciform-0.38.2}/CODE_OF_CONDUCT.rst +0 -0
  11. {sciform-0.38.0 → sciform-0.38.2}/CONTRIBUTING.rst +0 -0
  12. {sciform-0.38.0 → sciform-0.38.2}/LICENSE +0 -0
  13. {sciform-0.38.0 → sciform-0.38.2}/README.rst +0 -0
  14. {sciform-0.38.0 → sciform-0.38.2}/coverage_feature.toml +0 -0
  15. {sciform-0.38.0 → sciform-0.38.2}/coverage_unit.toml +0 -0
  16. {sciform-0.38.0 → sciform-0.38.2}/docs/Makefile +0 -0
  17. {sciform-0.38.0 → sciform-0.38.2}/docs/make.bat +0 -0
  18. {sciform-0.38.0 → sciform-0.38.2}/docs/requirements.txt +0 -0
  19. {sciform-0.38.0 → sciform-0.38.2}/docs/source/_static/css/custom.css +0 -0
  20. {sciform-0.38.0 → sciform-0.38.2}/docs/source/api.rst +0 -0
  21. {sciform-0.38.0 → sciform-0.38.2}/docs/source/conf.py +0 -0
  22. {sciform-0.38.0 → sciform-0.38.2}/docs/source/exp replacement.rst +0 -0
  23. {sciform-0.38.0 → sciform-0.38.2}/docs/source/fsml.rst +0 -0
  24. {sciform-0.38.0 → sciform-0.38.2}/docs/source/index.rst +0 -0
  25. {sciform-0.38.0 → sciform-0.38.2}/docs/source/options.rst +0 -0
  26. {sciform-0.38.0 → sciform-0.38.2}/docs/source/project.rst +0 -0
  27. {sciform-0.38.0 → sciform-0.38.2}/docs/source/usage.rst +0 -0
  28. {sciform-0.38.0 → sciform-0.38.2}/examples/__init__.py +0 -0
  29. {sciform-0.38.0 → sciform-0.38.2}/examples/data/fit_data.json +0 -0
  30. {sciform-0.38.0 → sciform-0.38.2}/examples/fit_plot_no_sciform.py +0 -0
  31. {sciform-0.38.0 → sciform-0.38.2}/examples/fit_plot_with_sciform.py +0 -0
  32. {sciform-0.38.0 → sciform-0.38.2}/examples/jupyter_output_example.ipynb +0 -0
  33. {sciform-0.38.0 → sciform-0.38.2}/examples/outputs/fit_plot_no_sciform.png +0 -0
  34. {sciform-0.38.0 → sciform-0.38.2}/examples/outputs/fit_plot_no_sciform_table.txt +0 -0
  35. {sciform-0.38.0 → sciform-0.38.2}/examples/outputs/fit_plot_with_sciform.png +0 -0
  36. {sciform-0.38.0 → sciform-0.38.2}/examples/outputs/fit_plot_with_sciform_table.txt +0 -0
  37. {sciform-0.38.0 → sciform-0.38.2}/examples/outputs/jupyter_output.png +0 -0
  38. {sciform-0.38.0 → sciform-0.38.2}/pyproject.toml +0 -0
  39. {sciform-0.38.0 → sciform-0.38.2}/ruff.toml +0 -0
  40. {sciform-0.38.0 → sciform-0.38.2}/setup.cfg +0 -0
  41. {sciform-0.38.0 → sciform-0.38.2}/src/sciform/__init__.py +0 -0
  42. {sciform-0.38.0 → sciform-0.38.2}/src/sciform/api/__init__.py +0 -0
  43. {sciform-0.38.0 → sciform-0.38.2}/src/sciform/api/formatted_number.py +0 -0
  44. {sciform-0.38.0 → sciform-0.38.2}/src/sciform/api/formatter.py +0 -0
  45. {sciform-0.38.0 → sciform-0.38.2}/src/sciform/api/global_configuration.py +0 -0
  46. {sciform-0.38.0 → sciform-0.38.2}/src/sciform/api/scinum.py +0 -0
  47. {sciform-0.38.0 → sciform-0.38.2}/src/sciform/format_utils/__init__.py +0 -0
  48. {sciform-0.38.0 → sciform-0.38.2}/src/sciform/format_utils/exp_translations.py +0 -0
  49. {sciform-0.38.0 → sciform-0.38.2}/src/sciform/format_utils/exponents.py +0 -0
  50. {sciform-0.38.0 → sciform-0.38.2}/src/sciform/format_utils/grouping.py +0 -0
  51. {sciform-0.38.0 → sciform-0.38.2}/src/sciform/format_utils/make_strings.py +0 -0
  52. {sciform-0.38.0 → sciform-0.38.2}/src/sciform/format_utils/numbers.py +0 -0
  53. {sciform-0.38.0 → sciform-0.38.2}/src/sciform/format_utils/rounding.py +0 -0
  54. {sciform-0.38.0 → sciform-0.38.2}/src/sciform/formatting/__init__.py +0 -0
  55. {sciform-0.38.0 → sciform-0.38.2}/src/sciform/formatting/fsml.py +0 -0
  56. {sciform-0.38.0 → sciform-0.38.2}/src/sciform/formatting/number_formatting.py +0 -0
  57. {sciform-0.38.0 → sciform-0.38.2}/src/sciform/formatting/output_conversion.py +0 -0
  58. {sciform-0.38.0 → sciform-0.38.2}/src/sciform/formatting/parser.py +0 -0
  59. {sciform-0.38.0 → sciform-0.38.2}/src/sciform/options/__init__.py +0 -0
  60. {sciform-0.38.0 → sciform-0.38.2}/src/sciform/options/conversion.py +0 -0
  61. {sciform-0.38.0 → sciform-0.38.2}/src/sciform/options/finalized_options.py +0 -0
  62. {sciform-0.38.0 → sciform-0.38.2}/src/sciform/options/global_options.py +0 -0
  63. {sciform-0.38.0 → sciform-0.38.2}/src/sciform/options/input_options.py +0 -0
  64. {sciform-0.38.0 → sciform-0.38.2}/src/sciform/options/option_types.py +0 -0
  65. {sciform-0.38.0 → sciform-0.38.2}/src/sciform/options/populated_options.py +0 -0
  66. {sciform-0.38.0 → sciform-0.38.2}/src/sciform/options/validation.py +0 -0
  67. {sciform-0.38.0 → sciform-0.38.2}/src/sciform.egg-info/SOURCES.txt +0 -0
  68. {sciform-0.38.0 → sciform-0.38.2}/src/sciform.egg-info/dependency_links.txt +0 -0
  69. {sciform-0.38.0 → sciform-0.38.2}/src/sciform.egg-info/requires.txt +0 -0
  70. {sciform-0.38.0 → sciform-0.38.2}/src/sciform.egg-info/top_level.txt +0 -0
  71. {sciform-0.38.0 → sciform-0.38.2}/tests/__init__.py +0 -0
  72. {sciform-0.38.0 → sciform-0.38.2}/tests/feature/__init__.py +0 -0
  73. {sciform-0.38.0 → sciform-0.38.2}/tests/feature/test_global_config.py +0 -0
  74. {sciform-0.38.0 → sciform-0.38.2}/tests/feature/test_options_printout.py +0 -0
  75. {sciform-0.38.0 → sciform-0.38.2}/tests/feature/test_output_conversion.py +0 -0
  76. {sciform-0.38.0 → sciform-0.38.2}/tests/feature/test_sci_num.py +0 -0
  77. {sciform-0.38.0 → sciform-0.38.2}/tests/feature/test_separators.py +0 -0
  78. {sciform-0.38.0 → sciform-0.38.2}/tests/feature/test_string_parser.py +0 -0
  79. {sciform-0.38.0 → sciform-0.38.2}/tests/feature/test_val_formatter.py +0 -0
  80. {sciform-0.38.0 → sciform-0.38.2}/tests/feature/test_val_fsml.py +0 -0
  81. {sciform-0.38.0 → sciform-0.38.2}/tests/feature/test_val_unc_formatter.py +0 -0
  82. {sciform-0.38.0 → sciform-0.38.2}/tests/feature/test_val_unc_fsml.py +0 -0
  83. {sciform-0.38.0 → sciform-0.38.2}/tests/test_docstrings.py +0 -0
  84. {sciform-0.38.0 → sciform-0.38.2}/tests/unit/__init__.py +0 -0
  85. {sciform-0.38.0 → sciform-0.38.2}/tests/unit/format_utils/__init__.py +0 -0
  86. {sciform-0.38.0 → sciform-0.38.2}/tests/unit/format_utils/test_exp_translations.py +0 -0
  87. {sciform-0.38.0 → sciform-0.38.2}/tests/unit/format_utils/test_exponent_utils.py +0 -0
  88. {sciform-0.38.0 → sciform-0.38.2}/tests/unit/format_utils/test_grouping.py +0 -0
  89. {sciform-0.38.0 → sciform-0.38.2}/tests/unit/format_utils/test_make_strings.py +0 -0
  90. {sciform-0.38.0 → sciform-0.38.2}/tests/unit/format_utils/test_number_utils.py +0 -0
  91. {sciform-0.38.0 → sciform-0.38.2}/tests/unit/format_utils/test_rounding_utils.py +0 -0
  92. {sciform-0.38.0 → sciform-0.38.2}/tests/unit/test_invalid_options.py +0 -0
  93. {sciform-0.38.0 → sciform-0.38.2}/tests/unit/test_options_strings.py +0 -0
  94. {sciform-0.38.0 → sciform-0.38.2}/tests/unit/test_validation.py +0 -0
@@ -14,6 +14,32 @@ Unreleased
14
14
 
15
15
  ----
16
16
 
17
+ 0.38.2 (2024-11-02)
18
+ -------------------
19
+
20
+ Fixed
21
+ -----
22
+
23
+ * Corrected a typo in a previous release.
24
+
25
+ ----
26
+
27
+ 0.38.1 (2024-11-02)
28
+ -------------------
29
+
30
+ Added
31
+ -----
32
+
33
+ * Documented examples demonstrating the interplay between ``sciform``
34
+ formatting the ``decimal`` module configuration.
35
+ [`#183 <https://github.com/jagerber48/sciform/issues/183>`_]
36
+ * Added an example demonstrating how users can implement a "fallback"
37
+ formatter for cases when users want different formatting behavior
38
+ applied when the uncertainty is invalid or not present.
39
+ [`#177 <https://github.com/jagerber48/sciform/issues/177>`_]
40
+
41
+ ----
42
+
17
43
  0.38.0 (2024-11-02)
18
44
  -------------------
19
45
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sciform
3
- Version: 0.38.0
3
+ Version: 0.38.2
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.0
3
+ Version: 0.38.2
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