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 [. And unit must be a valid unit string to be parsed by sc.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 is None. This ensures that columns without unit information are not accidentally assigned dimensionless 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.

Parameters:

head (str) – The string to parse.

Returns:

Tuple[str, Optional[Unit]] – The parsed name and unit.