Skip to content

Error in XLRD reader when reading temperature #101

Open

Description

@anomam

https://github.com/SunPower/Carousel/blob/master/carousel/core/data_readers.py#L306

It looks like 1 * UREG['degC'] leads to an error:

OffsetUnitCalculusError: Ambiguous operation with offset unit (degC).

But 1 * UREG.degC works... So strange

Activity

  1. self-assigned this
    on Mar 24, 2017
  2. mikofski commented on Mar 24, 2017

    @mikofski
    Member

    @anomam thanks for this. Pint handles temperature slightly differently than other units because it can also have an offset in addition to a conversion factor. Please read their documentation. I've been burned by it before too, but basically you can't just multiply by a unit, you have to use the Q_(blah, blah

    However, multiplication, division and exponentiation of quantities with offset units is problematic just like addition. Pint (since version 0.6) will by default raise an error when a quantity with offset unit is used in these operations. Due to this quantities with offset units cannot be created like other quantities by multiplication of magnitude and unit but have to be explicitly created:

    >>> ureg = UnitRegistry()
    >>> home = 25.4 * ureg.degC
    Traceback (most recent call last):
        ...
    pint.errors.OffsetUnitCalculusError: Ambiguous operation with offset unit (degC).
    >>> Q_(25.4, ureg.degC)
    <Quantity(25.4, 'degC')>

    It should be stated more clearly in the documentation, and any data readers or other classes that use units or convert them should be changed to use Q_(value, units) instead of value * units. Sorry!

    Note that this issue was addressed in data_readers.py in ccb6349. Originally PVSimLife used Quantities instead of Pint, and Quantities does not allow unit offsets, so it doesn't do Celsius or Fahrenheit, so it didn't have non-multiplicative units and this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions