Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support NumPy > 2.0 and Python 3.12 #115

Merged
merged 6 commits into from
Sep 11, 2024

Conversation

lochhh
Copy link
Contributor

@lochhh lochhh commented Sep 10, 2024

Closes #114

This PR addresses the failing tests reported in #114 (due to deprecations in NumPy 2.0) by:

  • replacing the deprecated np.string_ with np.bytes_
  • replacing bool(np.all(...)) with np.array_equal in grayscale detection
  • replacing np.in1d with np.isin

In addition, datetime.utcnow() is also deprecated since Python 3.12. So this has been replaced with datetime.datetime.now(datetime.timezone.utc). The alternative would be datetime.datetime.now(datetime.UTC) but this alias has only been added in version 3.11.

Despite the above changes, the tests continued to fail on CI. It turns out that on conda-forge the build package is called python-build. So I've updated this in the environment.yml as well.

Summary by CodeRabbit

  • New Features

    • Updated environment configuration to allow any version of numpy, enhancing compatibility with newer features.
    • Improved timestamp generation with explicit UTC timezone for better consistency across applications.
  • Bug Fixes

    • Enhanced grayscale detection logic for improved reliability in image processing.
  • Tests

    • Replaced np.in1d with np.isin in test cases for better clarity and performance.

Copy link
Contributor

coderabbitai bot commented Sep 10, 2024

Walkthrough

This pull request modifies the environment.yml file to support any version of NumPy, addressing compatibility issues with newer releases. It also updates the sleap_io/io/labelstudio.py file to improve timestamp handling by ensuring UTC representation. The sleap_io/io/slp.py file changes JSON encoding from strings to bytes, while the sleap_io/io/video.py file enhances grayscale detection logic. Lastly, a test assertion in tests/io/test_nwb.py is updated for improved clarity and efficiency.

Changes

Files Change Summary
environment.yml Removed version constraint for numpy, renamed build to python-build.
sleap_io/io/labelstudio.py, sleap_io/io/video.py Updated timestamp handling to UTC, reorganized imports, improved grayscale detection logic.
sleap_io/io/slp.py Changed JSON encoding from np.string_ to np.bytes_ in multiple functions.
tests/io/test_nwb.py Replaced np.in1d with np.isin in a test assertion for better clarity and efficiency.

Assessment against linked issues

Objective Addressed Explanation
Support for NumPy > 2.0.0 (#114)
Resolve deprecation warnings related to NumPy (#114)

🐰 In the meadow, we hop with glee,
New NumPy versions, wild and free!
With timestamps bright, in UTC's embrace,
Our code now dances, a joyful race!
From strings to bytes, we cheer and play,
Hooray for changes, hip-hip-hooray! 🌼

Tip

Announcements
  • The review status is no longer posted as a separate comment when there are no actionable or nitpick comments. In such cases, the review status is included in the walkthrough comment.
  • We have updated our review workflow to use the Anthropic's Claude family of models. Please share any feedback in the discussion post on our Discord.
  • Possibly related PRs: Walkthrough comment now includes a list of potentially related PRs to help you recall past context. Please share any feedback in the discussion post on our Discord.
  • Suggested labels: CodeRabbit can now suggest labels by learning from your past PRs in the walkthrough comment. You can also provide custom labeling instructions in the UI or configuration file.
  • Possibly related PRs, automatic label suggestions based on past PRs, learnings, and possibly related issues require data opt-in (enabled by default).

Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2bc3d52 and bd9293d.

Files selected for processing (5)
  • environment.yml (2 hunks)
  • sleap_io/io/labelstudio.py (2 hunks)
  • sleap_io/io/slp.py (4 hunks)
  • sleap_io/io/video.py (1 hunks)
  • tests/io/test_nwb.py (1 hunks)
Files skipped from review due to trivial changes (1)
  • tests/io/test_nwb.py
Additional comments not posted (9)
environment.yml (2)

17-17: Verify the impact of removing the numpy version constraint.

Removing the version constraint for numpy may introduce compatibility issues if the codebase relies on specific features or behavior of numpy versions below 2.0.0.

To verify the impact, run the test suite and manually test the critical functionalities of the application with the latest version of numpy installed.


27-27: LGTM!

Renaming the build package to python-build matches the package name on conda-forge.

sleap_io/io/labelstudio.py (1)

197-202: LGTM!

The change from datetime.datetime.utcnow() to datetime.datetime.now(datetime.timezone.utc) enhances the precision of the timestamps by explicitly setting the timezone to UTC and addresses the deprecation in Python 3.12.

sleap_io/io/video.py (1)

151-151: LGTM!

The change from using a boolean expression to np.array_equal improves the clarity and reliability of the grayscale detection logic by explicitly comparing the first and last channels of the image.

sleap_io/io/slp.py (5)

437-437: Verify compatibility impact of changing JSON encoding from np.string_ to np.bytes_.

This code segment changes the data type used for encoding JSON strings from np.string_ to np.bytes_ in the write_videos function.

Altering how the JSON data is represented and stored can potentially affect compatibility with components that read this data.

Ensure that all components that consume this JSON data can handle the np.bytes_ encoding. Verify there are no issues reading or deserializing the data.


469-469: Verify compatibility impact of changing JSON encoding to np.bytes_.

Similar to the previous code segment, this change in the write_tracks function also switches the JSON encoding to use np.bytes_.

Please refer to the compatibility verification requested in the previous comment. Ensure there are no issues with other components consuming this data.


520-520: Verify compatibility impact of changing JSON encoding to np.bytes_.

Once again, this code segment in the write_suggestions function changes the JSON encoding to use np.bytes_, similar to the previous segments.

As mentioned earlier, please verify compatibility with all components that consume this JSON data to ensure there are no issues caused by this change.


746-746: Verify compatibility impact of changing JSON encoding to np.bytes_.

This code segment in the write_metadata function also switches the JSON encoding to use np.bytes_, consistent with the previous changes.

As requested earlier, please thoroughly verify compatibility with all components that consume this JSON data to ensure there are no issues caused by this change in encoding.


Line range hint 1-1000: Changes look good, pending compatibility verification.

The code changes in this file are focused on transitioning from using np.string_ to np.bytes_ for JSON serialization across multiple functions, as mentioned in the summary.

The changes are straightforward and consistently applied. No other issues are observed.

However, as highlighted in the previous comments, it's crucial to verify compatibility with all components that consume this JSON data serialized with np.bytes_ encoding. Please thoroughly test and confirm there are no issues caused by this change.

If compatibility is confirmed, these changes can be approved.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@lochhh lochhh marked this pull request as ready for review September 10, 2024 19:49
Copy link

codecov bot commented Sep 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.01%. Comparing base (e002927) to head (bd9293d).
Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #115   +/-   ##
=======================================
  Coverage   96.01%   96.01%           
=======================================
  Files          17       17           
  Lines        2035     2035           
=======================================
  Hits         1954     1954           
  Misses         81       81           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@talmo talmo left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks @lochhh!!

For future reference: I also cloned this and tested it with numpy==1.26.4 and the changes here still pass all the tests, so we should be safe in terms of backwards compatibility.

Now let's just hope that all of our deps are happy with numpy 2 as well 😄

@talmo talmo merged commit 43ccaaa into talmolab:main Sep 11, 2024
9 checks passed
@lochhh lochhh deleted the lochhh/support-numpy2 branch September 12, 2024 15:08
@coderabbitai coderabbitai bot mentioned this pull request Sep 28, 2024
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.

Support for NumPy > 2.0.0
2 participants