Closed lewisjared closed 1 year ago
Patch coverage: 100.00
% and project coverage change: +0.01
:tada:
Comparison is base (
5e94e98
) 95.82% compared to head (8f62f5f
) 95.84%.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.
Check out this pull request on
See visual diffs & provide feedback on Jupyter Notebooks.
Powered by ReviewNB
And to add a bit more context for prosperity reasons. The previous behaviour of interpolate
was to convert integers to UNIX time (seconds since 1970ish). The more consistent behaviour would be to use integers as years and floats as decimal years.
Whether this is called a bug or a breaking change is up for debate, but the behaviour as it was previously implemented (ints mapping to UNIX time) was likely not used in favour of a call that looked like run.interpolate([datetime.date(y, 1, 1) for y in years])
. This can now be replaced with the much clearer run.interpolate(years)
.
The more consistent behaviour would be to use integers as years and floats as decimal years
I don't fully follow. More consistent with what? Use integers as years for what?
We commonly use integers to represent years when creating new ScmRun objects and for filtering.
E.g. the ScmRun constructor uses integer values to represent years (specifically Jan 1 of the year) and relies upon the same datetime conversion functionality now used by interpolate (scmdata.time._format_datetime
).
r = ScmRun(
[1.0, 2.0, 3.0, np.nan],
columns={
"scenario": ["a_scenario"],
"model": ["a_model"],
"region": ["World"],
"variable": ["Emissions|BC"],
"unit": ["Mg /yr"],
},
index=[2000, 2100, 2200, 2300],
)
assert r["year"].to_list() == [2000, 2100, 2200, 2300]
Nowhere else in the library are unix times used, which is why the behaviour is unexpected.
Nowhere else in the library are unix times used, which is why the behaviour is unexpected.
Yep got it thanks
@znicholls Any other feedback or are you ok with this being merged?
Assumes that each year is of equal length which can be useful in some circumstances.
This also fixes the bug where interpolate converts integer values into unix time. This functionality isn't consistent with the behaviour of the TimePoints class where integers are converted into years.
Pull request
Please confirm that this pull request has done the following:
CHANGELOG.rst
addedAdding to CHANGELOG.rst
Please add a single line in the changelog notes similar to one of the following: