Releases: jagerber48/sciform
0.39.0
0.39.0 (2024-11-15)
Removed
- Removed all support for base-2 formatting. The
sciform
package will focus on base-10 scientific formatting, more relevent for the physical sciences, unless there is demand for base-2 or base-n
formatting. We encourage users to consider the prefixed package if they have requirements for base-2 formatting. [#201]
0.38.2
0.38.2 (2024-11-02)
Fixed
- Corrected a typo in a previous release.
0.38.1
0.38.1 (2024-11-02)
Added
- Documented examples demonstrating the interplay between
sciform
formatting thedecimal
module configuration. [#183] - Added an example demonstrating how users can implement a "fallback" formatter for cases when users want different formatting behavior applied when the uncertainty is invalid or not present. [#177]
0.38.0
0.38.0 (2024-11-02)
Added
- Digits-past-the-decimal formatting (
round_mode="dec_place"
) is now supported for value/uncertainty pairs. #170 round_mode="all"
andround_mode="pdg"
options can now be accessed in the FSML using"A"
and"P"
flags. #192- Added a dark theme option (default on) for readthedocs documentation.
- Added code coverage breakdown for unit and feature tests to codecov CI.
Changed
- [BREAKING] Rounding configuration has been refactored. Previously
round_mode
accepted only"sig_fig"
and"dec_place"
string literals, all digits rounding mode was selected by settingsndigits = AutoDigits
and PDG rounding mode was selected by settingpdg_sig_figs = True
. Nowround_mode
accepts"sig_fig"
,"dec_place"
,"pdg"
and"all"
string literals,ndigits
only accepts integers, and thepdg_sig_figs
option is removed.round_mode
defaults to"all"
andndigits
defaults to 2. #185 - [BREAKING] Previously
exp_val
andndigits
accepted the enumsAutoExpVal
andAutoDigits
. Nowexp_val
accepts the string literal"auto"
andndigits
only accepts integers. #178, #185 - Previously, significant figure rounding with a value of
0
would result in trailing zeros being added in the formatted output. For example,format(SciNum(0), "!3f")
would give"0.00"
orformat(SciNum(0, float("nan")), "!2f")
would give"0.0 ± nan"
. This is not reasonable because zero doesn't have any significant figures, so it doesn't make sense to add more trailing zeros to indicate additional "fake" significant figures. Now if zero is used for significant figure rounding it always appears directly as"0"
. E.g.format(SciNum(0), "!3f")
gives"0"
andformat(SciNum(0, float("nan")), "!2f")
gives"0 ± nan"
. Note that, as before, trailing zeros may still be added to a zero value if the uncertainty is less than one, e.g.format(SciNum(0, 0.0012), "!2f")
gives"0.0000 ± 0.0012"
. #189 - Previously the backend
FinalizedOptions
class ran a validation check on itself after initialization. This check has been removed in favor of not complicating the validation code to handle the above change toexp_val
andndigits
. Users never directly instantiateFinalizedOptions
so this will hopefully be no problem.InputOptions
continue to be validated because this is the direct result of user input.PopulatedOptions
also must continue to be validated because options conflicts due to the combination of user input with global options can arise at options population time. - Update
ruff
version in pre-commit config.
Removed
- The
pdg_sig_figs
options has been removed. This option is now configured by settinground_mode="pdg"
.
Fixed
- The
ruff
version in the GitHub CI now matches theruff
in the local pre-commit configuration.
0.37.0
0.36.0
0.36.0 (2024-03-07)
Added
- Added many unit test to supplement the feature existing feature tests. [#102]
- Added much more input validation and corresponding messaging.
- Checks on input types and values.
- Extra translations dictionaries are now checked so that keys must be integers and values must consist of only English alphabetic characters. [#157]
Changed
- Major code reorganization. [#152]
- Move modules containing public interfaces into an
api
sub-package. - Break the bulky
format_utils
module into multiple modules, now in aformat_utils
sub-package. - Collect the main formatting algorithms into a
formatting
sub-package. - Sort tests into feature and unit tests.
- Move modules containing public interfaces into an
- Some utility code refactoring.
Fixed
- Fixed a bug where uncertainties between the Particle Data Group uncertainties thresholds would erroneously result in
ValueError
being raised when formatted withpdg_sig_figs=True
. [#164]
0.35.0
0.35.0 (2024-02-16)
Added
- The
Formatter
formatting method and theSciNum
constructor now accept formatted inputs for the value and optional uncertainty inputs. E.g.formatter("123.456(7)e-03")
orSciNum("24 +/- 2")
are now valid inputs. [#104] - Added the
paren_uncertainties_trim
option.
The previous behavior wasparen_uncertainties_trim=True
. Nowparen_uncertainties_trim=False
allows a more verbose presentation of the uncertainty inparen_uncertainty
mode in which leading zeros and separator characters are not stripped from the string. E.g.paren_uncertainties_trim=True
will give
123.002 3(21)
whileparen_uncertainties_trim=False
will give
123.002 3(0.002 1) - Added
value
anduncertainty
attributes to theFormattedNumber
class. - Added badge for Zenodo.
Removed
- [BREAKING] Removed the
paren_uncertainties_separators
option. This option made it possible (whenFalse
) to optionally strip all separator characters, including the decimal separator, from the uncertainty inparen_uncertainty
mode. This lead to the possibility of value/uncertainty pairs like
123 456.789 8 ± 123.456 7
being represented as
123 456.789 8(1234567)
sciform
will now display this as
123 456.789 8(123.456 7)
ifparen_uncertainty_strip=False
or
123 456.789 8(123.4567)
ifparen_uncertainty_strip=True
, but always retaining the decimal separator. In most cases many fewer significant digits of the uncertainty are displayed and the resulting outputs don't look as egregious when the decimal separator is stripped. Nonetheless, given that more outputs look better when the decimal is retained and that there is no official BIPM guidance on how parentheses should handle cases when the uncertainty digits span decimal or other separator characters,sciform
will not presently provide an option to strip the decimal separator character.
Changed
- Previously, when using
paren_uncertainty=True
, redundant parentheses were included around the value and uncertainty numbers if there was an ASCII exponent (e.g.e+02
) or in percent formatting mode. E.g. outputs would look like(32.4(1.2))e+02
or(32.4(1.2))%
. Now these redundant parentheses are excluded so outputs look like32.4(1.2)e+02
or32.4(1.2)%
. This is consistent with how the uncertainties package handles these cases. The extra parentheses were originally included for increased clarity, but the extra parentheses only clutter the output and there is sufficient clarity without them. This change eliminates an issue where the redundant parentheses were erroneously included or excluded after LaTeX/HTML/ASCII output conversion. [#145]
Fixed
- Previously, when formatting individual
Decimal
input values, the values were always normalized at an early stage in formatting. This meant that even ifndigits=AutoDigits
thenDecimal("1.0")
would be formatted the same asDecimal("1.00")
. However, for value/uncertainty formatting,Decimal
input to the uncertainty was not necessarily normalized at an early stage. This meant that withndigits=AutoDigits
, an uncertainty ofDecimal("1.0")
would be formatted to the tenths decimal place while an uncertainty ofDecimal("1.00")
would be formatted to the hundredths place. This behavior was inconsistent and undocumented. Now allDecimal
inputs are immediately normalized before any formatting. [#148] - Fixed the behavior around the sign symbols for zero and non-finite inputs. Previously
0
was treated as positive for the sake of resolving its sign symbol, the sign of infinite numbers was preserved but+inf
did not respect the"+"
and" "
sign modes, andnan
never had a sign but also never had an extra character added for"+"
or" "
sign modes. Now both0
andnan
are treated as having no sign. In both"+"
and" "
sign modes0
andnan
are prepended by a space. The sign of infinite numbers is retained as before, but now formatting of these numbers respects the sign mode. [#147]
0.34.1
0.34.1 (2024-02-10)
Added
- Updated the readme to reflect completion of the PyOpenSci review.
0.34.0
0.34.0 (2024-02-04)
Added
- The
Formatter
now exposes theinput_options
andpopulated_options
attributes. Theinput_options
attribute holds anInputOptions
object which stores a record of the input options passed into theFormatter
. Thepopulated_options
attribute returns aPopulatedOptions
object which shows the complete set of populated options which will be used for formatting after merging with the global options. Note that thepopulated_options
attribute is re-calculated each time it is access so that it reflects the current global options. Both theInputOptions
andPopulatedOptions
objects can be used to provide string representations of the options, or provide programmatic access to the options via either attribute access or theas_dict()
methods. [#110] - The
PopulatedOptions
used during formatting of a givenFormattedNumber
instance are stored on that instance for future
reference. - Added
get_default_global_options()
. - Now integer
0
can be passed intoleft_pad_char
to get the same behavior as string"0"
. [#128] - Added tests for docstrings.
Changed
-
[BREAKING] Renamed functions for configuring global options:
set_global_defaults()
->set_global_options()
reset_global_defaults()
->reset_global_options()
GlobalDefaultsContext()
->GlobalOptionsContext()
-
Refactored backend options handling code. Previously,
UserOptions
were rendered intoRenderedOptions
. During rendering the global options were appropriately merged in andsome string literal options were replaced with enums for internal use. These two classes were private. Now there areInputOptions
(which try to faithfully record user input),PopulatedOptions
(which capture the result of merging the global options into the input options, but still using user-friendly string representations of all options), andFinalizedOptions
(which use the internal enum representations ofcertain options). TheInputOptions
andPopulatedOptions
are now public while theFinalizedOptions
is still private to shield the enum representations from the users. This sizable refactor was precipitated by the publicizing of the options. [#110]
Removed
- [BREAKING] Removed
print_global_defaults()
in favor ofget_global_defaults()
which now returns aPopulatedOptions
object which can be printed by the user if desired.
Fixed
- Fixed a bug where
SciNum
formatting resulted instr
objects instead ofFormattedNumber
objects.
0.33.0
0.33.0 (2024-01-31)
Added
- Added the
FormattedNumber
class. This class is a subclass ofstr
and is now returned by theFormatter
instead ofstr
. TheFormattedNumber
class allows post-conversion to ASCII, HTML, and LaTeX formats. [#114 <https://github.com/jagerber48/sciform/issues/114>
_] - Added separate flags for code coverage reports for each python version.
Changed
-
In addition to removing the
latex
option from theFormatter
in favor of the introduction of theFormattedNumber
class, the LaTeX conversion algorithm has been slightly modified.- Left and right parentheses are no longer converted to
"\left("
and"\right)"
due to introducing strange spacing issues. SeeSpacing around \\left and \\right <https://tex.stackexchange.com/questions/2607/spacing-around-left-and-right>
_. - Previously spaces within the
sciform
output were handled inconsistently and occasionally required confusing extra handling. Now any spaces in the input string are directly and explicitly converted into math mode medium spaces:"\:"
. "μ"
is now included in the math mode\text{}
environment and converted to"\textmu"
.
- Left and right parentheses are no longer converted to
-
[BREAKING] Renamed
fill_char
toleft_pad_char
. [#126 <https://github.com/jagerber48/sciform/issues/126>
_] -
Slimmed down
[dev]
optional dependencies and created[examples]
optional dependencies. The former includes development tools, while the latter includes the heavy-weight requirements needed to run all the examples, including, e.g.jupyter
,scipy
, etc. -
Cleaned up and improved github actions for testing and linting/formatting. [
#136 <https://github.com/jagerber48/sciform/issues/136>
_]- Use
unittest
andcoverage
instead ofpytest
. - The requirements to run the automation match the
[dev]
optional dependencies. - Cache
pip
requirements to avoid unnecessarily downloading dependencies. - Remove a defunct
blackdoc
test. Hopefully this can be replaced whenruff
provides functionality for formatting.rst
files.
- Use
Fixed
- Fixed a bug where value/uncertainty pairs formatted in the
"parts_per"
format with zero exponent would appear with redundant parentheses, e.g."(1.2 ± 0.1)"
. [#130 <https://github.com/jagerber48/sciform/issues/130>
_]
Removed
- [BREAKING] Removed the
latex
option in favor of the introduction of theFormattedNumber.as_latex()
method. This removal simplifies the formatting algorithm by separating LaTeX formatting from other tasks like exponent string resolution. Thelatex
option also introduced a potential confusion with thesuperscript
option, which had no effect whenlatex=True
.