From a03c882c5a53edd5e9f05e566205d7311a856234 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20V=2E=20Treider?= Date: Wed, 27 Nov 2024 23:58:19 +0100 Subject: [PATCH] fix TimeSeries methods: count, latest and first (#2043) --- CHANGELOG.md | 5 +++++ cognite/client/_version.py | 2 +- cognite/client/data_classes/time_series.py | 6 +++--- pyproject.toml | 2 +- .../test_api/test_postgres_gateway/test_tables.py | 3 ++- .../test_api/test_transformations/test_schema.py | 3 +++ tests/tests_integration/test_api/test_workflows.py | 1 + 7 files changed, 16 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3382eba294..8ccefddf48 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,11 @@ Changes are grouped as follows - `Fixed` for any bug fixes. - `Security` in case of vulnerabilities. +## [7.69.1] - 2024-11-25 +### Fixed +- Convenience methods for `TimeSeries` (defined through Data Modeling with `instance_id`) now works as + intended: `count`, `latest` and `first`. + ## [7.69.0] - 2024-11-23 ### Added - Synthetic Datapoints API has better support for `instance_id`. Previously you had to specify these directly diff --git a/cognite/client/_version.py b/cognite/client/_version.py index 605c9152ed..32b309b089 100644 --- a/cognite/client/_version.py +++ b/cognite/client/_version.py @@ -1,4 +1,4 @@ from __future__ import annotations -__version__ = "7.69.0" +__version__ = "7.69.1" __api_subversion__ = "20230101" diff --git a/cognite/client/data_classes/time_series.py b/cognite/client/data_classes/time_series.py index b9fdb9d504..e92da53bf3 100644 --- a/cognite/client/data_classes/time_series.py +++ b/cognite/client/data_classes/time_series.py @@ -214,7 +214,7 @@ def count(self) -> int: if self.is_string: raise RuntimeError("String time series does not support count aggregate.") - identifier = Identifier.load(self.id, self.external_id).as_dict() + identifier = Identifier.load(self.id, self.external_id, self.instance_id).as_dict() dps = self._cognite_client.time_series.data.retrieve( **identifier, start=MIN_TIMESTAMP_MS, end=MAX_TIMESTAMP_MS + 1, aggregates="count", granularity="100d" ) @@ -228,7 +228,7 @@ def latest(self, before: int | str | datetime | None = None) -> Datapoint | None Returns: Datapoint | None: A datapoint object containing the value and timestamp of the latest datapoint. """ - identifier = Identifier.load(self.id, self.external_id).as_dict() + identifier = Identifier.load(self.id, self.external_id, self.instance_id).as_dict() if dps := self._cognite_client.time_series.data.retrieve_latest(**identifier, before=before): return dps[0] # type: ignore [return-value] return None @@ -239,7 +239,7 @@ def first(self) -> Datapoint | None: Returns: Datapoint | None: A datapoint object containing the value and timestamp of the first datapoint. """ - identifier = Identifier.load(self.id, self.external_id).as_dict() + identifier = Identifier.load(self.id, self.external_id, self.instance_id).as_dict() dps = self._cognite_client.time_series.data.retrieve( **identifier, start=MIN_TIMESTAMP_MS, end=MAX_TIMESTAMP_MS + 1, limit=1 ) diff --git a/pyproject.toml b/pyproject.toml index fd57af7ab1..1dc147dd34 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [tool.poetry] name = "cognite-sdk" -version = "7.69.0" +version = "7.69.1" description = "Cognite Python SDK" readme = "README.md" documentation = "https://cognite-sdk-python.readthedocs-hosted.com" diff --git a/tests/tests_integration/test_api/test_postgres_gateway/test_tables.py b/tests/tests_integration/test_api/test_postgres_gateway/test_tables.py index ce4cdfb3dc..7d3f8fcc86 100644 --- a/tests/tests_integration/test_api/test_postgres_gateway/test_tables.py +++ b/tests/tests_integration/test_api/test_postgres_gateway/test_tables.py @@ -1,3 +1,4 @@ +from collections.abc import Iterator from contextlib import suppress import pytest @@ -76,7 +77,7 @@ def one_raw_table(cognite_client: CogniteClient) -> tuple[str, str]: @pytest.fixture -def one_table(cognite_client: CogniteClient, one_user: User, one_raw_table: tuple[str, str]) -> Table: +def one_table(cognite_client: CogniteClient, one_user: User, one_raw_table: tuple[str, str]) -> Iterator[Table]: my_table = RawTableWrite( tablename=f"my_table-{random_string(10)}", options=RawTableOptions( diff --git a/tests/tests_integration/test_api/test_transformations/test_schema.py b/tests/tests_integration/test_api/test_transformations/test_schema.py index 6c5a99d264..db168257d4 100644 --- a/tests/tests_integration/test_api/test_transformations/test_schema.py +++ b/tests/tests_integration/test_api/test_transformations/test_schema.py @@ -1,3 +1,5 @@ +import pytest + from cognite.client.data_classes import TransformationDestination @@ -10,6 +12,7 @@ def test_assets(self, cognite_client): assert next(col for col in asset_columns if col.name == "metadata").type.type == "map" assert next(col for col in asset_columns if col.name == "metadata").type.key_type == "string" + @pytest.mark.xfail(reason="Nullable changed to False in a recent refactor, fix/revert underway") def test_assets_delete(self, cognite_client): asset_columns = cognite_client.transformations.schema.retrieve( destination=TransformationDestination.assets(), conflict_mode="delete" diff --git a/tests/tests_integration/test_api/test_workflows.py b/tests/tests_integration/test_api/test_workflows.py index 00f5c80070..3432bb308a 100644 --- a/tests/tests_integration/test_api/test_workflows.py +++ b/tests/tests_integration/test_api/test_workflows.py @@ -318,6 +318,7 @@ def test_retrieve_non_existing_workflow(self, cognite_client: CogniteClient) -> non_existing = cognite_client.workflows.retrieve("integration_test-non_existing_workflow") assert non_existing is None + @pytest.mark.skip("flaky; fix underway") def test_list_workflows(self, cognite_client: CogniteClient, workflow_list: WorkflowList) -> None: listed = cognite_client.workflows.list(limit=-1) assert len(listed) >= len(workflow_list)