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 CIReport class #1181

Merged
merged 2 commits into from
Feb 18, 2024
Merged

feat: ✨ add CIReport class #1181

merged 2 commits into from
Feb 18, 2024

Conversation

Anselmoo
Copy link
Owner

All PR-Submissions:


  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open
    Pull Requests for the same
    update/change?

New ✨✨ Feature-Submissions:


  • Does your submission pass tests?
  • Have you lint your code locally prior to submission? Fixed:
  • This PR is for a new feature, not a bug fix.

Changes to ⚙️ Core-Features:


  • Have you added an explanation of what your changes do and why you'd like
    us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully run tests with your changes locally?

@Anselmoo Anselmoo enabled auto-merge (squash) February 18, 2024 11:16
@github-actions github-actions bot added testing Improve testing & coverage maintenance Maintenance & Security dependencies Pull requests that update a dependency file python Pull requests that update Python code root labels Feb 18, 2024
@Anselmoo Anselmoo added enhancement New feature or request and removed testing Improve testing & coverage maintenance Maintenance & Security dependencies Pull requests that update a dependency file python Pull requests that update Python code root labels Feb 18, 2024
Copy link

Quality Gate Passed Quality Gate passed

Issues
2 New issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

Copy link
Contributor

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

PR Type: Enhancement

PR Summary: This pull request introduces the CIReport class, aimed at generating and presenting confidence interval reports for a given set of parameters. The class provides functionality to include or exclude offsets in the report, specify the number of digits for numerical values, and print the report as a table. Additionally, the PR includes updates to the PrintingResults class to support custom float formatting and integrates the new CIReport class into the existing codebase, replacing previous functionality with a more structured approach.

Decision: Comment

📝 Type: 'Enhancement' - not supported yet.
  • Sourcery currently only approves 'Typo fix' PRs.
✅ Issue addressed: this change correctly addresses the issue or implements the desired feature.
No details provided.
📝 Complexity: the changes are too large or complex for Sourcery to approve.
  • Unsupported files: the diff contains files that Sourcery does not currently support during reviews.

General suggestions:

  • Consider improving the clarity of method names within the CIReport class to enhance code readability. For instance, renaming convp to something more descriptive could make the code more accessible to new contributors or maintainers.
  • Explore the possibility of decoupling report generation from its presentation within the CIReport class. This separation of concerns could offer greater flexibility in how reports are generated and presented, potentially accommodating future requirements for different presentation formats or additional data processing before presentation.
  • Review the use of the __call__ method for generating the report. While this approach is intuitive, providing a more explicitly named method could improve code clarity and maintainability.
spectrafit/report.py: Consider simplifying the addition of the `CIReport` class by directly processing and printing confidence intervals within a single function to reduce complexity.

While the effort to modularize the code and introduce new functionalities is appreciated, the introduction of the CIReport class and its associated methods significantly increases the complexity of the codebase. This added complexity might not necessarily enhance the maintainability or readability of the code. Specifically, the new class and methods introduce additional layers of abstraction, increase the number of decision points, and add more parameters and logic that need to be understood and maintained.

A more streamlined approach could be to enhance the existing functionality without introducing a new class, focusing on simplifying the process of generating and printing the confidence interval report. Here's a suggested simplification that avoids the overhead of class management and method calls while retaining the flexibility of handling offsets and digit rounding:

def print_confidence_interval(ci, with_offset=True, ndigits=5):
    """
    Print the confidence intervals in a simplified format.

    Args:
        ci (Dict[str, List[Tuple[float, float]]]): The confidence intervals for the parameters.
        with_offset (bool, optional): Whether to include an offset in the report. Defaults to True.
        ndigits (int, optional): The number of digits to round the report values to. Defaults to 5.
    """
    df = pd.DataFrame()
    for name, intervals in ci.items():
        report = {}
        offset = 0.0
        if with_offset:
            offset = next((val for cval, val in intervals if abs(cval) < 1.0e-2), 0.0)
        for i, (cval, val) in enumerate(intervals):
            sval = val if cval < 1.0e-2 else val - offset
            bound_type = "LOWER" if i < len(intervals) / 2 else "UPPER"
            report[f"{cval * 100:.2f}% - {bound_type}"] = sval
        df[name] = pd.Series(report)
    print(df.round(ndigits).to_string())

This approach aims to reduce the overall complexity by directly processing and printing the confidence intervals within a single function, thus making the code easier to maintain and understand.

Thanks for using Sourcery. We offer it for free for open source projects and would be very grateful if you could help us grow. If you like it, would you consider sharing Sourcery on your favourite social media? ✨

Share Sourcery

Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

self.ndigits = ndigits
self.df = pd.DataFrame()

def convp(self, x: Tuple[float, float], bound_type: str) -> str:
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (llm): The method name convp is not immediately clear in its purpose. Consider renaming it to something more descriptive, such as format_confidence_interval, to improve code readability.

"""Convert the confidence interval to a string."""
return "BEST" if abs(x[0]) < 1.0e-2 else f"{x[0] * 100:.2f}% - {bound_type}"

def __call__(self) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (llm): Using the __call__ method to generate the report is an interesting choice. It makes the class instance callable, which can be intuitive for users familiar with the pattern. However, for clarity and future maintainability, consider adding a more explicitly named method, like generate, and have __call__ delegate to it. This approach enhances readability and makes the codebase more approachable for new developers or contributors.

Copy link

codecov bot commented Feb 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (574d29d) 100.00% compared to head (de54611) 100.00%.
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #1181   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           44        44           
  Lines         4431      4462   +31     
=========================================
+ Hits          4431      4462   +31     
Files Coverage Δ
spectrafit/report.py 100.00% <100.00%> (ø)
spectrafit/test/test_report.py 100.00% <100.00%> (ø)

@Anselmoo Anselmoo merged commit c8d0b27 into main Feb 18, 2024
46 checks passed
@Anselmoo Anselmoo deleted the feature/lint branch February 18, 2024 11:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant