Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/evo-objects/src/evo/objects/typed/_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ async def from_dataframe(self, df: pd.DataFrame, fb: IFeedback = NoFeedback) ->
:param df: DataFrame containing the new values for this table.
:param fb: Optional feedback object to report upload progress.
"""
self._document.update(await self._data_to_schema(df, self._context, fb=fb))
self._document.update(await self._data_to_schema(df, self._obj, fb=fb))

# Mark the context as modified so loading data is not allowed
self._context.mark_modified(self._data)
Expand Down
2 changes: 1 addition & 1 deletion packages/evo-objects/src/evo/objects/typed/_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def _set_property_value(schema_property: BaseSchemaProperty, document: dict[str,
class SchemaBuilder:
"""Helper class to build a schema document by applying SchemaProperty values."""

def __init__(self, schema_model_cls: type[SchemaModel], context: ModelContext) -> None:
def __init__(self, schema_model_cls: type[SchemaModel], context: IContext) -> None:
self.document: dict[str, Any] = {}
self._properties = schema_model_cls._schema_properties
self._sub_models = schema_model_cls._sub_models
Expand Down
2 changes: 1 addition & 1 deletion packages/evo-objects/src/evo/objects/typed/pointset.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ async def coordinates(self, fb: IFeedback = NoFeedback) -> pd.DataFrame:
:param fb: Optional feedback object to report download progress.
:return: A DataFrame with 'x', 'y', 'z' columns representing point coordinates.
"""
return await self.locations._table.get_dataframe(fb=fb)
return await self.locations._table.to_dataframe(fb=fb)

async def to_dataframe(self, *keys: str, fb: IFeedback = NoFeedback) -> pd.DataFrame:
"""Get the full dataframe for the pointset, including coordinates and attributes.
Expand Down
17 changes: 17 additions & 0 deletions packages/evo-objects/tests/typed/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import copy
import uuid
from collections.abc import Callable
from unittest.mock import Mock

import pandas as pd
Expand Down Expand Up @@ -136,3 +137,19 @@ async def from_reference(self, context: IContext, reference: ObjectReference):
assert reference.object_id is not None, "Reference must have an object ID"
object_dict = copy.deepcopy(self.objects[str(reference.object_id)])
return MockDownloadedObject(self, object_dict)


def mock_data_client(mock_client: MockClient) -> Callable[[IContext], MockClient]:
"""Build a `get_data_client` stand-in for patching.

