Skip to content

chore: handle pandas v2 and v3 by enforcing datetime freq of millisec#2528

Open
haakonvt wants to merge 3 commits intopysdk-release-v8from
fix-pandas-v3
Open

chore: handle pandas v2 and v3 by enforcing datetime freq of millisec#2528
haakonvt wants to merge 3 commits intopysdk-release-v8from
fix-pandas-v3

Conversation

@haakonvt
Copy link
Copy Markdown
Contributor

@haakonvt haakonvt commented Mar 25, 2026

Quite a few changes in pandas v3, specifically around the inference of frequency for datetime-like data: https://pandas.pydata.org/docs/whatsnew/v3.0.0.html#datetime-timedelta-resolution-inference

This PR unifies frequency to always be milliseconds, matching the API closely.

@haakonvt haakonvt requested review from a team as code owners March 25, 2026 12:44
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 addresses compatibility issues with Pandas v3 by unifying datetime frequency to milliseconds throughout the application. The changes ensure consistent and correct handling of time-series data, adapting to Pandas' updated inference mechanisms. Additionally, various project dependencies have been updated to their latest stable versions, improving overall stability and leveraging new features.

Highlights

  • Pandas v3 Compatibility: Adapted the codebase to handle changes introduced in Pandas v3, particularly concerning datetime frequency inference.
  • Datetime Frequency Unification: Standardized datetime handling to consistently use millisecond ('ms') frequency across relevant functions and data structures, aligning with the updated Pandas API.
  • Dependency Updates: Updated numerous Python dependencies in poetry.lock to their latest versions, including anyio, charset-normalizer, importlib-metadata, jaraco-context, nh3, protobuf, pyjwt, python-discovery, and types-requests. This also includes conditional updates for pandas itself, supporting both v2.x and v3.x based on Python version.
  • Test Adjustments: Modified unit tests to reflect the new millisecond datetime precision and updated Pandas DataFrame indexing syntax (e.g., using .iloc[0] instead of [0]).

🧠 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.

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.

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
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 handling of datetime units in pandas DataFrames from nanoseconds to milliseconds across the codebase, including the _pandas_helpers.py utility functions and various unit tests. Additionally, it includes numerous dependency updates in poetry.lock, notably upgrading anyio, charset-normalizer, identify, importlib-metadata, jaraco-context, nh3, protobuf, pyjwt, python-discovery, and types-requests. The dependency management for pandas has been refined to support different versions based on the Python environment, with a new entry for pandas 3.0.1 for Python >=3.11 and adjusted markers for pandas and pytz for Python 3.10. There are no review comments to address.

@haakonvt haakonvt changed the title Fix pandas v3 chore: handle pandas v2 and v3 by enforcing datetime freq of millisec Mar 25, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 25, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.44%. Comparing base (b201b22) to head (b6f0dd5).
⚠️ Report is 6 commits behind head on pysdk-release-v8.

Additional details and impacted files
@@                 Coverage Diff                  @@
##           pysdk-release-v8    #2528      +/-   ##
====================================================
- Coverage             93.44%   93.44%   -0.01%     
====================================================
  Files                   478      478              
  Lines                 48173    48218      +45     
====================================================
+ Hits                  45016    45058      +42     
- Misses                 3157     3160       +3     
Files with missing lines Coverage Δ
cognite/client/utils/_pandas_helpers.py 87.65% <100.00%> (ø)
...tegration/test_api/test_datapoint_subscriptions.py 86.93% <100.00%> (ø)
...ests/tests_integration/test_api/test_datapoints.py 99.30% <100.00%> (+<0.01%) ⬆️
tests/tests_unit/test_api/test_datapoints.py 100.00% <100.00%> (ø)
tests/tests_unit/test_api/test_raw.py 100.00% <ø> (ø)
tests/tests_unit/test_api/test_sequences.py 100.00% <100.00%> (ø)
tests/tests_unit/test_api/test_time_series.py 100.00% <100.00%> (ø)
tests/tests_unit/test_base.py 98.93% <ø> (ø)
...a_classes/test_data_models/test_typed_instances.py 99.37% <ø> (ø)
...ts/tests_unit/test_data_classes/test_datapoints.py 100.00% <ø> (ø)
... and 1 more

... and 16 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.

@MortGron
Copy link
Copy Markdown
Contributor

I already made a PR for this: #2485
I will just quote from the description of that PR:

Currently when using to_pandas on list like objects a timestamp resolution of 'ns' is enforced for both Pandas v2 and v3. For single Cognite resources that have only timestamp attributes, resolution will be 'ns' in Pandas v2 and 'ms' in v3. For single Cognite resources that have at least on timestamp attribute and at least one non-timestamp attribute, time resolution will be 'ms' in both v2 and v3.

Are all these cases handled here?

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.

2 participants