Skip to content

Commit

Permalink
Merge pull request #107 from neptune-ai/kg/move-dict-api-to-legacy-pa…
Browse files Browse the repository at this point in the history
…ckage

Add `neptune_scale.legacy.Run`
  • Loading branch information
kgodlewski authored Dec 19, 2024
2 parents 19439a3 + facc0cd commit 6f201da
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
11 changes: 1 addition & 10 deletions src/neptune_scale/api/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@
from neptune_api.proto.neptune_pb.ingest.v1.common_pb2 import Run as CreateRun
from neptune_api.proto.neptune_pb.ingest.v1.pub.ingest_pb2 import RunOperation

from neptune_scale.api.attribute import (
Attribute,
AttributeStore,
)
from neptune_scale.api.attribute import AttributeStore
from neptune_scale.api.validation import (
verify_dict_type,
verify_max_length,
Expand Down Expand Up @@ -390,12 +387,6 @@ def _create_run(
)
self._operations_queue.enqueue(operation=operation)

def __getitem__(self, key: str) -> Attribute:
return self._attr_store[key]

def __setitem__(self, key: str, value: Any) -> None:
self._attr_store[key] = value

def log_metrics(
self,
data: dict[str, Union[float, int]],
Expand Down
28 changes: 28 additions & 0 deletions src/neptune_scale/legacy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from typing import Any

import neptune_scale.api.run
from neptune_scale.api.attribute import Attribute

__all__ = ("Run",)


class Run(neptune_scale.api.run.Run):
"""This class extends the main Run class with a dict-like API compatible (on a basic level)
with the legacy neptune-client package.
Example:
from neptune_scale.legacy import Run
run = Run(...)
run['foo'] = 1
run['metrics/loss'].append(0.5, step=10)
run.close()
"""

def __getitem__(self, key: str) -> Attribute:
return self._attr_store[key]

def __setitem__(self, key: str, value: Any) -> None:
self._attr_store[key] = value
2 changes: 1 addition & 1 deletion tests/unit/test_attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
mark,
)

from neptune_scale import Run
from neptune_scale.api.attribute import cleanup_path
from neptune_scale.legacy import Run


@fixture
Expand Down

0 comments on commit 6f201da

Please sign in to comment.