The accessors are called so that a caller passing something that is not an `IContext` fails here, exactly as it
would against the real `get_data_client`.
"""

def get_data_client(context: IContext) -> MockClient:
context.get_connector()
context.get_environment()
context.get_cache()
return mock_client

return get_data_client
10 changes: 5 additions & 5 deletions packages/evo-objects/tests/typed/test_base_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from evo.objects.typed.base import _BaseObject
from evo.objects.typed.types import Point3, Size3d, Size3i

from .helpers import MockClient
from .helpers import MockClient, mock_data_client


class TestRefreshMethodExists(TestCase):
Expand Down Expand Up @@ -60,8 +60,8 @@ def setUp(self) -> None:
def _mock_geoscience_objects(self):
mock_client = MockClient(self.environment)
with (
patch("evo.objects.typed.attributes.get_data_client", lambda _: mock_client),
patch("evo.objects.typed._data.get_data_client", lambda _: mock_client),
patch("evo.objects.typed.attributes.get_data_client", mock_data_client(mock_client)),
patch("evo.objects.typed._data.get_data_client", mock_data_client(mock_client)),
patch("evo.objects.typed.base.create_geoscience_object", mock_client.create_geoscience_object),
patch("evo.objects.typed.base.replace_geoscience_object", mock_client.replace_geoscience_object),
patch("evo.objects.DownloadedObject.from_context", mock_client.from_reference),
Expand Down Expand Up @@ -143,8 +143,8 @@ def setUp(self) -> None:
def _mock_geoscience_objects(self):
mock_client = MockClient(self.environment)
with (
patch("evo.objects.typed.attributes.get_data_client", lambda _: mock_client),
patch("evo.objects.typed._data.get_data_client", lambda _: mock_client),
patch("evo.objects.typed.attributes.get_data_client", mock_data_client(mock_client)),
patch("evo.objects.typed._data.get_data_client", mock_data_client(mock_client)),
patch("evo.objects.typed.base.create_geoscience_object", mock_client.create_geoscience_object),
patch("evo.objects.typed.base.replace_geoscience_object", mock_client.replace_geoscience_object),
patch("evo.objects.DownloadedObject.from_context", mock_client.from_reference),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
)
from evo.objects.typed.exceptions import ObjectValidationError

from .helpers import MockClient
from .helpers import MockClient, mock_data_client


def _make_example_data(
Expand Down Expand Up @@ -125,9 +125,9 @@ def setUp(self) -> None:
def _mock_geoscience_objects(self):
mock_client = MockClient(self.environment)
with (
patch("evo.objects.typed.attributes.get_data_client", lambda _: mock_client),
patch("evo.objects.typed._data.get_data_client", lambda _: mock_client),
patch("evo.objects.typed._utils.get_data_client", lambda _: mock_client),
patch("evo.objects.typed.attributes.get_data_client", mock_data_client(mock_client)),
patch("evo.objects.typed._data.get_data_client", mock_data_client(mock_client)),
patch("evo.objects.typed._utils.get_data_client", mock_data_client(mock_client)),
patch("evo.objects.typed.base.create_geoscience_object", mock_client.create_geoscience_object),
patch("evo.objects.typed.base.replace_geoscience_object", mock_client.replace_geoscience_object),
patch("evo.objects.DownloadedObject.from_context", mock_client.from_reference),
Expand Down
6 changes: 3 additions & 3 deletions packages/evo-objects/tests/typed/test_downhole_intervals.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from evo.objects.typed.base import BaseObject
from evo.objects.typed.exceptions import ObjectValidationError

from .helpers import MockClient
from .helpers import MockClient, mock_data_client

_N = 4 # number of test intervals

Expand Down Expand Up @@ -66,8 +66,8 @@ def setUp(self) -> None:
def _mock_geoscience_objects(self):
mock_client = MockClient(self.environment)
with (
patch("evo.objects.typed.attributes.get_data_client", lambda _: mock_client),
patch("evo.objects.typed._data.get_data_client", lambda _: mock_client),
patch("evo.objects.typed.attributes.get_data_client", mock_data_client(mock_client)),
patch("evo.objects.typed._data.get_data_client", mock_data_client(mock_client)),
patch("evo.objects.typed.base.create_geoscience_object", mock_client.create_geoscience_object),
patch("evo.objects.typed.base.replace_geoscience_object", mock_client.replace_geoscience_object),
patch("evo.objects.DownloadedObject.from_context", mock_client.from_reference),
Expand Down
6 changes: 3 additions & 3 deletions packages/evo-objects/tests/typed/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from evo.objects.typed._model import SchemaBuilder, SchemaLocation, SchemaModel
from evo.objects.utils.table_formats import FLOAT_ARRAY_3, KnownTableFormat

from .helpers import MockClient
from .helpers import MockClient, mock_data_client


class TestSchemaConstants(TestWithConnector):
Expand Down Expand Up @@ -85,8 +85,8 @@ def setUp(self) -> None:
def _mock_geoscience_objects(self):
mock_client = MockClient(self.environment)
with (
patch("evo.objects.typed.attributes.get_data_client", lambda _: mock_client),
patch("evo.objects.typed._data.get_data_client", lambda _: mock_client),
patch("evo.objects.typed.attributes.get_data_client", mock_data_client(mock_client)),
patch("evo.objects.typed._data.get_data_client", mock_data_client(mock_client)),
):
yield mock_client

Expand Down
16 changes: 13 additions & 3 deletions packages/evo-objects/tests/typed/test_pointset.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from evo.objects.typed.base import BaseObject
from evo.objects.typed.exceptions import ObjectValidationError

from .helpers import MockClient
from .helpers import MockClient, mock_data_client


class TestPointSet(TestWithConnector):
Expand All @@ -41,8 +41,8 @@ def setUp(self) -> None:
def _mock_geoscience_objects(self):
mock_client = MockClient(self.environment)
with (
patch("evo.objects.typed.attributes.get_data_client", lambda _: mock_client),
patch("evo.objects.typed._data.get_data_client", lambda _: mock_client),
patch("evo.objects.typed.attributes.get_data_client", mock_data_client(mock_client)),
patch("evo.objects.typed._data.get_data_client", mock_data_client(mock_client)),
patch("evo.objects.typed.base.create_geoscience_object", mock_client.create_geoscience_object),
patch("evo.objects.typed.base.replace_geoscience_object", mock_client.replace_geoscience_object),
patch("evo.objects.DownloadedObject.from_context", mock_client.from_reference),
Expand Down Expand Up @@ -143,6 +143,16 @@ async def test_from_reference(self, class_to_call):
actual_df = await result.locations.to_dataframe()
pd.testing.assert_frame_equal(actual_df, self.example_pointset.locations)

async def test_coordinates(self):
"""Test that coordinates() returns only the x, y, z columns."""
with self._mock_geoscience_objects():
obj = await PointSet.create(context=self.context, data=self.example_pointset)

actual_df = await obj.coordinates()

expected_df = self.example_pointset.locations[["x", "y", "z"]]
pd.testing.assert_frame_equal(actual_df, expected_df)

def test_bounding_box_from_data(self):
"""Test that the bounding box is computed correctly from the data."""
bbox = self.example_pointset.compute_bounding_box()
Expand Down
4 changes: 2 additions & 2 deletions packages/evo-objects/tests/typed/test_regular_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from evo.objects.typed.base import BaseObject
from evo.objects.typed.exceptions import ObjectValidationError

from .helpers import MockClient
from .helpers import MockClient, mock_data_client


class TestRegularGrid(TestWithConnector):
Expand All @@ -44,7 +44,7 @@ def setUp(self) -> None:
def _mock_geoscience_objects(self):
mock_client = MockClient(self.environment)
with (
patch("evo.objects.typed.attributes.get_data_client", lambda _: mock_client),
patch("evo.objects.typed.attributes.get_data_client", mock_data_client(mock_client)),
patch("evo.objects.typed.base.create_geoscience_object", mock_client.create_geoscience_object),
patch("evo.objects.typed.base.replace_geoscience_object", mock_client.replace_geoscience_object),
patch("evo.objects.DownloadedObject.from_context", mock_client.from_reference),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from evo.objects.typed.exceptions import ObjectValidationError
from evo.objects.typed.regular_masked_grid import RegularMasked3DGrid, RegularMasked3DGridData

from .helpers import MockClient
from .helpers import MockClient, mock_data_client


class TestRegularMaskedGrid(TestWithConnector):
Expand All @@ -42,8 +42,8 @@ def setUp(self) -> None:
def _mock_geoscience_objects(self):
mock_client = MockClient(self.environment)
with (
patch("evo.objects.typed.attributes.get_data_client", lambda _: mock_client),
patch("evo.objects.typed.regular_masked_grid.get_data_client", lambda _: mock_client),
patch("evo.objects.typed.attributes.get_data_client", mock_data_client(mock_client)),
patch("evo.objects.typed.regular_masked_grid.get_data_client", mock_data_client(mock_client)),
patch("evo.objects.typed.base.create_geoscience_object", mock_client.create_geoscience_object),
patch("evo.objects.typed.base.replace_geoscience_object", mock_client.replace_geoscience_object),
patch("evo.objects.DownloadedObject.from_context", mock_client.from_reference),
Expand Down
4 changes: 2 additions & 2 deletions packages/evo-objects/tests/typed/test_tensor_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from evo.objects.typed.exceptions import ObjectValidationError
from evo.objects.typed.tensor_grid import Tensor3DGrid, Tensor3DGridData

from .helpers import MockClient
from .helpers import MockClient, mock_data_client


class TestTensorGrid(TestWithConnector):
Expand All @@ -42,7 +42,7 @@ def setUp(self) -> None:
def _mock_geoscience_objects(self):
mock_client = MockClient(self.environment)
with (
patch("evo.objects.typed.attributes.get_data_client", lambda _: mock_client),
patch("evo.objects.typed.attributes.get_data_client", mock_data_client(mock_client)),
patch("evo.objects.typed.base.create_geoscience_object", mock_client.create_geoscience_object),
patch("evo.objects.typed.base.replace_geoscience_object", mock_client.replace_geoscience_object),
patch("evo.objects.DownloadedObject.from_context", mock_client.from_reference),
Expand Down
Loading