Skip to content

Commit

Permalink
Merge pull request #98 from op3/master
Browse files Browse the repository at this point in the history
Use raw strings for relevant strings with backslashes
  • Loading branch information
lebigot authored Jun 22, 2019
2 parents 6d57b70 + be00513 commit 0e0bfd3
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions uncertainties/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1019,13 +1019,13 @@ def from_superscript(number_str):
# parentheses. This has the side effect of making the part between
# the parentheses non-breakable (the text inside parentheses in a
# LaTeX math expression $...$ can be broken).
'latex': ('\left(', r'\right)'),
'latex': (r'\left(', r'\right)'),
'default': ('(', ')') # Basic text mode
}

def format_num(nom_val_main, error_main, common_exp,
fmt_parts, prec, main_pres_type, options):
'''
r'''
Return a formatted number with uncertainty.
Null errors (error_main) are displayed as the integer 0, with
Expand Down Expand Up @@ -1166,10 +1166,10 @@ def format_num(nom_val_main, error_main, common_exp,
elif isnan(error_main):
uncert_str = robust_format(error_main, main_pres_type)
if 'L' in options:
uncert_str = '\mathrm{%s}' % uncert_str
uncert_str = r'\mathrm{%s}' % uncert_str
elif isinf(error_main):
if 'L' in options:
uncert_str = '\infty'
uncert_str = r'\infty'
else:
uncert_str = robust_format(error_main, main_pres_type)
else: # Error with a meaningful first digit (not 0, and real number)
Expand Down Expand Up @@ -1239,13 +1239,13 @@ def format_num(nom_val_main, error_main, common_exp,
if 'L' in options:

if isnan(nom_val_main):
nom_val_str = '\mathrm{%s}' % nom_val_str
nom_val_str = r'\mathrm{%s}' % nom_val_str
elif isinf(nom_val_main):
# !! It is wasteful, in this case, to replace
# nom_val_str: could this be avoided while avoiding to
# duplicate the formula for nom_val_str for the common
# case (robust_format(...))?
nom_val_str = '%s\infty' % ('-' if nom_val_main < 0 else '')
nom_val_str = r'%s\infty' % ('-' if nom_val_main < 0 else '')

value_str = nom_val_str+value_end

Expand Down Expand Up @@ -1364,14 +1364,14 @@ def format_num(nom_val_main, error_main, common_exp,
if 'L' in options:

if isnan(nom_val_main):
nom_val_str = '\mathrm{%s}' % nom_val_str
nom_val_str = r'\mathrm{%s}' % nom_val_str
elif isinf(nom_val_main):
nom_val_str = '%s\infty' % ('-' if nom_val_main < 0 else '')
nom_val_str = r'%s\infty' % ('-' if nom_val_main < 0 else '')

if isnan(error_main):
error_str = '\mathrm{%s}' % error_str
error_str = r'\mathrm{%s}' % error_str
elif isinf(error_main):
error_str = '\infty'
error_str = r'\infty'

if nom_has_exp:
nom_val_str += exp_str
Expand Down Expand Up @@ -1405,7 +1405,7 @@ def format_num(nom_val_main, error_main, common_exp,
# Unicode-compatible LaTeX source can use ±:
pm_symbol = u'±'
elif 'L' in options:
pm_symbol = ' \pm '
pm_symbol = r' \pm '
else:
pm_symbol = '+/-'

Expand Down Expand Up @@ -1954,7 +1954,7 @@ def __format__(self, format_spec):

# Format specification parsing:

match = re.match('''
match = re.match(r'''
(?P<fill>[^{}]??)(?P<align>[<>=^]?) # fill cannot be { or }
(?P<sign>[-+ ]?)
(?P<zero>0?)
Expand Down Expand Up @@ -2923,7 +2923,7 @@ def correlation_matrix(nums_with_uncert):
# Regexp for a number with uncertainty (e.g., "-1.234(2)e-6"), where
# the uncertainty is optional (in which case the uncertainty is
# implicit). The uncertainty can also be nan or NAN:
NUMBER_WITH_UNCERT_RE_STR = u'''
NUMBER_WITH_UNCERT_RE_STR = ur'''
([+-])? # Sign
%s # Main number
(?:\(%s\))? # Optional uncertainty
Expand All @@ -2940,7 +2940,7 @@ def correlation_matrix(nums_with_uncert):
# Number with uncertainty with a factored exponent (e.g., of the form
# (... +/- ...)e10): this is a loose matching, so as to accommodate
# for multiple formats:
NUMBER_WITH_UNCERT_GLOBAL_EXP_RE_MATCH = re.compile(u'''
NUMBER_WITH_UNCERT_GLOBAL_EXP_RE_MATCH = re.compile(ur'''
\(
(?P<simple_num_with_uncert>.*)
\)
Expand Down Expand Up @@ -3012,7 +3012,7 @@ def parse_error_in_parentheses(representation):
return (value, uncert_value)

# Regexp for catching the two variable parts of -1.2×10⁻¹²:
PRETTY_PRINT_MATCH = re.compile(u'(.*?)\s*×\s*10(.*)').match
PRETTY_PRINT_MATCH = re.compile(ur'(.*?)\s*×\s*10(.*)').match

def to_float(value_str):
'''
Expand Down Expand Up @@ -3089,7 +3089,7 @@ def str_to_number_with_uncert(representation):
else:
factor = 1 # No global exponential factor

match = re.match(u'(.*)(?:\+/-|±)(.*)', representation)
match = re.match(ur'(.*)(?:\+/-|±)(.*)', representation)
if match:

(nom_value, uncert) = match.groups()
Expand Down

0 comments on commit 0e0bfd3

Please sign in to comment.