diff --git a/mpcontribs-client/mpcontribs/client/__init__.py b/mpcontribs-client/mpcontribs/client/__init__.py index 772b0f578..613698100 100644 --- a/mpcontribs-client/mpcontribs/client/__init__.py +++ b/mpcontribs-client/mpcontribs/client/__init__.py @@ -1517,15 +1517,25 @@ def init_columns(self, columns: dict = None) -> dict: new_unit = new_column.get("unit", "NaN") existing_unit = existing_column.get("unit") if existing_unit != new_unit: + conv_args = [] + for u in [existing_unit, new_unit]: + try: + conv_args.append(ureg.Unit(u)) + except ValueError as ex: + raise MPContribsClientError( + f"Can't convert {existing_unit} to {new_unit} for {path}" + ) try: - factor = ureg.convert(1, ureg.Unit(existing_unit), ureg.Unit(new_unit)) + factor = ureg.convert(1, *conv_args) except DimensionalityError: raise MPContribsClientError( f"Can't convert {existing_unit} to {new_unit} for {path}" ) if not isclose(factor, 1): - logger.info(f"Changing {existing_unit} to {new_unit} for {path} ...") + logger.info( + f"Changing {existing_unit} to {new_unit} for {path} ..." + ) # TODO scale contributions to new unit raise MPContribsClientError( "Changing units not supported yet. Please resubmit"