From 143174e737d3b873238f1131e1def1cbd0fed6f8 Mon Sep 17 00:00:00 2001 From: Justin Date: Sat, 4 Nov 2023 13:40:26 -0600 Subject: [PATCH 1/8] =?UTF-8?q?replace=20+/-=20with=20=C2=B1=20in=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_val_unc_formatter.py | 53 +++----- tests/test_val_unc_fsml.py | 220 ++++++++++++++++---------------- 2 files changed, 128 insertions(+), 145 deletions(-) diff --git a/tests/test_val_unc_formatter.py b/tests/test_val_unc_formatter.py index 55c7f913..898bd700 100644 --- a/tests/test_val_unc_formatter.py +++ b/tests/test_val_unc_formatter.py @@ -108,7 +108,7 @@ def test_percent(self): ((0.123_456_78, 0.000_002_55), [ (FormatOptions(exp_mode=ExpMode.PERCENT, lower_separator=GroupingSeparator.UNDERSCORE), - '(12.345_678 +/- 0.000_255)%'), + '(12.345_678 ± 0.000_255)%'), (FormatOptions(exp_mode=ExpMode.PERCENT, bracket_unc=True, lower_separator=GroupingSeparator.UNDERSCORE), @@ -148,17 +148,8 @@ def test_bracket_unc_remove_dec_symb(self): def test_unc_pm_whitespace(self): cases_list = [ ((123.456, 0.789), [ - (FormatOptions(unc_pm_whitespace=True), '123.456 +/- 0.789'), - (FormatOptions(unc_pm_whitespace=False), '123.456+/-0.789') - ]) - ] - - self.run_val_unc_formatter_cases(cases_list) - - def test_unicode_pm(self): - cases_list = [ - ((123.456, 0.789), [ - (FormatOptions(unicode_pm=True), '123.456 ± 0.789') + (FormatOptions(unc_pm_whitespace=True), '123.456 ± 0.789'), + (FormatOptions(unc_pm_whitespace=False), '123.456±0.789') ]) ] @@ -169,7 +160,7 @@ def test_superscript_exp(self): ((789, 0.01), [ (FormatOptions( exp_mode=ExpMode.SCIENTIFIC, - superscript_exp=True), '(7.8900 +/- 0.0001)×10²') + superscript_exp=True), '(7.8900 ± 0.0001)×10²') ]) ] @@ -183,14 +174,6 @@ def test_latex(self): upper_separator=GroupingSeparator.UNDERSCORE, latex=True), r'\left(123\_450 \pm 2\right)\times 10^{-1}'), - - # Latex mode takes precedence over unicode_pm - (FormatOptions(exp_mode=ExpMode.SCIENTIFIC, - exp_val=-1, - upper_separator=GroupingSeparator.UNDERSCORE, - unicode_pm=True, - latex=True), - r'\left(123\_450 \pm 2\right)\times 10^{-1}'), (FormatOptions(exp_mode=ExpMode.SCIENTIFIC, exp_format=ExpFormat.PREFIX, exp_val=3, @@ -215,27 +198,27 @@ def test_latex(self): def test_pdg(self): cases_list = [ ((10, 0.0353), [ - (FormatOptions(pdg_sig_figs=True), '10.000 +/- 0.035') + (FormatOptions(pdg_sig_figs=True), '10.000 ± 0.035') ]), ((10, 0.0354), [ - (FormatOptions(pdg_sig_figs=True), '10.000 +/- 0.035') + (FormatOptions(pdg_sig_figs=True), '10.000 ± 0.035') ]), ((10, 0.0355), [ - (FormatOptions(pdg_sig_figs=True), '10.00 +/- 0.04') + (FormatOptions(pdg_sig_figs=True), '10.00 ± 0.04') ]), ((10, 0.0949), [ - (FormatOptions(pdg_sig_figs=True), '10.00 +/- 0.09') + (FormatOptions(pdg_sig_figs=True), '10.00 ± 0.09') ]), ((10, 0.0950), [ - (FormatOptions(pdg_sig_figs=True), '10.00 +/- 0.10') + (FormatOptions(pdg_sig_figs=True), '10.00 ± 0.10') ]), ((10, 0.0951), [ - (FormatOptions(pdg_sig_figs=True), '10.00 +/- 0.10') + (FormatOptions(pdg_sig_figs=True), '10.00 ± 0.10') ]), ((3141592.7, 1618), [ (FormatOptions(exp_mode=ExpMode.ENGINEERING, exp_format=ExpFormat.PREFIX, - pdg_sig_figs=True), '(3.1416 +/- 0.0016) M') + pdg_sig_figs=True), '(3.1416 ± 0.0016) M') ]) ] @@ -244,22 +227,22 @@ def test_pdg(self): def test_pdg_invalid_unc(self): cases_list = [ ((123, 0), [ - (FormatOptions(pdg_sig_figs=True), '123 +/- 0') + (FormatOptions(pdg_sig_figs=True), '123 ± 0') ]), ((-123, 0), [ - (FormatOptions(pdg_sig_figs=True), '-123 +/- 0') + (FormatOptions(pdg_sig_figs=True), '-123 ± 0') ]), ((0, 0), [ - (FormatOptions(pdg_sig_figs=True), '0 +/- 0') + (FormatOptions(pdg_sig_figs=True), '0 ± 0') ]), ((123, float('nan')), [ - (FormatOptions(pdg_sig_figs=True), '123 +/- nan') + (FormatOptions(pdg_sig_figs=True), '123 ± nan') ]), ((-123, float('nan')), [ - (FormatOptions(pdg_sig_figs=True), '-123 +/- nan') + (FormatOptions(pdg_sig_figs=True), '-123 ± nan') ]), ((0, float('nan')), [ - (FormatOptions(pdg_sig_figs=True), '0 +/- nan') + (FormatOptions(pdg_sig_figs=True), '0 ± nan') ]) ] @@ -276,7 +259,7 @@ def test_binary(self): is implemented """ sform = Formatter(FormatOptions(exp_mode=ExpMode.BINARY)) - self.assertEqual(sform(1024, 32), '(1.00000 +/- 0.03125)b+10') + self.assertEqual(sform(1024, 32), '(1.00000 ± 0.03125)b+10') def test_pdg_ndigits_error(self): self.assertRaises(ValueError, FormatOptions, pdg_sig_figs=True, diff --git a/tests/test_val_unc_fsml.py b/tests/test_val_unc_fsml.py index 255c8055..18c57a38 100644 --- a/tests/test_val_unc_fsml.py +++ b/tests/test_val_unc_fsml.py @@ -23,30 +23,30 @@ def run_val_unc_fsml_cases(self, cases_list: ValUncFSMLCases): def test_fixed(self): cases_list = [ ((123.456, 0.789), [ - ('f', '123.456 +/- 0.789'), - ('!1f', '123.5 +/- 0.8'), - ('!2f', '123.46 +/- 0.79'), - ('!3f', '123.456 +/- 0.789'), - ('!4f', '123.4560 +/- 0.7890'), + ('f', '123.456 ± 0.789'), + ('!1f', '123.5 ± 0.8'), + ('!2f', '123.46 ± 0.79'), + ('!3f', '123.456 ± 0.789'), + ('!4f', '123.4560 ± 0.7890'), ('!2f()', '123.46(79)') ]), ((-123.456, 0.789), [ - ('f', '-123.456 +/- 0.789'), - ('!1f', '-123.5 +/- 0.8'), - ('!2f', '-123.46 +/- 0.79'), - ('!3f', '-123.456 +/- 0.789'), - ('!4f', '-123.4560 +/- 0.7890'), + ('f', '-123.456 ± 0.789'), + ('!1f', '-123.5 ± 0.8'), + ('!2f', '-123.46 ± 0.79'), + ('!3f', '-123.456 ± 0.789'), + ('!4f', '-123.4560 ± 0.7890'), ('!2f()', '-123.46(79)') ]), ((0.789, 123.456), [ - ('f', '0.789 +/- 123.456'), - ('!1f', '0 +/- 100'), - ('!2f', '0 +/- 120'), - ('!3f', '1 +/- 123'), - ('!4f', '0.8 +/- 123.5'), - ('!5f', '0.79 +/- 123.46'), - ('!6f', '0.789 +/- 123.456'), - ('!7f', '0.7890 +/- 123.4560'), + ('f', '0.789 ± 123.456'), + ('!1f', '0 ± 100'), + ('!2f', '0 ± 120'), + ('!3f', '1 ± 123'), + ('!4f', '0.8 ± 123.5'), + ('!5f', '0.79 ± 123.46'), + ('!6f', '0.789 ± 123.456'), + ('!7f', '0.7890 ± 123.4560'), ('!1f()', '0(100)'), ('!2f()', '0(120)'), ('!3f()', '1(123)'), @@ -56,14 +56,14 @@ def test_fixed(self): ('!7f()', '0.7890(123.4560)') ]), ((-0.789, 123.456), [ - ('f', '-0.789 +/- 123.456'), - ('!1f', '0 +/- 100'), - ('!2f', '0 +/- 120'), - ('!3f', '-1 +/- 123'), - ('!4f', '-0.8 +/- 123.5'), - ('!5f', '-0.79 +/- 123.46'), - ('!6f', '-0.789 +/- 123.456'), - ('!7f', '-0.7890 +/- 123.4560'), + ('f', '-0.789 ± 123.456'), + ('!1f', '0 ± 100'), + ('!2f', '0 ± 120'), + ('!3f', '-1 ± 123'), + ('!4f', '-0.8 ± 123.5'), + ('!5f', '-0.79 ± 123.46'), + ('!6f', '-0.789 ± 123.456'), + ('!7f', '-0.7890 ± 123.4560'), ('!1f()', '0(100)'), ('!2f()', '0(120)'), ('!3f()', '-1(123)'), @@ -79,22 +79,22 @@ def test_fixed(self): def test_scientific(self): cases_list = [ ((123.456, 0.789), [ - ('e', '(1.23456 +/- 0.00789)e+02'), - ('!1e', '(1.235 +/- 0.008)e+02'), - ('!2e', '(1.2346 +/- 0.0079)e+02'), - ('!3e', '(1.23456 +/- 0.00789)e+02'), - ('!4e', '(1.234560 +/- 0.007890)e+02'), + ('e', '(1.23456 ± 0.00789)e+02'), + ('!1e', '(1.235 ± 0.008)e+02'), + ('!2e', '(1.2346 ± 0.0079)e+02'), + ('!3e', '(1.23456 ± 0.00789)e+02'), + ('!4e', '(1.234560 ± 0.007890)e+02'), ('!2e()', '(1.2346(79))e+02'), ]), ((0.789, 123.456), [ - ('e', '(0.00789 +/- 1.23456)e+02'), - ('!1e', '(0 +/- 1)e+02'), - ('!2e', '(0.0 +/- 1.2)e+02'), - ('!3e', '(0.01 +/- 1.23)e+02'), - ('!4e', '(0.008 +/- 1.235)e+02'), - ('!5e', '(0.0079 +/- 1.2346)e+02'), - ('!6e', '(0.00789 +/- 1.23456)e+02'), - ('!7e', '(0.007890 +/- 1.234560)e+02'), + ('e', '(0.00789 ± 1.23456)e+02'), + ('!1e', '(0 ± 1)e+02'), + ('!2e', '(0.0 ± 1.2)e+02'), + ('!3e', '(0.01 ± 1.23)e+02'), + ('!4e', '(0.008 ± 1.235)e+02'), + ('!5e', '(0.0079 ± 1.2346)e+02'), + ('!6e', '(0.00789 ± 1.23456)e+02'), + ('!7e', '(0.007890 ± 1.234560)e+02'), ('!1e()', '(0(1))e+02'), ('!2e()', '(0.0(1.2))e+02'), ('!3e()', '(0.01(1.23))e+02'), @@ -104,14 +104,14 @@ def test_scientific(self): ('!7e()', '(0.007890(1.234560))e+02'), ]), ((0, 123.456), [ - ('e', '(0.00000 +/- 1.23456)e+02'), - ('!1e', '(0 +/- 1)e+02'), - ('!2e', '(0.0 +/- 1.2)e+02'), - ('!3e', '(0.00 +/- 1.23)e+02'), - ('!4e', '(0.000 +/- 1.235)e+02'), - ('!5e', '(0.0000 +/- 1.2346)e+02'), - ('!6e', '(0.00000 +/- 1.23456)e+02'), - ('!7e', '(0.000000 +/- 1.234560)e+02'), + ('e', '(0.00000 ± 1.23456)e+02'), + ('!1e', '(0 ± 1)e+02'), + ('!2e', '(0.0 ± 1.2)e+02'), + ('!3e', '(0.00 ± 1.23)e+02'), + ('!4e', '(0.000 ± 1.235)e+02'), + ('!5e', '(0.0000 ± 1.2346)e+02'), + ('!6e', '(0.00000 ± 1.23456)e+02'), + ('!7e', '(0.000000 ± 1.234560)e+02'), ('!1e()', '(0(1))e+02'), ('!2e()', '(0.0(1.2))e+02'), ('!3e()', '(0.00(1.23))e+02'), @@ -127,22 +127,22 @@ def test_scientific(self): def test_engineering(self): cases_list = [ ((1234.56, 0.789), [ - ('r', '(1.234560 +/- 0.000789)e+03'), - ('!1r', '(1.2346 +/- 0.0008)e+03'), - ('!2r', '(1.23456 +/- 0.00079)e+03'), - ('!3r', '(1.234560 +/- 0.000789)e+03'), - ('!4r', '(1.2345600 +/- 0.0007890)e+03'), + ('r', '(1.234560 ± 0.000789)e+03'), + ('!1r', '(1.2346 ± 0.0008)e+03'), + ('!2r', '(1.23456 ± 0.00079)e+03'), + ('!3r', '(1.234560 ± 0.000789)e+03'), + ('!4r', '(1.2345600 ± 0.0007890)e+03'), ('!2r()', '(1.23456(79))e+03'), ]), ((0.789, 123.456), [ - ('r', '(0.789 +/- 123.456)e+00'), - ('!1r', '(0 +/- 100)e+00'), - ('!2r', '(0 +/- 120)e+00'), - ('!3r', '(1 +/- 123)e+00'), - ('!4r', '(0.8 +/- 123.5)e+00'), - ('!5r', '(0.79 +/- 123.46)e+00'), - ('!6r', '(0.789 +/- 123.456)e+00'), - ('!7r', '(0.7890 +/- 123.4560)e+00'), + ('r', '(0.789 ± 123.456)e+00'), + ('!1r', '(0 ± 100)e+00'), + ('!2r', '(0 ± 120)e+00'), + ('!3r', '(1 ± 123)e+00'), + ('!4r', '(0.8 ± 123.5)e+00'), + ('!5r', '(0.79 ± 123.46)e+00'), + ('!6r', '(0.789 ± 123.456)e+00'), + ('!7r', '(0.7890 ± 123.4560)e+00'), ('!1r()', '(0(100))e+00'), ('!2r()', '(0(120))e+00'), ('!3r()', '(1(123))e+00'), @@ -158,22 +158,22 @@ def test_engineering(self): def test_engineering_shifted(self): cases_list = [ ((123.456, 0.789), [ - ('#r', '(0.123456 +/- 0.000789)e+03'), - ('#!1r', '(0.1235 +/- 0.0008)e+03'), - ('#!2r', '(0.12346 +/- 0.00079)e+03'), - ('#!3r', '(0.123456 +/- 0.000789)e+03'), - ('#!4r', '(0.1234560 +/- 0.0007890)e+03'), + ('#r', '(0.123456 ± 0.000789)e+03'), + ('#!1r', '(0.1235 ± 0.0008)e+03'), + ('#!2r', '(0.12346 ± 0.00079)e+03'), + ('#!3r', '(0.123456 ± 0.000789)e+03'), + ('#!4r', '(0.1234560 ± 0.0007890)e+03'), ('#!2r()', '(0.12346(79))e+03') ]), ((0.789, 123.456), [ - ('#r', '(0.000789 +/- 0.123456)e+03'), - ('#!1r', '(0.0 +/- 0.1)e+03'), - ('#!2r', '(0.00 +/- 0.12)e+03'), - ('#!3r', '(0.001 +/- 0.123)e+03'), - ('#!4r', '(0.0008 +/- 0.1235)e+03'), - ('#!5r', '(0.00079 +/- 0.12346)e+03'), - ('#!6r', '(0.000789 +/- 0.123456)e+03'), - ('#!7r', '(0.0007890 +/- 0.1234560)e+03'), + ('#r', '(0.000789 ± 0.123456)e+03'), + ('#!1r', '(0.0 ± 0.1)e+03'), + ('#!2r', '(0.00 ± 0.12)e+03'), + ('#!3r', '(0.001 ± 0.123)e+03'), + ('#!4r', '(0.0008 ± 0.1235)e+03'), + ('#!5r', '(0.00079 ± 0.12346)e+03'), + ('#!6r', '(0.000789 ± 0.123456)e+03'), + ('#!7r', '(0.0007890 ± 0.1234560)e+03'), ('#!1r()', '(0.0(0.1))e+03'), ('#!2r()', '(0.00(0.12))e+03'), ('#!3r()', '(0.001(0.123))e+03'), @@ -189,7 +189,7 @@ def test_engineering_shifted(self): def test_percent(self): cases_list = [ ((0.12462, 0.0001), [ - ('%', '(12.46 +/- 0.01)%'), + ('%', '(12.46 ± 0.01)%'), ('%()', '(12.46(1))%') ]) ] @@ -241,12 +241,12 @@ def test_bracket_unc(self): def test_match_width(self): cases_list = [ ((123.456, 0.789), [ - ('0!2f', '123.46 +/- 0.79'), - ('0=0!2f', '123.46 +/- 000.79') + ('0!2f', '123.46 ± 0.79'), + ('0=0!2f', '123.46 ± 000.79') ]), ((0.789, 123.456), [ - ('0!2f', ' 0 +/- 120'), - ('0=0!2f', '000 +/- 120') + ('0!2f', ' 0 ± 120'), + ('0=0!2f', '000 ± 120') ]) ] @@ -255,33 +255,33 @@ def test_match_width(self): def test_nan_inf(self): cases_list = [ ((12.34, NAN), [ - ('', '12.34 +/- nan'), - ('e', '(1.234 +/- nan)e+01'), + ('', '12.34 ± nan'), + ('e', '(1.234 ± nan)e+01'), ('()', '12.34(nan)'), ('e()', '(1.234(nan))e+01') ]), ((12.34, INF), [ - ('', '12.34 +/- inf'), - ('e', '(1.234 +/- inf)e+01'), + ('', '12.34 ± inf'), + ('e', '(1.234 ± inf)e+01'), ('()', '12.34(inf)'), ('e()', '(1.234(inf))e+01') ]), ((NAN, 12.34), [ - ('', 'nan +/- 12.34'), - ('e', '(nan +/- 1.234)e+01'), + ('', 'nan ± 12.34'), + ('e', '(nan ± 1.234)e+01'), ('()', 'nan(12.34)'), ('e()', '(nan(1.234))e+01') ]), ((INF, 12.34), [ - ('', 'inf +/- 12.34'), - ('e', '(inf +/- 1.234)e+01'), + ('', 'inf ± 12.34'), + ('e', '(inf ± 1.234)e+01'), ('()', 'inf(12.34)'), ('e()', '(inf(1.234))e+01') ]), ((NAN, NAN), [ - ('', 'nan +/- nan'), + ('', 'nan ± nan'), ('()', 'nan(nan)'), - ('e', 'nan +/- nan'), + ('e', 'nan ± nan'), ('e()', 'nan(nan)') ]) ] @@ -291,8 +291,8 @@ def test_nan_inf(self): def test_nan_inf_exp(self): cases_list = [ ((NAN, NAN), [ - ('', 'nan +/- nan'), - ('e', '(nan +/- nan)e+00'), + ('', 'nan ± nan'), + ('e', '(nan ± nan)e+00'), ('()', 'nan(nan)'), ('e()', '(nan(nan))e+00') ]) @@ -303,16 +303,16 @@ def test_nan_inf_exp(self): def test_capitalization(self): cases_list = [ ((123.456, 0.789), [ - ('e', '(1.23456 +/- 0.00789)e+02'), - ('E', '(1.23456 +/- 0.00789)E+02') + ('e', '(1.23456 ± 0.00789)e+02'), + ('E', '(1.23456 ± 0.00789)E+02') ]), ((NAN, NAN), [ - ('e', '(nan +/- nan)e+00'), - ('E', '(NAN +/- NAN)E+00') + ('e', '(nan ± nan)e+00'), + ('E', '(NAN ± NAN)E+00') ]), ((INF, INF), [ - ('e', '(inf +/- inf)e+00'), - ('E', '(INF +/- INF)E+00') + ('e', '(inf ± inf)e+00'), + ('E', '(INF ± INF)E+00') ]) ] @@ -322,10 +322,10 @@ def test_capitalization(self): def test_rounding(self): cases_list = [ ((0.0999, 0.0999), [ - ('!1e', '(1 +/- 1)e-01') + ('!1e', '(1 ± 1)e-01') ]), ((0.0999, 0.999), [ - ('!1e', '(0 +/- 1)e+00') + ('!1e', '(0 ± 1)e+00') ]) ] self.run_val_unc_fsml_cases(cases_list) @@ -333,18 +333,18 @@ def test_rounding(self): def test_match_widths(self): cases_list = [ ((123.456, 0.789), [ - ('0=0', '123.456 +/- 000.789'), - ('0= 0', ' 123.456 +/- 000.789'), - (' 0', ' 123.456 +/- 0.789'), - ('+0', '+123.456 +/- 0.789'), - ('0', '123.456 +/- 0.789') + ('0=0', '123.456 ± 000.789'), + ('0= 0', ' 123.456 ± 000.789'), + (' 0', ' 123.456 ± 0.789'), + ('+0', '+123.456 ± 0.789'), + ('0', '123.456 ± 0.789') ]), ((0.789, 123.456), [ - ('0=0', '000.789 +/- 123.456'), - ('0= 0', ' 000.789 +/- 123.456'), - (' 0', ' 0.789 +/- 123.456'), - ('+0', '+ 0.789 +/- 123.456'), - ('0', ' 0.789 +/- 123.456') + ('0=0', '000.789 ± 123.456'), + ('0= 0', ' 000.789 ± 123.456'), + (' 0', ' 0.789 ± 123.456'), + ('+0', '+ 0.789 ± 123.456'), + ('0', ' 0.789 ± 123.456') ]) ] self.run_val_unc_fsml_cases(cases_list) @@ -352,8 +352,8 @@ def test_match_widths(self): def test_prefix(self): cases_list = [ ((123.456, 0.789), [ - ('ex+3p', '(0.123456 +/- 0.000789) k'), - ('ex-3p', '(123456 +/- 789) m') + ('ex+3p', '(0.123456 ± 0.000789) k'), + ('ex-3p', '(123456 ± 789) m') ],) ] self.run_val_unc_fsml_cases(cases_list) From cd7bc42dc4e4b41cd075ab17192fdc19dfa629d2 Mon Sep 17 00:00:00 2001 From: Justin Date: Sat, 4 Nov 2023 22:07:01 -0600 Subject: [PATCH 2/8] update code to pass tests --- src/sciform/format_options.py | 6 ------ src/sciform/formatting.py | 4 +--- tests/test_print.py | 2 -- 3 files changed, 1 insertion(+), 11 deletions(-) diff --git a/src/sciform/format_options.py b/src/sciform/format_options.py index 72d78e50..9fae17b5 100644 --- a/src/sciform/format_options.py +++ b/src/sciform/format_options.py @@ -32,7 +32,6 @@ class RenderedFormatOptions: pdg_sig_figs: bool val_unc_match_widths: bool bracket_unc_remove_seps: bool - unicode_pm: bool unc_pm_whitespace: bool def __post_init__(self): @@ -164,9 +163,6 @@ class FormatOptions: separator symbols should be removed from the uncertainty when using bracket uncertainty mode. E.g. expressing ``123.4 +/- 2.3`` as ``123.4(23)`` instead of ``123.4(2.3)``. - :param unicode_pm: :class:`bool` indicating if the ``'+/-'`` - separator should be replaced with the unicode plus minus symbol - ``'±'``. :param unc_pm_whitespace: :class:`bool` indicating if there should be whitespace surrounding the ``'+/-'`` symbols when formatting. E.g. ``123.4+/-2.3`` compared to ``123.4 +/- 2.3``. @@ -200,7 +196,6 @@ class FormatOptions: pdg_sig_figs: Optional[bool] = None val_unc_match_widths: Optional[bool] = None bracket_unc_remove_seps: Optional[bool] = None - unicode_pm: Optional[bool] = None unc_pm_whitespace: Optional[bool] = None add_c_prefix: InitVar[bool] = False @@ -348,7 +343,6 @@ def validate_options(options: Union[FormatOptions, RenderedFormatOptions]): pdg_sig_figs=False, val_unc_match_widths=False, bracket_unc_remove_seps=False, - unicode_pm=False, unc_pm_whitespace=True ) diff --git a/src/sciform/formatting.py b/src/sciform/formatting.py index 379f3012..55fca28e 100644 --- a/src/sciform/formatting.py +++ b/src/sciform/formatting.py @@ -285,10 +285,8 @@ def format_val_unc(val: Decimal, unc: Decimal, if not options.bracket_unc: if options.latex: pm_symb = r'\pm' - elif options.unicode_pm: - pm_symb = '±' else: - pm_symb = '+/-' + pm_symb = '±' if options.unc_pm_whitespace: pm_symb = f' {pm_symb} ' diff --git a/tests/test_print.py b/tests/test_print.py index 66324e3a..8b84ee2c 100644 --- a/tests/test_print.py +++ b/tests/test_print.py @@ -34,7 +34,6 @@ def test_print_global_defaults(self): " 'pdg_sig_figs': False,\n" " 'val_unc_match_widths': False,\n" " 'bracket_unc_remove_seps': False,\n" - " 'unicode_pm': False,\n" " 'unc_pm_whitespace': True}\n" ) self.assertEqual(actual_printout, expected_printout) @@ -67,7 +66,6 @@ def test_unrendered_options_repr(self): " 'pdg_sig_figs': False,\n" " 'val_unc_match_widths': False,\n" " 'bracket_unc_remove_seps': False,\n" - " 'unicode_pm': False,\n" " 'unc_pm_whitespace': True}\n" ) self.assertEqual(actual_printout, expected_printout) From 3402fba839ab3938bd379cc67acc428ae76d7c8c Mon Sep 17 00:00:00 2001 From: Justin Date: Sat, 4 Nov 2023 22:13:12 -0600 Subject: [PATCH 3/8] =?UTF-8?q?replace=20+/-=20by=20=C2=B1=20in=20docs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.rst | 8 ++++---- docs/source/examples.rst | 4 ++-- docs/source/options.rst | 36 ++++++++++++++++++------------------ docs/source/usage.rst | 10 ++++------ 4 files changed, 28 insertions(+), 30 deletions(-) diff --git a/README.rst b/README.rst index fd07f4b2..4b3d0232 100644 --- a/README.rst +++ b/README.rst @@ -109,17 +109,17 @@ using the ``SciNumUnc`` object. ... upper_separator=GroupingSeparator.SPACE, ... lower_separator=GroupingSeparator.SPACE)) >>> print(sform(123456.654321, 0.0034)) -123 456.654 3 +/- 0.003 4 +123 456.654 3 ± 0.003 4 >>> sform = Formatter(FormatOptions( ... ndigits=4, ... exp_mode=ExpMode.ENGINEERING)) >>> print(sform(123456.654321, 0.0034)) -(123.456654321 +/- 0.000003400)e+03 +(123.456654321 ± 0.000003400)e+03 >>> from sciform import SciNumUnc >>> num = SciNumUnc(123456.654321, 0.0034) >>> print(f'{num:_!2f}') -123_456.6543 +/- 0.0034 +123_456.6543 ± 0.0034 >>> print(f'{num:_!2f()}') 123_456.6543(34) @@ -130,5 +130,5 @@ Acknowledgements ``sciform`` was heavily motivated by the prefix formatting provided in the `prefixed `_ -package and the value +/- uncertainty formatting in the +package and the value ± uncertainty formatting in the `uncertainties `_ package. diff --git a/docs/source/examples.rst b/docs/source/examples.rst index 7fc92b33..a7e05d47 100644 --- a/docs/source/examples.rst +++ b/docs/source/examples.rst @@ -74,7 +74,7 @@ available formatting options. >>> unc = 1618 >>> sform = Formatter() >>> print(sform(num, unc)) -3141593 +/- 1618 +3141593 ± 1618 >>> sform = Formatter(FormatOptions( ... exp_mode=ExpMode.ENGINEERING, ... exp_format=ExpFormat.PREFIX, @@ -136,7 +136,7 @@ instead. >>> num_unc = SciNumUnc(3141592.7, 1618) >>> print(f'{num_unc}') -3141593 +/- 1618 +3141593 ± 1618 >>> with GlobalDefaultsContext(FormatOptions( ... pdg_sig_figs=True, ... unicode_pm=True, diff --git a/docs/source/options.rst b/docs/source/options.rst index aa262ac0..3ae37951 100644 --- a/docs/source/options.rst +++ b/docs/source/options.rst @@ -40,7 +40,7 @@ directly with no extra exponent. >>> print(sform(123.456)) 123.456 >>> print(sform(123.456, 0.001)) -123.456 +/- 0.001 +123.456 ± 0.001 .. _percent_mode: @@ -55,7 +55,7 @@ appended to the end of the formatted string. >>> print(sform(0.12345)) 12.345% >>> print(sform(0.12345, 0.001)) -(12.3 +/- 0.1)% +(12.3 ± 0.1)% .. _scientific: @@ -70,7 +70,7 @@ mantissa ``m`` satisfies ``1 <= m < 10``. >>> print(sform(123.456)) 1.23456e+02 >>> print(sform(123.456, 0.001)) -(1.23456 +/- 0.00001)e+02 +(1.23456 ± 0.00001)e+02 Note that, for all exponent modes, the exponent integer is always displayed with a sign symbol (+ or -) and is left padded with a zero so @@ -103,7 +103,7 @@ notation. >>> print(sform(123.456)) 123.456e+00 >>> print(sform(123.456, 0.001)) -(123.456 +/- 0.001)e+00 +(123.456 ± 0.001)e+00 .. _engineering_shifted: @@ -118,7 +118,7 @@ the exponent is chosen so that the mantissa ``m`` satisfies >>> print(sform(123.456)) 0.123456e+03 >>> print(sform(123.456, 0.001)) -(0.123456 +/- 0.000001)e+03 +(0.123456 ± 0.000001)e+03 .. _binary: @@ -570,7 +570,7 @@ The latex format makes the following changes: superscript strings like ``'\times 10^{+2}`` * Replace ``'('`` and ``')'`` by latex size-aware delimiters ``'\left('`` and ``'\right)'``. -* Replace ``'+/-'`` by ``'\pm'`` +* Replace ``'±'`` by ``'\pm'`` * Replace ``'_'`` by ``'\_'`` * Replace ``'%'`` by ``'\%'`` * Exponent replacements such as ``'M'``, ``'Ki'``, or ``'ppb'`` and @@ -633,7 +633,7 @@ according to the options below. >>> sform = Formatter() >>> print(sform(123.456, 0.789)) -123.456 +/- 0.789 +123.456 ± 0.789 .. _pdg_sig_figs: @@ -678,11 +678,11 @@ mode with :class:`AutoDigits` precision and the ``pdg_sig_figs`` flag. ... ndigits=AutoDigits, ... pdg_sig_figs=True)) >>> print(sform(1, 0.0123)) -1.000 +/- 0.012 +1.000 ± 0.012 >>> print(sform(1, 0.0483)) -1.00 +/- 0.05 +1.00 ± 0.05 >>> print(sform(1, 0.0997)) -1.00 +/- 0.10 +1.00 ± 0.10 If ``ndigits`` is specified (i.e. not ``None``) but ``ndigits!=AutoDigits`` with ``pdg_sig_figs=True`` then ``ValueError`` is @@ -696,12 +696,12 @@ symbol when formatting value/uncertainties. >>> sform = Formatter() >>> print(sform(123.456, 0.789)) -123.456 +/- 0.789 +123.456 ± 0.789 >>> sform = Formatter(FormatOptions(unc_pm_whitespace=False)) >>> print(sform(123.456, 0.789)) -123.456+/-0.789 +123.456±0.789 -The user can also replace the ``'+/-'`` symbol with a unicode ``'±'`` +The user can also replace the ``'±'`` symbol with a unicode ``'±'`` symbol using the ``unicode_pm`` option. >>> sform = Formatter(FormatOptions(unicode_pm=True)) @@ -713,7 +713,7 @@ symbol using the ``unicode_pm`` option. Bracket Uncertainty ------------------- -Instead of displaying ``123.456 +/- 0.789``, there is a notation where +Instead of displaying ``123.456 ± 0.789``, there is a notation where the uncertainty is shown in brackets after the value as ``123.456(789)``. Here the ``(789)`` in parentheses is meant to be "matched up" with the @@ -762,10 +762,10 @@ Remove Separators for Bracket Uncertainty In some cases using bracket uncertainty results in digits such that the decimal point could appear in the uncertainty in the brackets. -For example: ``18.4 +/- 2.1 -> 18.4(2.1)``. +For example: ``18.4 ± 2.1 -> 18.4(2.1)``. In such cases, there is no official guidance on if the decimal symbol should be included in the bracket symbols or not. -That is, one may format ``18.4 +/- 2.1 -> 18.4(21)``. +That is, one may format ``18.4 ± 2.1 -> 18.4(21)``. The interpretation here is that the uncertainty is 21 tenths, since the least significant digit of the value is in the tenths place. The author's preference is to keep the decimal symbol because it allows @@ -831,10 +831,10 @@ This feature is accessed with the ``val_unc_match_widths`` option. ... top_dig_place=2, ... val_unc_match_widths=False)) >>> print(sform(12345, 1.23)) -12345.00 +/- 001.23 +12345.00 ± 001.23 >>> sform = Formatter(FormatOptions( ... fill_mode=FillMode.ZERO, ... top_dig_place=2, ... val_unc_match_widths=True)) >>> print(sform(12345, 1.23)) -12345.00 +/- 00001.23 +12345.00 ± 00001.23 diff --git a/docs/source/usage.rst b/docs/source/usage.rst index 67985653..8ffb77d4 100644 --- a/docs/source/usage.rst +++ b/docs/source/usage.rst @@ -77,7 +77,7 @@ Value/Uncertainty Formatting One of the most important use cases for scientific formatting is formatting a value together with its specified uncertainty, e.g. -``84.3 +/- 0.2``. +``84.3 ± 0.2``. :mod:`sciform` provides the ability to format pairs of numbers into value/uncertainty strings. :mod:`sciform` attempts to follow @@ -94,11 +94,11 @@ using the :class:`SciNumUnc` object. >>> unc = 0.2 >>> sform = Formatter(FormatOptions(ndigits=2)) >>> print(sform(val, unc)) -84.30 +/- 0.20 +84.30 ± 0.20 >>> from sciform import SciNumUnc >>> val_unc = SciNumUnc(val, unc) >>> print(f'{val_unc:!2}') -84.30 +/- 0.20 +84.30 ± 0.20 Value/uncertainty pairs can also be formatted using a parentheses notation in which the uncertainty is displayed in parentheses following @@ -164,7 +164,6 @@ package default settings): 'pdg_sig_figs': False, 'val_unc_match_widths': False, 'bracket_unc_remove_seps': False, - 'unicode_pm': False, 'unc_pm_whitespace': True} The global default settings can be modified by passing @@ -203,7 +202,6 @@ unchanged. 'pdg_sig_figs': False, 'val_unc_match_widths': False, 'bracket_unc_remove_seps': False, - 'unicode_pm': False, 'unc_pm_whitespace': True} The global default settings can be reset to the :mod:`sciform` defaults @@ -304,7 +302,7 @@ concerned with the exact decimal representation of their numerical data. for its :class:`float`. In this format, a :class:`float` occupies 64 bits of memory: 52 bits for the mantissa, 11 bits for the exponent and 1 bit for the sign. -* Any decimal with 15 digits between about ``+/- 1.8e+308`` can be +* Any decimal with 15 digits between about ``± 1.8e+308`` can be uniquely represented by a :class:`float`. However, two decimals with more than 15 digits may map to the same :class:`float`. From cee8bd51ec2f3306c8956fbc9c61c6a4e4a71a5b Mon Sep 17 00:00:00 2001 From: Justin Date: Sun, 5 Nov 2023 14:24:38 -0700 Subject: [PATCH 4/8] fix doctests --- docs/source/examples.rst | 2 -- docs/source/options.rst | 20 -------------------- src/sciform/formatter.py | 2 +- 3 files changed, 1 insertion(+), 23 deletions(-) diff --git a/docs/source/examples.rst b/docs/source/examples.rst index a7e05d47..c9301d85 100644 --- a/docs/source/examples.rst +++ b/docs/source/examples.rst @@ -79,7 +79,6 @@ available formatting options. ... exp_mode=ExpMode.ENGINEERING, ... exp_format=ExpFormat.PREFIX, ... pdg_sig_figs=True, -... unicode_pm=True, ... unc_pm_whitespace=False)) >>> print(sform(num, unc)) (3.1416±0.0016) M @@ -139,7 +138,6 @@ instead. 3141593 ± 1618 >>> with GlobalDefaultsContext(FormatOptions( ... pdg_sig_figs=True, -... unicode_pm=True, ... unc_pm_whitespace=False)): ... print(f'{num_unc:rp}') (3.1416±0.0016) M diff --git a/docs/source/options.rst b/docs/source/options.rst index 3ae37951..ae9820b5 100644 --- a/docs/source/options.rst +++ b/docs/source/options.rst @@ -688,26 +688,6 @@ If ``ndigits`` is specified (i.e. not ``None``) but ``ndigits!=AutoDigits`` with ``pdg_sig_figs=True`` then ``ValueError`` is raised. -Plus Minus Symbol Formatting ----------------------------- - -The user can enable (default) or disable white space around the plus/minus -symbol when formatting value/uncertainties. - ->>> sform = Formatter() ->>> print(sform(123.456, 0.789)) -123.456 ± 0.789 ->>> sform = Formatter(FormatOptions(unc_pm_whitespace=False)) ->>> print(sform(123.456, 0.789)) -123.456±0.789 - -The user can also replace the ``'±'`` symbol with a unicode ``'±'`` -symbol using the ``unicode_pm`` option. - ->>> sform = Formatter(FormatOptions(unicode_pm=True)) ->>> print(sform(123.456, 0.789)) -123.456 ± 0.789 - .. _bracket_uncertainty: Bracket Uncertainty diff --git a/src/sciform/formatter.py b/src/sciform/formatter.py index afdab527..06ff4847 100644 --- a/src/sciform/formatter.py +++ b/src/sciform/formatter.py @@ -34,7 +34,7 @@ class Formatter: ... round_mode=RoundMode.SIG_FIG, ... ndigits=2)) >>> print(sform(12345.678, 3.4)) - (12.3457 +/- 0.0034)e+03 + (12.3457 ± 0.0034)e+03 :param format_options: :class:`FormatOptions` indicating which format options should be used for formatting. From 258206a7e7a9108180e2dc222211f905091e9771 Mon Sep 17 00:00:00 2001 From: Justin Date: Sun, 5 Nov 2023 22:02:33 -0700 Subject: [PATCH 5/8] remove some references to unicode pm --- docs/source/options.rst | 4 ++-- docs/source/usage.rst | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/source/options.rst b/docs/source/options.rst index ae9820b5..02c7f958 100644 --- a/docs/source/options.rst +++ b/docs/source/options.rst @@ -577,8 +577,8 @@ The latex format makes the following changes: non-finite numbers such as ``'nan'``, ``'NAN'``, ``'inf'``, and ``'INF'`` are wrapped in ``'\text{}'``. -Note that use of ``latex`` renders the use of ``unicode_pm`` and -``superscript_exp`` meaningless. +Note that use of ``latex`` renders the use of the ``superscript_exp`` +meaningless. Include Exponent on nan and inf =============================== diff --git a/docs/source/usage.rst b/docs/source/usage.rst index 8ffb77d4..a708c00c 100644 --- a/docs/source/usage.rst +++ b/docs/source/usage.rst @@ -250,7 +250,7 @@ values. Note that the :ref:`FSML ` does not provide complete control over all possible format options. For example, there is no code in the :ref:`FSML ` for configuring -the ``unicode_pm`` option. +the ``pdg_sig_figs`` option. If the user wishes to configure these options, but also use the :ref:`FSML `, then they must do so by modifying the global default settings. From c4d56e1d36ec67f43650d6cd2d7ab43b8db37b2d Mon Sep 17 00:00:00 2001 From: Justin Date: Sun, 5 Nov 2023 22:09:13 -0700 Subject: [PATCH 6/8] changelog --- CHANGELOG.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 63d63f98..eb9862e8 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -13,6 +13,16 @@ Fixed about the specific `FormatOptions` instance. [`#75 `_] +Removed +^^^^^^^ + +* Removed the ``unicode_pm`` feature which allowed toggling between + using ``'+/-'`` or ``'±'`` in value/uncertainty strings. Previously + ``unicode_pm`` defaulted to ``False`` so that ``'+/-'`` was the + default behavior. Now the default behavior is to use ``'±'`` and there + is no way to change to the old ``'+/-'`` behavior. + [`#10 `_] + ---- 0.29.1 (2023-10-22) From 2e59065e74ec8115611e07560a9bbdb1805117f1 Mon Sep 17 00:00:00 2001 From: Justin Date: Sun, 5 Nov 2023 22:09:51 -0700 Subject: [PATCH 7/8] Fix some changelog formatting --- CHANGELOG.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index eb9862e8..66c67a4a 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -8,9 +8,9 @@ Unreleased Fixed ^^^^^ -* Fixed a bug where the `repr` for `FormatOptions` would return a string - containing information about the global format options rather than - about the specific `FormatOptions` instance. +* Fixed a bug where the ``repr`` for ``FormatOptions`` would return a + string containing information about the global format options rather + than about the specific ``FormatOptions`` instance. [`#75 `_] Removed From 1babd83c0e6e5be30b3b7120a82fade6dd08052e Mon Sep 17 00:00:00 2001 From: Justin Date: Sun, 5 Nov 2023 22:19:14 -0700 Subject: [PATCH 8/8] grammar --- docs/source/options.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/options.rst b/docs/source/options.rst index 02c7f958..1d411656 100644 --- a/docs/source/options.rst +++ b/docs/source/options.rst @@ -578,7 +578,7 @@ The latex format makes the following changes: ``'INF'`` are wrapped in ``'\text{}'``. Note that use of ``latex`` renders the use of the ``superscript_exp`` -meaningless. +option meaningless. Include Exponent on nan and inf ===============================