Skip to content

chore(state datapoints): Fix state datapoints getitem, slicing and iteration - #2824

Open
haakonvt wants to merge 8 commits into
add-state-ts-retrieve-arrays-supportfrom
fix-state-dps-getitem-and-iteration
Open

chore(state datapoints): Fix state datapoints getitem, slicing and iteration#2824
haakonvt wants to merge 8 commits into
add-state-ts-retrieve-arrays-supportfrom
fix-state-dps-getitem-and-iteration

Conversation

@haakonvt

@haakonvt haakonvt commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Add proper support for state datapoints (numeric_states, string_states) in DatapointsArray and Datapoints: __getitem__/slicing, & iteration.

Changes:

  • Added numeric_states and string_states fields to DatapointsArray initialization and _data_fields()
  • Fixed __getitem__() and iteration to:
    • Convert float64 arrays back to int (with NaN -> None)
    • Map plural state keys (numeric_statesnumeric_state) for single Datapoint objects
  • Fixed dump() to output singular state keys (numericState/numeric_state) in JSON
  • Added test coverage for state datapoint getitem, slicing, iteration, and dump behavior

@haakonvt
haakonvt requested review from a team as code owners September 7, 2026 20:05
@haakonvt
haakonvt force-pushed the fix-state-dps-getitem-and-iteration branch from bbb024a to 72155c4 Compare September 7, 2026 20:05

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

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.

Code Review

This pull request adds support for state datapoints (numeric and string states) in Datapoints and DatapointsArray, including plural-to-singular key mapping and handling of missing values (NaN to None). It also adds corresponding unit tests. The feedback suggests optimizing the numpy_dtype_fix function by checking for None early to avoid exception overhead in performance-critical loops.

Comment thread cognite/client/data_classes/datapoints.py
@codecov

codecov Bot commented Sep 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (08de949) to head (b1bad12).

Additional details and impacted files
@@                           Coverage Diff                            @@
##           add-state-ts-retrieve-arrays-support    #2824      +/-   ##
========================================================================
+ Coverage                                 93.13%   93.16%   +0.03%     
========================================================================
  Files                                       516      516              
  Lines                                     53832    53929      +97     
========================================================================
+ Hits                                      50135    50245     +110     
+ Misses                                     3697     3684      -13     
Files with missing lines Coverage Δ
cognite/client/data_classes/datapoints.py 90.98% <100.00%> (+0.39%) ⬆️
...ts/tests_unit/test_data_classes/test_datapoints.py 100.00% <100.00%> (ø)

... and 7 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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