Update time series
- async AsyncCogniteClient.time_series.update(
- item: TimeSeries | TimeSeriesWrite | TimeSeriesUpdate | Sequence[TimeSeries | TimeSeriesWrite | TimeSeriesUpdate],
- mode: Literal['replace_ignore_null', 'patch', 'replace'] = 'replace_ignore_null',
Update one or more time series.
- Parameters:
item (TimeSeries | TimeSeriesWrite | TimeSeriesUpdate | Sequence[TimeSeries | TimeSeriesWrite | TimeSeriesUpdate]) – Time series to update
mode (Literal['replace_ignore_null', 'patch', 'replace']) – How to update data when a non-update object is given (TimeSeries or -Write). If you use ‘replace_ignore_null’, only the fields you have set will be used to replace existing (default). Using ‘replace’ will additionally clear all the fields that are not specified by you. Last option, ‘patch’, will update only the fields you have set and for container-like fields such as metadata or labels, add the values to the existing. For more details, see Update and Upsert Mode Parameter.
- Returns:
Updated time series.
- Return type:
Examples
Update a time series that you have fetched. This will perform a full update of the time series:
>>> from cognite.client import CogniteClient, AsyncCogniteClient >>> client = CogniteClient() >>> # async_client = AsyncCogniteClient() # another option >>> res = client.time_series.retrieve(id=1) >>> res.description = "New description" >>> res = client.time_series.update(res)
Perform a partial update on a time series, updating the description and adding a new field to metadata:
>>> from cognite.client.data_classes import TimeSeriesUpdate >>> my_update = ( ... TimeSeriesUpdate(id=1) ... .description.set("New description") ... .metadata.add({"key": "value"}) ... ) >>> res = client.time_series.update(my_update)
Perform a partial update on a time series by instance id.
Warning: It is not recommended to update a time series with an instance_id through the Time Series API. Only a very limited set of legacy properties can be updated this way; the majority must be updated via the Data Modeling API (the same API that was used to create the time series in the first place).
>>> from cognite.client.data_classes import TimeSeriesUpdate >>> from cognite.client.data_classes.data_modeling import NodeId
>>> my_update = ( ... TimeSeriesUpdate(instance_id=NodeId("test", "hello")) ... .external_id.set("test:hello") ... .metadata.add({"test": "hello"}) ... ) >>> client.time_series.update(my_update)