Skip to content

KeyError using binary scales when binary=True #34

@Gustra

Description

@Gustra

I'm getting KeyError '' when trying to scale using a binary quantity:

>>> from quantiphy import Quantity
>>> i=Quantity(100.0, binary=True)
>>> print(i.binary(scale='Mi'))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<redacted>/venv/lib/python3.11/site-packages/quantiphy/quantiphy.py", line 2382, in binary
    number, units = _scale(scale, self)
                    ^^^^^^^^^^^^^^^^^^^
  File "<redacted>/venv/lib/python3.11/site-packages/quantiphy/quantiphy.py", line 74, in _scale
    scaled = UnitConversion._convert_units(scale, unscaled.units, unscaled)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<redacted>/venv/lib/python3.11/site-packages/quantiphy/quantiphy.py", line 3614, in _convert_units
    to_units, from_units, to_sf, from_sf = get_converter(to_units, from_units)
                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<redacted>/venv/lib/python3.11/site-packages/quantiphy/quantiphy.py", line 3610, in get_converter
    return to_units, from_units, get_sf(to_sf), get_sf(from_sf)
                                                ^^^^^^^^^^^^^^^
  File "<redacted>/venv/lib/python3.11/site-packages/quantiphy/quantiphy.py", line 3607, in get_sf
    return float('1' + MAPPINGS[sf])
                       ~~~~~~~~^^^^
KeyError: ''

"i.render(scale='Mi')" produces the same error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions