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

feat: Add future annotations and update version to 1.4.4 #124

Merged
merged 4 commits into from
Oct 23, 2024

Conversation

Anselmoo
Copy link
Owner

@Anselmoo Anselmoo commented Oct 23, 2024

Introduce future annotations for improved type hinting across the codebase. Update the package version to 1.4.4 and add new dependencies. Enhance documentation for dependencies.

Summary by Sourcery

Introduce future annotations for improved type hinting and refactor the codebase to use a new LigandFieldTheory parent class. Update the package version to 1.4.4 and enhance documentation for dependencies.

New Features:

  • Introduce future annotations for improved type hinting across the codebase.

Enhancements:

  • Refactor classes to inherit from a new LigandFieldTheory parent class, improving code structure and reusability.
  • Add type hints and annotations to various methods for better code clarity and type safety.

Documentation:

  • Enhance documentation for dependencies and update docstrings for improved clarity.

- Updated package version in __init__.py
- Added future annotations import in tools.py and cmd.py
- Refactored calculation method signature in batch.py
- Added new dependencies in pyproject.toml and updated poetry.lock
Copy link

semanticdiff-com bot commented Oct 23, 2024

Review changes with SemanticDiff.

Analyzed 8 of 10 files.

Overall, the semantic diff is 30% smaller than the GitHub diff.

Filename Status
poetry.lock Unsupported file format
pyproject.toml Unsupported file format
✔️ tanabesugano/__init__.py 63.49% smaller
✔️ tanabesugano/batch.py 77.53% smaller
✔️ tanabesugano/cmd.py 55.53% smaller
✔️ tanabesugano/matrices.py 25.71% smaller
✔️ tanabesugano/tools.py 56.43% smaller
✔️ tanabesugano/test/test_batch.py Analyzed
✔️ tanabesugano/test/test_front.py 1.64% smaller
✔️ tanabesugano/test/test_num.py Analyzed

Copy link

sourcery-ai bot commented Oct 23, 2024

Reviewer's Guide by Sourcery

This pull request introduces future annotations for improved type hinting, updates the package version to 1.4.4, and enhances the codebase with better typing and code structure. The changes primarily focus on improving type annotations, refactoring class structures, and updating method signatures across multiple files in the tanabesugano package.

Class diagram for LigandFieldTheory and its subclasses

classDiagram
    class LigandFieldTheory {
        +Float64Array eigensolver(Float64Array matrix)
        +Dict~str, Float64Array~ solver()
    }
    class d2 {
        +Float64Array A_1_1_states()
        +Float64Array E_1_states()
        +Float64Array T_1_2_states()
        +Float64Array T_3_1_states()
    }
    class d3 {
        +Float64Array T_2_2_states()
        +Float64Array T_2_1_states()
        +Float64Array E_2_states()
        +Float64Array T_4_1_states()
    }
    class d4 {
        +Float64Array T_3_1_states()
        +Float64Array T_1_2_states()
        +Float64Array A_1_1_states()
        +Float64Array E_1_1_states()
        +Float64Array T_3_2_states()
        +Float64Array T_1_1_states()
        +Float64Array E_3_1_states()
        +Float64Array A_3_2_states()
        +Float64Array A_1_2_states()
    }
    class d5 {
        +Float64Array T_2_2_states()
        +Float64Array T_2_1_states()
        +Float64Array E_2_states()
        +Float64Array A_2_1_states()
        +Float64Array A_2_2_states()
        +Float64Array T_4_1_states()
        +Float64Array T_4_2_states()
        +Float64Array E_4_states()
    }
    class d6 {
        +Float64Array T_3_1_states()
        +Float64Array T_1_2_states()
        +Float64Array A_1_1_states()
        +Float64Array E_1_1_states()
        +Float64Array T_3_2_states()
        +Float64Array T_1_1_states()
        +Float64Array E_3_1_states()
        +Float64Array A_3_2_states()
        +Float64Array A_1_2_states()
    }
    class d7 {
        +Float64Array T_2_2_states()
        +Float64Array T_2_1_states()
        +Float64Array E_2_states()
        +Float64Array T_4_1_states()
    }
    class d8 {
        +Float64Array A_1_1_states()
        +Float64Array E_1_states()
        +Float64Array T_1_2_states()
        +Float64Array T_3_1_states()
    }
    LigandFieldTheory <|-- d2
    LigandFieldTheory <|-- d3
    LigandFieldTheory <|-- d4
    LigandFieldTheory <|-- d5
    LigandFieldTheory <|-- d6
    LigandFieldTheory <|-- d7
    LigandFieldTheory <|-- d8
