Expose Run.is_default in facade#153
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #153 +/- ##
=====================================
Coverage 88.9% 88.9%
=====================================
Files 236 236
Lines 8656 8661 +5
=====================================
+ Hits 7698 7703 +5
Misses 958 958
🚀 New features to boost your workflow:
|
c0d84c8 to
ed0a184
Compare
78a5825 to
71c0e69
Compare
|
It's probably best to make this a |
| def meta(self, meta: dict[str, PrimitiveTypes | np.generic | None]) -> None: | ||
| self._meta._set(meta) | ||
|
|
||
| def is_default(self) -> bool: |
There was a problem hiding this comment.
| def is_default(self) -> bool: | |
| @property | |
| def is_default(self) -> bool: |
There was a problem hiding this comment.
Sure, we can do that :)
Would we want this to be a read-only property or should this get a setter and deleter (that would then presumably call Run.set_as_default() and Run.unset_as_default())?
There was a problem hiding this comment.
I've not written setter and deleter for now since they are not required for the message_ix tutorials. If we want them at a later point, I propose a follow-up issue/PR.
We would likely want something of this sort:
@is_default.setter
def is_default(self, value: bool) -> None:
if value:
self.set_as_default()
else:
self.unset_as_default()If it bothers us that mypy deems one test case as unreachable, we might want to set up an attribute _is_default and use is_default.setter to set that directly. Though even if is_default.getter simply returns the state of _is_default, mypy might not recognize this properly because it's hidden behind this extra layer.
There was a problem hiding this comment.
Yeah, I agree lets leave that for another time...
There was a problem hiding this comment.
Maybe @danielhuppmann can clarify whether we actually want that :)
There was a problem hiding this comment.
I think doing is_default as a property is a good idea, but I would stick with the more "functional" set_as_default() to change the status, to avoid confusion or making changes by accident.
3cc17d2 to
8fe4cac
Compare
71c0e69 to
64b32ca
Compare
Working on iiasa/ixmp#552, I realized that
ixmp4.core.Runshould expose itsis_defaultvalue, which is already present inrun._model.This PR exposes the value by using a function (and tests that calling
set_as_default()andunset_as_default()updateis_default()). It could also be a property, though it's more dynamic than e.g.Run.idorRun.model, that's why I opted for a function: to indicate that this value needs to be retrieved when it's requested.