Skip to content

Commit

Permalink
Open _get_rank(scenario_config_id) API in DataNode class
Browse files Browse the repository at this point in the history
  • Loading branch information
jrobinAV committed Nov 27, 2024
1 parent a6317fe commit 3ba5c9c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
35 changes: 19 additions & 16 deletions taipy/core/data/data_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,6 @@ def __init__(
self._edits: List[Edit] = edits or []

self._properties: _Properties = _Properties(self, **kwargs)
dn_cfg = Config.data_nodes.get(self._config_id, None)
self._ranks: Dict[str, int] = dn_cfg._ranks if dn_cfg else {}

def __eq__(self, other) -> bool:
"""Check if two data nodes are equal."""
Expand Down Expand Up @@ -572,23 +570,28 @@ def get_last_edit(self) -> Optional[Edit]:
"""
return self._edits[-1] if self._edits else None

def get_rank(self) -> int:
"""Get the rank of this data node regarding to its scenario owner
def _get_rank(self, scenario_config_id: str) -> int:
"""Get the data node rank for given scenario config.
The rank corresponds to the order of appearance of the data nodes in a scenario config DAG.
Arguments:
scenario_config_id (str): The identifier of the scenario config used to
get the data node rank.
Returns:
The int value representing the rank.
The int value representing the rank of the data node config in the scenario config DAG.
If the data node config is not found or has no rank, 0xffff is returned. These cases should never happen.
If the data node config is not part of the scenario config, 0xfffe is returned as an infinite rank.
"""
if not self.owner_id:
return 0xfffe
config = Config.data_nodes.get(self.config_id, None)
if not config:
return 0xfffd

from ... import core as tp
owner = tp.get(self.owner_id)
if not isinstance(owner, tp.Scenario):
return 0xfffc
return config._ranks.get(owner.config_id, 0xfffb)
dn_config = Config.data_nodes.get(self._config_id, None)
if not dn_config:
self._logger.error(f"Data node config `{self.config_id}` for data node `{self.id}` is not found.")
return 0xffff
if not dn_config._ranks:
self._logger.error(f"Data node config `{self.config_id}` for data node `{self.id}` has no rank.")
return 0xffff
return dn_config._ranks.get(scenario_config_id, 0xfffe)

@abstractmethod
def _read(self):
Expand Down
2 changes: 1 addition & 1 deletion taipy/gui_core/_adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ class _GuiCoreDatanodeProperties(_GuiCoreProperties):
_GuiCorePropDesc(DataNodeFilter("Last edit date", datetime, "last_edit_date"), for_sort=True),
_GuiCorePropDesc(DataNodeFilter("Expiration date", datetime, "expiration_date"), extended=True, for_sort=True),
_GuiCorePropDesc(DataNodeFilter("Expired", bool, "is_expired"), extended=True),
_GuiCorePropDesc(DataNodeFilter("Rank", int, "get_rank()"), for_sort=True),
_GuiCorePropDesc(DataNodeFilter("Rank", int, "_get_rank()"), for_sort=True),
]
__DN_VALIDITY = None

Expand Down
9 changes: 3 additions & 6 deletions tests/core/data/test_data_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ def test_create_with_default_values(self):
assert dn.job_ids == []
assert not dn.is_ready_for_reading
assert len(dn.properties) == 0
assert len(dn._ranks) == 0

def test_create_with_ranks(self):
# Test _rank is propagated from the config
Expand All @@ -92,10 +91,9 @@ def test_create_with_ranks(self):
assert dn.job_ids == []
assert not dn.is_ready_for_reading
assert len(dn.properties) == 0
assert len(dn._ranks) == 3
assert dn._ranks["A"] == 1
assert dn._ranks["B"] == 2
assert dn._ranks["C"] == 0
assert dn._get_rank("A") == 1
assert dn._get_rank("B") == 2
assert dn._get_rank("C") == 0

def test_is_up_to_date_when_not_written(self):
dn_confg_1 = Config.configure_in_memory_data_node("dn_1", default_data="a")
Expand Down Expand Up @@ -137,7 +135,6 @@ def test_create(self):
assert dn.is_ready_for_reading
assert len(dn.properties) == 2
assert dn.properties == {"prop": "erty", "name": "a name"}
assert len(dn._ranks) == 0

with pytest.raises(InvalidConfigurationId):
DataNode("foo bar")
Expand Down

0 comments on commit 3ba5c9c

Please sign in to comment.