IAMconsortium / pyam

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

Renaming empty IamDataFrame returns IndexError #631

Closed danielhuppmann closed 2 years ago

danielhuppmann commented 2 years ago

Calling the rename() method on an empty IamDataFrame returns

IndexError: index 0 is out of bounds for axis 0 with size 0

where one could reasonably expect to see an IamDataFrame without raising an error.

Bug reported by @HauHe @Renato-Rodrigues

phackstock commented 2 years ago

I was looking at addressing iamconsortium/nomenclature#116 when this error popped up. @danielhuppmann what should in your opinion be the desired behavior? Should I just return the empty data frame (in case inplace is true? If so should I log any warning or something along those lines or should I just silently return the empty data frame.

phackstock commented 2 years ago

If the desired behavior is the one described above, I would implement the fix in IamDataFrame.rename() by adding a check using IamDataFrame.empty as the first thing in the function. If true I would return either the dataframe or none, depending on whether or not inplace is true.