IAMconsortium / pyam

Analysis & visualization of energy & climate scenarios
https://pyam-iamc.readthedocs.io/
Apache License 2.0
227 stars 119 forks source link

Bugfix for incorrect dimension-accessors when initializing from pandas #763

Closed danielhuppmann closed 1 year ago

danielhuppmann commented 1 year ago

Please confirm that this PR has done the following:

Description of PR

This PR introduces an explicit removal of unused levels when initializing from a pandas object. This bug could lead to inconsistent return-values of the dimension-accessors.

closes #762

codecov[bot] commented 1 year ago

Codecov Report

Merging #763 (98f59f0) into main (4bfcec0) will increase coverage by 0.0%. The diff coverage is 100.0%.

@@          Coverage Diff          @@
##            main    #763   +/-   ##
=====================================
  Coverage   94.4%   94.4%           
=====================================
  Files         59      59           
  Lines       6080    6086    +6     
=====================================
+ Hits        5744    5750    +6     
  Misses       336     336           
Files Changed Coverage Δ
pyam/utils.py 92.7% <100.0%> (+<0.1%) :arrow_up:
tests/test_core.py 100.0% <100.0%> (ø)
coroa commented 1 year ago

ok, thanks, indeed, that is the issue i encountered today.

i would have suggested to replace calls to get_index_levels method with its pandas version, ie something like:

def get_index_levels(index, level):
     return index.unique(level)

so they can decide what is the most efficient solution, but your fix is also fine.