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

Homogenize return type of Lattice.get_points_in_sphere to always be np.array(s) #3797

Merged
merged 2 commits into from
May 1, 2024

Conversation

janosh
Copy link
Member

@janosh janosh commented May 1, 2024

closes #3794

@janosh janosh added fix Bug fix PRs core Pymatgen core labels May 1, 2024
@janosh janosh requested review from shyuep and mkhorton as code owners May 1, 2024 17:06
Copy link

coderabbitai bot commented May 1, 2024

Walkthrough

The updates to the pymatgen codebase focus on refining the return types of the get_points_in_sphere() method in the Lattice module to ensure consistency, especially in scenarios where no points are found within a specified radius. This adjustment aligns the method's behavior with user expectations, preventing errors related to unexpected return types.

Changes

File Path Change Summary
.../core/lattice.py Standardized return types in get_points_in_sphere() to numpy arrays for empty results.
.../core/test_lattice.py Updated variable names and added checks for consistent return types in test_get_points_in_sphere().

Assessment against linked issues

Objective Addressed Explanation
Ensure consistent return types in get_points_in_sphere() [#3794]
Prevent type errors due to unexpected empty return types [#3794]
Align method behavior with user expectations [#3794]

Recent Review Details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits Files that changed from the base of the PR and between 9a3f714 and 650ee0c.
Files selected for processing (2)
  • pymatgen/core/lattice.py (2 hunks)
  • tests/core/test_lattice.py (1 hunks)
Files skipped from review due to trivial changes (1)
  • pymatgen/core/lattice.py
Additional comments not posted (4)
tests/core/test_lattice.py (4)

355-356: Ensure that the fractional coordinates are correctly calculated from the points.


359-366: The test case for get_points_in_sphere correctly checks for the number of neighbors and their distances. However, ensure that the method now consistently returns numpy arrays as per the PR's objective.


369-372: The test case for the more complex scenario using zip_results=True is well-implemented. It checks the tuple's length and the number of coordinates, distances, indices, and supercell information.


376-388: This test case effectively checks the consistent return type when no points are found in the sphere, addressing the issue #3794 directly. The use of isinstance and checking the types within the tuple to ensure they are all numpy arrays is a good practice.


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.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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.

@janosh janosh enabled auto-merge (squash) May 1, 2024 17:07
@janosh janosh merged commit 1369689 into master May 1, 2024
22 checks passed
@janosh janosh deleted the fix-gh-3794 branch May 1, 2024 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Pymatgen core fix Bug fix PRs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

get_points_in_sphere() has inconsistent return types
1 participant