Skip to content

Commit

Permalink
fix TimeSeries methods: count, latest and first (#2043)
Browse files Browse the repository at this point in the history
  • Loading branch information
haakonvt authored Nov 27, 2024
1 parent 1dc0e88 commit a03c882
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cognite/client/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import annotations

__version__ = "7.69.0"
__version__ = "7.69.1"
__api_subversion__ = "20230101"
6 changes: 3 additions & 3 deletions cognite/client/data_classes/time_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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
Expand All @@ -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
)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from collections.abc import Iterator
from contextlib import suppress

import pytest
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import pytest

from cognite.client.data_classes import TransformationDestination


Expand All @@ -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"
Expand Down
1 change: 1 addition & 0 deletions tests/tests_integration/test_api/test_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a03c882

Please sign in to comment.