Skip to content

feat(DatapointsAPI): Add missing 'type' field to Datapoints[Array] data classes#2484

Open
haakonvt wants to merge 6 commits intopysdk-release-v8from
add-dps-type-field
Open

feat(DatapointsAPI): Add missing 'type' field to Datapoints[Array] data classes#2484
haakonvt wants to merge 6 commits intopysdk-release-v8from
add-dps-type-field

Conversation

@haakonvt
Copy link
Contributor

@haakonvt haakonvt commented Feb 20, 2026

Since we have not released v8 yet, we have a golden opportunity to implement necessary changes just-in-time for release.

Changes

  1. Update protobuf files
  2. Update Datapoints and DatapointsArray to respect required fields
  3. Add the new field 'type' as required

@haakonvt haakonvt requested review from a team as code owners February 20, 2026 19:47
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @haakonvt, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the time series data model by introducing a new mandatory 'type' field to the Datapoints and DatapointsArray classes. This change ensures that time series data explicitly carries its type information, which is reflected across protobuf definitions, class constructors, data loading mechanisms, and various utility functions. The update also includes a performance-driven change to the equality comparison for Datapoints objects and a minor script refactoring.

Highlights

  • New 'type' field: Introduced a mandatory 'type' field to the Datapoints and DatapointsArray data classes, which can be 'numeric', 'string', or 'state'.
  • Protobuf updates: Updated the underlying protobuf definitions (data_point_list_response_pb2.py and data_point_list_response_pb2.pyi) to include the new TimeSeriesType enum and the 'type' field in DataPointListItem.
  • Data class constructor changes: Modified the __init__ methods of Datapoints and DatapointsArray to require id, is_string, is_step, and the new type field.
  • Internal method adjustments: Updated various internal methods such as _load, _ts_info, dump, _get_non_empty_data_fields, and _slice to correctly handle the new 'type' field.
  • Equality comparison change: Overrode the __eq__ method in Datapoints to compare objects by identity (id(self) == id(other)) rather than content, addressing performance concerns with large data arrays.
  • Test suite alignment: Adjusted numerous unit and integration tests to pass the newly required arguments to Datapoints and DatapointsArray constructors.
  • Script refinement: Simplified the scripts/update_proto_files.py by removing shlex.split when calling subprocess.run.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • cognite/client/_proto/data_point_list_response_pb2.py
    • Updated protobuf definition to include a new TimeSeriesType enum and a 'type' field in DataPointListItem.
  • cognite/client/_proto/data_point_list_response_pb2.pyi
    • Updated type hints for the protobuf generated code to reflect the new TimeSeriesType enum and 'type' field.
  • cognite/client/data_classes/datapoint_aggregates.py
    • Corrected a typo in a comment from 'techinally' to 'technically'.
  • cognite/client/data_classes/datapoints.py
    • Modified DatapointsArray and Datapoints constructors to make id, is_string, is_step, and type required arguments.
    • Updated _load methods to handle the new required fields.
    • Included the 'type' field in _ts_info, dump, _get_non_empty_data_fields, and _slice methods.
    • Overrode the __eq__ method in Datapoints to compare by object identity.
  • cognite/client/utils/_datapoints.py
    • Added the 'type' field to the dictionary returned by get_ts_info_from_proto.
  • scripts/update_proto_files.py
    • Refactored the subprocess.run call by removing shlex.split for cleaner execution.
  • tests/tests_integration/test_api/test_datapoints.py
    • Updated DatapointsArray constructor calls in integration tests to include the new required fields.
  • tests/tests_integration/test_api/test_synthetic_time_series.py
    • Updated Datapoints constructor calls in integration tests to include the new required fields.
  • tests/tests_unit/test_api/test_datapoints.py
    • Updated Datapoints constructor calls in unit tests to include the new required fields.
  • tests/tests_unit/test_data_classes/test_repr.py
    • Updated Datapoints and DatapointsArray constructor calls in representation tests to include the new required fields.
Activity
  • The author updated protobuf files to reflect the new data model.
  • The author updated the Datapoints and DatapointsArray classes to incorporate the new required fields.
  • The author added the 'type' field as a required attribute in the relevant data classes.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
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

The pull request adds the type field and enforces required fields in Datapoints and DatapointsArray. However, the change to __eq__ in Datapoints to use object identity (id()) is a critical issue that breaks value equality and will cause unit tests to fail. Additionally, the PR title is missing the ! indicator for breaking changes, and there is a type mismatch where the proto integer enum for type is passed directly to classes expecting string literals.

Comment on lines 1041 to +1044
def __eq__(self, other: Any) -> bool:
return (
type(self) is type(other)
and self.id == other.id
and self.external_id == other.external_id
and list(self._get_non_empty_data_fields()) == list(other._get_non_empty_data_fields())
)
# Override CogniteResource __eq__ which checks exact type & dump being equal. We do not want
# this: comparing arrays with (mostly) floats is a very bad idea; also dump is exceedingly expensive.
return id(self) == id(other)
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

The __eq__ implementation has been changed to check object identity (id(self) == id(other)). This is a critical issue for DTOs as it breaks value equality; different instances with identical data will no longer be considered equal. This change also causes the test_eq unit test in this PR to fail. If dump() is too expensive, please implement a more efficient value-based equality check instead of falling back to identity.

Comment on lines +609 to +612
id: int,
is_string: bool,
is_step: bool,
type: Literal["numeric", "string", "state"],
Copy link
Contributor

Choose a reason for hiding this comment

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

high

Making id, is_string, is_step, and type required arguments in the constructor is a breaking change. According to the repository style guide, breaking changes must be indicated in the PR title with a ! after the type/scope.

References
  1. Breaking changes must be clearly indicated in the PR title with a ! after the type/scope. (link)

"external_id": res.externalId,
"is_string": res.isString,
"is_step": res.isStep,
"type": res.type,
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The res.type value from the protobuf response is an integer enum, but the Datapoints and DatapointsArray classes expect a string literal ('numeric', 'string', or 'state'). Passing the raw integer will cause type mismatches. Please map the proto enum values to the corresponding string literals.

References
  1. Strong Typing: Use type hints extensively with MyPy. Avoid Any when possible. (link)

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