Open byersiiasa opened 2 years ago
Thanks for reporting this issue, @byersiiasa!
Played around for a few minutes, I think there are three issues:
a
and b
as stringsname
-argument for the computed data should be again an integer, but this indeed runs into a bug - it works in my test case, however, if you pass an integer-castable string, i.e., name="2006"
A suggested alternative using the subtract
method and then adding the result to meta
:
df.set_meta(
meta=df.filter(variable="Emissions|CO2").subtract(a=2100, b=2020, name="0", axis="year", append=False)._data,
name="Emissions|CO2 2100-2020",
)
Indeed - at the moment the numerical operations assume explicitly that they will not be applied to the time
axis (e.g., year
). The result of such a calculation would have a time dimensionality of 0, and thus be considered metadata in our current data model.
I think it's an open question as to whether we would want to support this directly in the operation interface (e.g., if axis is year, then add to meta) or have a separate interface that supports that.
The implementation you provide @danielhuppmann I think is great for that, now it's just a question of what we want to support in a 'first class' manner.
For clarification, the numerical operations work fine on the "year" dimension, i.e.
df.subtract(a=1, b=2, name="3", axis="year")
except for the "bug" that the returned index-value on the time domain has to be specified as an integer-castable string instead of an integer.
However, in many cases, this will not really make sense as a "timeseries"-type data. (Usually, diff() might be more useful here.)
So imho, the actual question is: should we explicitly raise an error when doing data operations along the time domain?
I would not overload the data-ops methods with some optionality to add to meta
instead of data
- instead, the method set_meta_from_data would be a better prototype...
I tested the
.subtract()
function passingaxis='year'
but I guess that was my misunderstanding and it is not supposed to work as the result needs to be assigned to a 'year'. e.g.@gidden suggested to add at least an error warning advising that the operation along the 'year' axis is not supported.