Skip to content

feat: Allow iterable of ids in retrieve methods for datapoints#2583

Open
MortGron wants to merge 4 commits into
masterfrom
retrieve-datapoints-accept-iterable-of-ids
Open

feat: Allow iterable of ids in retrieve methods for datapoints#2583
MortGron wants to merge 4 commits into
masterfrom
retrieve-datapoints-accept-iterable-of-ids

Conversation

@MortGron
Copy link
Copy Markdown
Contributor

Description

It is common that the IDs the users fead to the retreive methods are in a set or dict or other non-sequence type.
This PRs allow the IDs be Iterable in the datapoints retrieve methods.

Checklist:

  • Tests added/updated.
  • Documentation updated. Documentation is generated from docstrings - these must be updated according to your change.
    If a new method has been added it should be referenced in cognite.rst in order to generate docs based on its docstring.
  • The PR title follows the Conventional Commit spec.

@MortGron MortGron marked this pull request as ready for review April 20, 2026 20:52
@MortGron MortGron requested review from a team as code owners April 20, 2026 20:52
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request generalizes the input types for datapoint retrieval methods, replacing Sequence and SequenceNotStr with Iterable across the API and utility modules. Feedback was provided to explicitly disallow dict inputs in the identifier parsing logic, as dictionaries are iterables that could lead to confusing error messages if not handled early.

Comment thread cognite/client/_api/datapoint_tasks.py
@MortGron
Copy link
Copy Markdown
Contributor Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the datapoints API to support Iterable types for identifiers, allowing the use of collections like sets or dictionary keys instead of being restricted to sequences. The changes include updates to type hints, docstrings, and internal parsing logic across the async and sync APIs. Feedback indicates that _FullDatapointsQuery.is_single_identifier and the retrieve_latest method were not updated to handle the new Iterable support, which may result in incorrect return types or ignored settings for certain collection types.

Comment thread cognite/client/_api/datapoint_tasks.py
Comment on lines +1010 to +1012
id (None | int | DatapointsQuery | Iterable[int | DatapointsQuery]): Id, DatapointsQuery or (mixed) iterable of these. If a dict is passed, its keys will be used as ids. See examples below.
external_id (None | str | DatapointsQuery | Iterable[str | DatapointsQuery]): External id, DatapointsQuery or (mixed) iterable of these. If a dict is passed, its keys will be used as external_ids. See examples below.
instance_id (None | NodeId | DatapointsQuery | Iterable[NodeId | DatapointsQuery]): Instance id, DatapointsQuery or (mixed) iterable of these. If a dict is passed, its keys will be used as instance_ids.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The overloads for retrieve_latest (starting at line 1642) and its internal helper RetrieveLatestDpsFetcher._parse_user_input (line 2552) were not updated to support Iterable and still rely on Sequence and MutableSequence. This results in an inconsistent API where set or tuple of LatestDatapointQuery objects will not be correctly processed, and their individual settings (like before or target_unit) will be ignored.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what Gemini asks for here is consistency across the retrieve datapoints methods. I personally am ok with incrementally chaning the methods to accept Iterable of IDs, that is, skipping retrieve_latest for now. What do you think @cognitedata/python-sdk-maintainers ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant