iiasa / ixmp

The ix modeling platform for integrated and cross-cutting scenario analysis
https://docs.messageix.org/ixmp
Apache License 2.0
38 stars 112 forks source link

Minor reporting fixes #396

Closed khaeru closed 3 years ago

khaeru commented 3 years ago

Two small issues spotted while working on MESSAGEix-Transport:

  1. Dask behaviour has changed; see the commit message.
  2. Units handling in computations.ratio() was triggering some odd behaviour in pint:
    File "/home/khaeru/vc/iiasa/ixmp/ixmp/reporting/computations.py", line 344, in ratio
    result.attrs["_unit"] = u_num / u_denom
    File "/home/khaeru/.local/lib/python3.8/site-packages/pint/unit.py", line 198, in __truediv__
    return qself / other
    File "/home/khaeru/.local/lib/python3.8/site-packages/pint/quantity.py", line 1270, in __truediv__
    return self._mul_div(other, operator.truediv)
    File "/home/khaeru/.local/lib/python3.8/site-packages/pint/quantity.py", line 115, in wrapped
    return f(self, *args, **kwargs)
    File "/home/khaeru/.local/lib/python3.8/site-packages/pint/quantity.py", line 95, in wrapped
    result = f(self, *args, **kwargs)
    File "/home/khaeru/.local/lib/python3.8/site-packages/pint/quantity.py", line 1231, in _mul_div
    no_offset_units_other = len(other._get_non_multiplicative_units())
    AttributeError: 'Unit' object has no attribute '_get_non_multiplicative_units'

Despite the effort of collect_units() to ensure units are from the same registry, things like this would happen:

kilometer <class 'pint.unit.build_unit_class.<locals>.Unit'>          
megapassenger <class 'pint.unit.Unit'>    

Note the different classes. The explicit re-instantiation prevents this.

How to review

Note that the CI checks all pass.

PR checklist

codecov[bot] commented 3 years ago

Codecov Report

Merging #396 (05352ef) into master (95a5ca8) will increase coverage by 0.0%. The diff coverage is 100.0%.

@@          Coverage Diff           @@
##           master    #396   +/-   ##
======================================
  Coverage    96.8%   96.9%           
======================================
  Files          46      46           
  Lines        5337    5339    +2     
======================================
+ Hits         5171    5174    +3     
+ Misses        166     165    -1     
Impacted Files Coverage Δ
ixmp/reporting/__init__.py 95.0% <100.0%> (-0.1%) :arrow_down:
ixmp/reporting/computations.py 98.8% <100.0%> (+<0.1%) :arrow_up:
ixmp/reporting/utils.py 97.3% <100.0%> (+1.4%) :arrow_up: