4545 LatestDatapointList ,
4646 LatestDatapointQuery ,
4747)
48- from cognite .client .data_classes .data_modeling . ids import NodeId
48+ from cognite .client .data_classes .data_modeling import NodeId
4949from cognite .client .data_classes .datapoint_aggregates import Aggregate
5050from cognite .client .exceptions import CogniteAPIError , CogniteNotFoundError
5151from cognite .client .utils import _json_extended as _json
@@ -1029,16 +1029,16 @@ async def retrieve(
10291029 Examples:
10301030
10311031 You can specify the identifiers of the datapoints you wish to retrieve in a number of ways. In this example
1032- we are using the time-ago format, ``"2w-ago"`` to get raw data for the time series with id=42 from 2 weeks ago up until now.
1032+ we are using the time-ago format, ``"2w-ago"`` to get raw data for a time series from 2 weeks ago up until now.
10331033 You can also use the time-ahead format, like ``"3d-ahead"``, to specify a relative time in the future.
10341034
10351035 >>> from cognite.client import CogniteClient, AsyncCogniteClient
1036+ >>> from cognite.client.data_classes.data_modeling import NodeId
10361037 >>> client = CogniteClient()
10371038 >>> # async_client = AsyncCogniteClient() # another option
1038- >>> dps = client.time_series.data.retrieve(id=42, start="2w-ago")
1039- >>> # You can also use instance_id:
1040- >>> from cognite.client.data_classes.data_modeling import NodeId
1041- >>> dps = client.time_series.data.retrieve(instance_id=NodeId("ts-space", "foo"))
1039+ >>> dps = client.time_series.data.retrieve(
1040+ ... instance_id=NodeId("ts-space", "foo"), start="2w-ago"
1041+ ... )
10421042
10431043 Although raw datapoints are returned by default, you can also get aggregated values, such as `max` or `average`. You may also fetch more than one time series simultaneously. Here we are
10441044 getting daily averages and maximum values for all of 2018, for two different time series, where we're specifying `start` and `end` as integers
@@ -1396,14 +1396,15 @@ async def retrieve_arrays(
13961396
13971397 Examples:
13981398
1399- Get weekly ``min`` and ``max`` aggregates for a time series with id=42 since the year 2000 , then compute the range of values:
1399+ Get weekly ``min`` and ``max`` aggregates for a time series using instance_id , then compute the range of values:
14001400
14011401 >>> from cognite.client import CogniteClient
1402+ >>> from cognite.client.data_classes.data_modeling import NodeId
14021403 >>> from datetime import datetime, timezone
14031404 >>> client = CogniteClient()
14041405 >>> # async_client = AsyncCogniteClient() # another option
14051406 >>> dps = client.time_series.data.retrieve_arrays(
1406- ... id=42 ,
1407+ ... instance_id=NodeId("my-space", "my-ts-xid") ,
14071408 ... start=datetime(2020, 1, 1, tzinfo=timezone.utc),
14081409 ... aggregates=["min", "max"],
14091410 ... granularity="7d",
@@ -1536,14 +1537,15 @@ async def retrieve_dataframe(
15361537
15371538 Examples:
15381539
1539- Get a pandas dataframe using a single time series external ID, with data from the last two weeks,
1540+ Get a pandas dataframe using a single time series instance ID, with data from the last two weeks,
15401541 but with no more than 100 datapoints:
15411542
15421543 >>> from cognite.client import CogniteClient, AsyncCogniteClient
1544+ >>> from cognite.client.data_classes.data_modeling import NodeId
15431545 >>> client = CogniteClient()
15441546 >>> # async_client = AsyncCogniteClient() # another option
15451547 >>> df = client.time_series.data.retrieve_dataframe(
1546- ... external_id="foo" , start="2w-ago", end="now", limit=100
1548+ ... instance_id=NodeId("my-space", "my-ts-xid") , start="2w-ago", end="now", limit=100
15471549 ... )
15481550
15491551 Get the pandas dataframe with a uniform index (fixed spacing between points) of 1 day, for two time series with
@@ -1574,11 +1576,11 @@ async def retrieve_dataframe(
15741576 ... include_aggregate_name=False,
15751577 ... )
15761578
1577- You may also use ``pandas.Timestamp`` to define start and end. Here we fetch using instance_id :
1579+ You may also use ``pandas.Timestamp`` to define start and end:
15781580
15791581 >>> import pandas as pd
15801582 >>> df = client.time_series.data.retrieve_dataframe(
1581- ... instance_id=NodeId("my-space", "my-ts-xid") ,
1583+ ... external_id="foo" ,
15821584 ... start=pd.Timestamp("2023-01-01"),
15831585 ... end=pd.Timestamp("2023-02-01"),
15841586 ... )
@@ -1849,18 +1851,18 @@ async def retrieve_latest(
18491851 Getting the latest datapoint in a time series:
18501852
18511853 >>> from cognite.client import CogniteClient, AsyncCogniteClient
1854+ >>> from cognite.client.data_classes.data_modeling import NodeId
18521855 >>> client = CogniteClient()
18531856 >>> # async_client = AsyncCogniteClient() # another option
1854- >>> res = client.time_series.data.retrieve_latest(id=1)
1857+ >>> res = client.time_series.data.retrieve_latest(
1858+ ... instance_id=NodeId("my-space", "my-ts-xid")
1859+ ... )
18551860 >>> if res: # Check if datapoint exists
18561861 ... print(res.timestamp, res.value)
18571862
1858- You can also use external_id or instance_id ; single identifier or list of identifiers:
1863+ You can also use id or external_id ; single identifier or list of identifiers:
18591864
1860- >>> from cognite.client.data_classes.data_modeling import NodeId
1861- >>> res = client.time_series.data.retrieve_latest(
1862- ... external_id=["foo", "bar"], instance_id=NodeId("my-space", "my-ts-xid")
1863- ... )
1865+ >>> res = client.time_series.data.retrieve_latest(id=1, external_id=["foo", "bar"])
18641866
18651867 You can also get the latest datapoint before a specific time:
18661868
@@ -1978,6 +1980,7 @@ async def insert(
19781980
19791981 >>> from cognite.client import CogniteClient
19801982 >>> from cognite.client.data_classes import StatusCode
1983+ >>> from cognite.client.data_classes.data_modeling import NodeId
19811984 >>> from datetime import datetime, timezone
19821985 >>> client = CogniteClient()
19831986 >>> # async_client = AsyncCogniteClient() # another option
@@ -1987,20 +1990,19 @@ async def insert(
19871990 ... (datetime(2018, 1, 3, tzinfo=timezone.utc), 3000, StatusCode.Uncertain),
19881991 ... (datetime(2018, 1, 4, tzinfo=timezone.utc), None, StatusCode.Bad),
19891992 ... ]
1990- >>> client.time_series.data.insert(datapoints, id=1)
1993+ >>> client.time_series.data.insert(
1994+ ... datapoints, instance_id=NodeId("my-space", "my-ts-xid")
1995+ ... )
19911996
19921997 The timestamp can be given by datetime as above, or in milliseconds since epoch. Status codes can also be
19931998 passed as normal integers; this is necessary if a subcategory or modifier flag is needed, e.g. 3145728: 'GoodClamped':
19941999
1995- >>> from cognite.client.data_classes.data_modeling import NodeId
19962000 >>> datapoints = [
19972001 ... (150000000000, 1000),
19982002 ... (160000000000, 2000, 3145728),
19992003 ... (170000000000, 2000, 2147483648), # Same as StatusCode.Bad
20002004 ... ]
2001- >>> client.time_series.data.insert(
2002- ... datapoints, instance_id=NodeId("my-space", "my-ts-xid")
2003- ... )
2005+ >>> client.time_series.data.insert(datapoints, id=1)
20042006
20052007 Or they can be a list of dictionaries:
20062008
@@ -2161,9 +2163,12 @@ async def delete_range(
21612163 Deleting the last week of data from a time series:
21622164
21632165 >>> from cognite.client import CogniteClient, AsyncCogniteClient
2166+ >>> from cognite.client.data_classes.data_modeling import NodeId
21642167 >>> client = CogniteClient()
21652168 >>> # async_client = AsyncCogniteClient() # another option
2166- >>> client.time_series.data.delete_range(start="1w-ago", end="now", id=1)
2169+ >>> client.time_series.data.delete_range(
2170+ ... start="1w-ago", end="now", instance_id=NodeId("my-space", "my-ts-xid")
2171+ ... )
21672172
21682173 Deleting the data from now until 2 days in the future from a time series containing e.g. forecasted data:
21692174
0 commit comments