Skip to content

Commit

Permalink
feat: Use double quote in NQL params.
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrykGala committed Nov 25, 2024
1 parent 7118bd1 commit b3acb3b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/neptune_fetcher/read_only_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ def _fetch_df(
limit=limit,
sort_by=sort_by,
ascending=ascending,
object_type=object_type,
)

# Accumulate list dicts containing attributes. Map short_run_id -> dict(attr_path -> value)
Expand Down Expand Up @@ -725,13 +726,14 @@ def _stream_runs(
limit: Optional[int],
sort_by: str,
ascending: bool,
object_type: Literal["run", "experiment"] = "run",
) -> Generator[_AttributeContainer, None, None]:
sort_type: str = _find_sort_type(backend, project_id, sort_by)

return list_objects_from_project(
backend=backend,
project_id=project_id,
object_type="run",
object_type=object_type,
columns=[],
query=str(query),
limit=limit,
Expand Down
9 changes: 6 additions & 3 deletions src/neptune_fetcher/read_only_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
FieldDefinition,
FieldType,
)
from neptune_fetcher.util import escape_nql_criterion

if TYPE_CHECKING:
from neptune_fetcher.read_only_project import ReadOnlyProject
Expand All @@ -58,21 +59,23 @@ def __init__(

if custom_id is not None:
run = read_only_project.fetch_runs_df(
query=f"`sys/custom_run_id`:string = '{custom_id}'", limit=1, columns=["sys/id"]
query=f'`sys/custom_run_id`:string = "{escape_nql_criterion(custom_id)}"', limit=1, columns=["sys/id"]
)

if len(run) == 0:
raise ValueError(f"No experiment found with custom id '{custom_id}'")
self.with_id = run.iloc[0]["sys/id"]
elif experiment_name is not None:
experiment = read_only_project.fetch_experiments_df(
query=f"`sys/name`:string = '{experiment_name}'", limit=1, columns=["sys/id"]
query=f'`sys/name`:string = "{escape_nql_criterion(experiment_name)}"', limit=1, columns=["sys/id"]
)
if len(experiment) == 0:
raise ValueError(f"No experiment found with name '{experiment_name}'")
self.with_id = experiment.iloc[0]["sys/id"]
else:
run = read_only_project.fetch_runs_df(query=f"`sys/id`:string = '{with_id}'", limit=1, columns=["sys/id"])
run = read_only_project.fetch_runs_df(
query=f'`sys/id`:string = "{escape_nql_criterion(with_id)}"', limit=1, columns=["sys/id"]
)
if len(run) == 0:
raise ValueError(f"No experiment found with Neptune ID '{with_id}'")
self.with_id = with_id
Expand Down
14 changes: 14 additions & 0 deletions tests/e2e/test_run_filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

import pytest

from neptune_fetcher import ReadOnlyRun

#
# Tests for filtering runs by various attributes
#
Expand Down Expand Up @@ -150,6 +152,18 @@ def test__experiments_name_regex_neg_is_empty(project, sys_columns):
project.fetch_experiments_df(columns=sys_columns, names_exclude_regex="")


@pytest.mark.parametrize(
"value",
[r"+\abc" "+\abc", "foobar", r"foo\+bar", r"foo\\+bar"],
)
def test__experiments_name_constructor(project, value):
with pytest.raises(ValueError, match=f"No experiment found with name '{value}'"):
ReadOnlyRun(project, experiment_name=value)

with pytest.raises(ValueError, match=f"No experiment found with Neptune ID '{value}'"):
ReadOnlyRun(project, with_id=value)


@pytest.mark.parametrize(
"tags, expect_ids",
# Note that in test code we limit the number of results by providing a custom_id_regex="-[15]+"
Expand Down

0 comments on commit b3acb3b

Please sign in to comment.