Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fetch_runs_table method for state param usage #1253

Merged
merged 12 commits into from
Feb 22, 2023
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
- Added exception for unsupported types ([#1229](https://github.com/neptune-ai/neptune-client/pull/1229))
- Change run status to Active / Inactive ([#1233](https://github.com/neptune-ai/neptune-client/pull/1233))
- Package renamed from `neptune-client` to `neptune` ([#1225](https://github.com/neptune-ai/neptune-client/pull/1225))
- Changed return values for run state ([#1253](https://github.com/neptune-ai/neptune-client/pull/1253))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's change it to something about changing values for filtering runs table with the state. + Let's update the old one (Line 22) to something about returned values from the runs table state value.


## neptune-client 0.16.18

Expand Down
13 changes: 13 additions & 0 deletions src/neptune/internal/utils/run_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ class RunState(enum.Enum):
_api_active = "running"
_api_inactive = "idle"

@classmethod
def from_string(cls, value: str) -> "RunState":
try:
return cls(value.capitalize())
except ValueError as e:
raise NeptuneException(f"Can't map RunState to API: {value}") from e

@staticmethod
def from_api(value: str) -> "RunState":
if value == RunState._api_active.value:
Expand All @@ -35,3 +42,9 @@ def from_api(value: str) -> "RunState":
return RunState.inactive
else:
raise NeptuneException(f"Unknown RunState: {value}")

def to_api(self) -> str:
if self is RunState.active:
return self._api_active.value
if self is RunState.inactive:
return self._api_inactive.value
4 changes: 2 additions & 2 deletions src/neptune/metadata_containers/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
from neptune.internal.operation_processors.operation_processor import OperationProcessor
from neptune.internal.state import ContainerState
from neptune.internal.utils import as_list
from neptune.internal.utils.run_state import RunState
from neptune.metadata_containers import MetadataContainer
from neptune.metadata_containers.metadata_containers_table import Table
from neptune.types.mode import Mode
Expand Down Expand Up @@ -131,7 +132,7 @@ def _prepare_nql_query(ids, states, owners, tags):
name="sys/state",
type=NQLAttributeType.EXPERIMENT_STATE,
operator=NQLAttributeOperator.EQUALS,
value=state,
value=RunState.from_string(state).to_api(),
)
for state in states
],
Expand Down Expand Up @@ -261,7 +262,6 @@ def fetch_runs_table(
tags = as_list("tag", tag)

nql_query = self._prepare_nql_query(ids, states, owners, tags)

return MetadataContainer._fetch_entries(
self,
child_type=ContainerType.RUN,
Expand Down
9 changes: 9 additions & 0 deletions tests/unit/neptune/new/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import pytest

from neptune import init_project
from neptune.metadata_containers import Project


@pytest.fixture(scope="session")
def project() -> Project:
return init_project(mode="read-only")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for this. debug + mock backend

17 changes: 17 additions & 0 deletions tests/unit/neptune/new/test_fetch_runs_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import pytest

from neptune.exceptions import NeptuneException


@pytest.mark.parametrize("state", ["active", "inactive", "Active", "Inactive", "aCTive", "INacTiVe"])
def test_fetch_runs_table_is_case_insensitive(state, project):
try:
project.fetch_runs_table(state=state)
assert True
except Exception as e:
assert False, e


def test_fetch_runs_table_raises_correct_exception_if_state_incorrect(project):
with pytest.raises(NeptuneException):
project.fetch_runs_table(state="some_incorrect_state")