scipp.compat.pandas_compat.parse_bracket_header#
- scipp.compat.pandas_compat.parse_bracket_header(head)#
Parses strings of the form
name [unit]
.name
may be any string that does not contain the character[
. Andunit
must be a valid unit string to be parsed bysc.Unit(unit)
. Whitespace between the name and unit is removed.Both name and unit, including brackets, are optional. If the unit is missing but empty brackets are present,
sc.units.default_unit
is returned. If the brackets are absent as well, the returned unit isNone
. This ensures that columns without unit information are not accidentally assigneddimensionless
which can silence downstream errors.If the name is missing, an empty string is returned.
If the input does not conform to the expected pattern, it is returned in full and the unit is returned as
None
. This happens, e.g., when there are multiple opening brackets ([
).If the string between brackets does not represent a valid unit, the full input is returned as the name and the unit is returned as
None
.