Loading

Class diagram for CMDmain

classDiagram
    class CMDmain {
        +float Dq
        +float B
        +float C
        +int nroot
        +DataFrame df
        +void plot()
        +void label_plot(str arg0, str arg1, str arg2)
        +void savetxt()
        +void calculation()
        +dict subsplit_states(dict states)
        +void ci_cut(float dq_ci)
        +void ts_print(dict states, float dq_ci)
        +void interactive_plot()
    }
Loading

File-Level Changes

Change Details Files
Introduce future annotations and update type hints
  • Add 'from future import annotations' to multiple files
  • Update type hints for function parameters and return values
  • Introduce TypeAlias for Float64Array
  • Add type hints to class attributes and method parameters
tanabesugano/matrices.py
tanabesugano/cmd.py
tanabesugano/batch.py
tanabesugano/tools.py
tanabesugano/__init__.py
Refactor class structures and improve inheritance
  • Create a parent class LigandFieldTheory for common functionality
  • Update child classes to inherit from LigandFieldTheory
  • Implement abstract method solver() in LigandFieldTheory
  • Refactor init methods to use super().init()
tanabesugano/matrices.py
Enhance documentation and code readability
  • Update docstrings to follow a consistent format
  • Add more descriptive comments for complex calculations
  • Improve method and variable naming for clarity
tanabesugano/matrices.py
tanabesugano/cmd.py
tanabesugano/batch.py
Update package version and dependencies
  • Increment package version to 1.4.4
  • Update import statements to use absolute imports
tanabesugano/__init__.py
tanabesugano/matrices.py
tanabesugano/cmd.py
tanabesugano/batch.py
Improve error handling and input validation
  • Add more specific error messages for invalid inputs
  • Use ValueError for invalid d_count instead of KeyError
tanabesugano/matrices.py
tanabesugano/batch.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

phylum-io bot commented Oct 23, 2024

Phylum OSS Supply Chain Risk Analysis - FAILED

This repository analyzes the risk of new dependencies. An
administrator of this repository has set requirements via Phylum policy.

If you see this comment, one or more dependencies have failed Phylum's risk analysis.

Package: ruff@0.7.0 failed.

ruff@0.7.0 contains obfuscated Python.

Risk Domain: Malicious Code
Risk Level: high

Reason: Obfuscated code

View this project in the Phylum UI

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @Anselmoo - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟢 Security: all looks good
  • 🟡 Testing: 1 issue found
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

"""
return eigh(matrix)[0]

def solver(self) -> Dict[str, Float64Array]:
Copy link

Choose a reason for hiding this comment

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

suggestion: Standardize solver method return type across all subclasses

Ensure that all subclasses of LigandFieldTheory implement the solver method with the same return type annotation. This will improve consistency and make the code more maintainable.

    def solver(self) -> Dict[str, np.ndarray]:

)
else:
raise ValueError("`d_count` must be in {2,3,4,5,6,7,8}")
msg = "The number of unpaired electrons should be between 2 and 8."
Copy link

Choose a reason for hiding this comment

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

suggestion: Improve error handling for invalid d_count values

Consider adding a check for d_count at the beginning of the method or in the init to fail fast and provide a clear error message. This will improve the user experience when invalid inputs are provided.

def __init__(self, d_count):
    if not 2 <= d_count <= 8:
        raise ValueError("The number of unpaired electrons should be between 2 and 8.")
    self.d_count = d_count

# Rest of the class implementation...

@@ -8,16 +10,16 @@ def state_check(x):
if x == 3:
states = matrices.d3(Dq=i).solver()
return len(states)
Copy link

Choose a reason for hiding this comment

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

suggestion (testing): Consider adding more comprehensive tests for the state_check function

The current test only checks the number of states returned. It would be beneficial to add tests that verify the correctness of the states themselves, not just their count. Also, consider adding test cases for d2 and d8 configurations.

from __future__ import annotations
import numpy as np
from tanabesugano import matrices

def test_state_check():
    assert state_check(3) == 120
    assert state_check(2) == 45
    assert state_check(8) == 1001

    d3_states = matrices.d3(Dq=1000).solver()
    assert len(d3_states) == 120
    assert isinstance(d3_states[0], np.ndarray)
    assert d3_states[0].shape == (7,)

@Anselmoo Anselmoo merged commit 19b791d into master Oct 23, 2024
9 of 10 checks passed
@Anselmoo Anselmoo deleted the feature/matrices branch October 23, 2024 04:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant