Skip to content

Commit

Permalink
improve code example
Browse files Browse the repository at this point in the history
  • Loading branch information
haakonvt committed Nov 23, 2023
1 parent b93ceab commit 5ec09ae
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 21 deletions.
34 changes: 14 additions & 20 deletions cognite/client/_api/transformations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,34 +299,28 @@ def update(
Perform a partial update on a transformation, updating the query and making it private::
>>> from cognite.client import CogniteClient
>>> from cognite.client.data_classes import TransformationUpdate
>>> c = CogniteClient()
>>> my_update = TransformationUpdate(id=1).query.set("SELECT * FROM _cdf.assets").is_public.set(False)
>>> res = c.transformations.update(my_update)
Update the session used when authenticating for a list of transformations:
Update the session used for reading (source) and writing (destination) when authenticating for all
transformations in a given data set:
>>> from cognite.client import CogniteClient
>>> from cognite.client.data_classes import NonceCredentials
>>> c = CogniteClient()
>>> session = c.iam.sessions.create()
>>> nonce = NonceCredentials(
... session_id=session.id,
... nonce=session.nonce,
... cdf_project_name=client.config.project
>>> to_update = c.transformations.list(data_set_external_ids=["foo"])
>>> new_session = c.iam.sessions.create()
>>> new_nonce = NonceCredentials(
... session_id=new_session.id,
... nonce=new_session.nonce,
... cdf_project_name=c.config.project
... )
>>> my_updates = []
>>> for t in c.transformations.list():
... t.source_nonce = nonce
... t.destination_nonce = nonce
... updates.append(t)
>>> c.transformations.update(my_updates)
>>> for tr in to_update:
... tr.source_nonce = new_nonce
... tr.destination_nonce = new_nonce
>>> res = c.transformations.update(to_update)
"""

if isinstance(item, Sequence):
item = list(item).copy()
item = list(item)
sessions: dict[str, NonceCredentials] = {}
for i, t in enumerate(item):
if isinstance(t, Transformation):
Expand All @@ -340,7 +334,7 @@ def update(
item._process_credentials(keep_none=True)
elif not isinstance(item, TransformationUpdate):
raise TypeError(
"item must be Sequence[Transformation], Transformation, Sequence[TransformationUpdate] or TransformationUpdate"
"item must be one of: TransformationUpdate, Transformation, Sequence[TransformationUpdate | Transformation]."
)

return self._update_multiple(
Expand Down
2 changes: 1 addition & 1 deletion cognite/client/data_classes/transformations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ class TransformationFilter(CogniteFilter):
has_blocked_error (bool | None): Whether only the blocked transformations should be included in the results.
created_time (dict[str, Any] | TimestampRange | None): Range between two timestamps
last_updated_time (dict[str, Any] | TimestampRange | None): Range between two timestamps
data_set_ids (list[dict[str, Any]] | None): Return only transformations in the specified data sets with these ids.
data_set_ids (list[dict[str, Any]] | None): Return only transformations in the specified data sets with these ids, e.g. [{"id": 1}, {"externalId": "foo"}].
tags (TagsFilter | None): Return only the resource matching the specified tags constraints. It only supports ContainsAny as of now.
"""

Expand Down

0 comments on commit 5ec09ae

Please sign in to comment.