Skip to content

fix: Fix preparing data for mahotas.haralick to avoid overflow problem#1150

Merged
Czaki merged 7 commits intodevelopfrom
fix_segfault_mahotas_numpy
Jul 16, 2024
Merged

fix: Fix preparing data for mahotas.haralick to avoid overflow problem#1150
Czaki merged 7 commits intodevelopfrom
fix_segfault_mahotas_numpy

Conversation

@Czaki
Copy link
Collaborator

@Czaki Czaki commented Jul 16, 2024

Workaround for luispedro/mahotas#150

Summary by CodeRabbit

  • Bug Fixes

    • Improved image rescaling logic to enhance visual representation accuracy.
  • Tests

    • Reordered test items for better organization and efficiency based on file paths.

@Czaki Czaki added this to the 0.15.4 milestone Jul 16, 2024
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jul 16, 2024

🧙 Sourcery has finished reviewing your pull request!


Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • Continue your discussion with Sourcery by replying directly to review comments.
  • You can change your review settings at any time by accessing your dashboard:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 16, 2024

Walkthrough

The changes primarily focus on modifying the _rescale_image function in measurement_calculation.py to alter the rescaling calculation. Additionally, updates to pytest_collection_modifyitems in conftest.py reorders test items based on file paths to separate batch tests from non-batch tests. These changes aim to enhance the accuracy of image rescaling and improve the organization of test executions.

Changes

File Path Change Summary
package/PartSegCore/analysis/measurement_calculation.py Adjusted the _rescale_image function to change the rescaling divisor from 255 to 254, impacting the visual representation of processed images.
package/tests/conftest.py Updated the pytest_collection_modifyitems function to reorder test items based on file paths, separating batch and non-batch tests.

Poem

In the code where pixels dance,
A tiny change, a slight advance,
From 255 to 254,
Images rescaled, just a bit more.
Tests now sorted, batch and free,
A clearer path for code to see.
A bunny's work, hop and cheer,
For better code, throughout the year!


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

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

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.

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.

We've reviewed this pull request using the Sourcery rules engine. If you would also like our AI-powered code review then let us know.

@Czaki Czaki changed the title fix: rescale to range 0-254 instead of 0-255 for mahotas fix: Rescale to range 0-254 instead of 0-255 for mahotas Jul 16, 2024
@Czaki Czaki changed the title fix: Rescale to range 0-254 instead of 0-255 for mahotas fix: Rescale to range 0-254 instead of 0-255 for mahotas Jul 16, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1c8ce01 and d37c400.

Files selected for processing (2)
  • package/PartSegCore/analysis/measurement_calculation.py (1 hunks)
  • package/tests/conftest.py (1 hunks)
Additional comments not posted (2)
package/tests/conftest.py (1)

272-274: Review of test item reordering logic

The logic to separate and reorder test items based on the presence of "test_analysis_batch" in the file path appears to be correct. However, it's important to ensure that this reordering does not inadvertently affect dependencies between tests or the overall test suite's execution order.

Verification successful

Reordering of tests appears safe

The logic to separate and reorder test items based on the presence of "test_analysis_batch" in the file path appears to be correct. No direct dependencies on test order were found, and the use of fixtures does not indicate any explicit ordering constraints. Therefore, the reordering should not affect the overall test suite's execution.

  • No instances of pytest.mark.dependency, pytest.mark.order, pytest.mark.tryfirst, or pytest.mark.trylast were found.
  • Several instances of pytest.mark.usefixtures were found, but they do not impose explicit order dependencies.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any test dependencies that might be affected by the reordering.

# Test: Search for test dependencies. Expect: No direct dependencies on test order.
rg --type python -A 5 $'pytest.mark.dependency'

Length of output: 77


Script:

#!/bin/bash
# Description: Check for any test dependencies that might be affected by the reordering.

# Test: Search for test dependencies. Expect: No direct dependencies on test order.
rg --glob '*.py' -A 5 $'pytest.mark.dependency'

Length of output: 46


Script:

#!/bin/bash
# Description: Check for other potential test dependencies or ordering constraints.

# Test: Search for other potential dependencies or ordering constraints. Expect: No direct dependencies on test order.
rg --glob '*.py' -A 5 $'pytest.mark.order'
rg --glob '*.py' -A 5 $'pytest.mark.usefixtures'
rg --glob '*.py' -A 5 $'pytest.mark.tryfirst'
rg --glob '*.py' -A 5 $'pytest.mark.trylast'

Length of output: 14159

package/PartSegCore/analysis/measurement_calculation.py (1)

1538-1538: Review of rescaling function modification

The change from a divisor of 255 to 254 in the _rescale_image function is implemented correctly. However, it's crucial to verify that this change does not affect other functionalities that depend on the output of this function.

@Czaki Czaki changed the title fix: Rescale to range 0-254 instead of 0-255 for mahotas fix: Fix prepare data for mahotas.haralick to avoid overflow problem Jul 16, 2024
@codecov
Copy link

codecov bot commented Jul 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.02%. Comparing base (fb00b42) to head (5a030fc).
Report is 53 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1150      +/-   ##
===========================================
- Coverage    93.04%   93.02%   -0.02%     
===========================================
  Files          207      207              
  Lines        32700    32705       +5     
===========================================
  Hits         30425    30425              
- Misses        2275     2280       +5     

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

@Czaki Czaki added the skip check PR title skip spellcheking PR title label Jul 16, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d37c400 and 0297f33.

Files selected for processing (1)
  • package/PartSegCore/analysis/measurement_calculation.py (1 hunks)
Additional context used
GitHub Check: codecov/patch
package/PartSegCore/analysis/measurement_calculation.py

[warning] 1537-1537: package/PartSegCore/analysis/measurement_calculation.py#L1537
Added line #L1537 was not covered by tests

Additional comments not posted (1)
package/PartSegCore/analysis/measurement_calculation.py (1)

1536-1540: Adjustment in _rescale_image function to prevent overflow

The change from 255 to 254 as a divisor in the rescaling formula is intended to prevent overflow issues. This is a sensible change given the context of the problem described in the PR. However, ensure that this change is reflected in all relevant parts of the application to maintain consistency.

Additionally, consider the impact this change might have on the visual representation of images. It would be beneficial to verify this through visual inspections or additional tests.

Tools
GitHub Check: codecov/patch

[warning] 1537-1537: package/PartSegCore/analysis/measurement_calculation.py#L1537
Added line #L1537 was not covered by tests

if data.dtype == np.uint8:
return data
if isinstance(data.dtype, np.integer) and data.min() >= 0 and data.max() < 255:
return data.astype(np.uint8)
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing test coverage for new line in _rescale_image

The static analysis tool flagged that the newly added line #1537 is not covered by tests. It's crucial to add unit tests for this change to ensure that the new behavior works as expected and does not introduce any regressions.

+ # Add unit tests to cover the new behavior in `_rescale_image`

Committable suggestion was skipped due to low confidence.

Tools
GitHub Check: codecov/patch

[warning] 1537-1537: package/PartSegCore/analysis/measurement_calculation.py#L1537
Added line #L1537 was not covered by tests

@Czaki
Copy link
Collaborator Author

Czaki commented Jul 16, 2024

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 16, 2024

Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0297f33 and 0f71824.

Files selected for processing (1)
  • package/PartSegCore/analysis/measurement_calculation.py (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • package/PartSegCore/analysis/measurement_calculation.py

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0f71824 and e2fd214.

Files selected for processing (1)
  • package/tests/conftest.py (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • package/tests/conftest.py

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e2fd214 and fbf3eea.

Files selected for processing (1)
  • package/tests/conftest.py (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • package/tests/conftest.py

@sonarqubecloud
Copy link

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between fbf3eea and 5a030fc.

Files selected for processing (1)
  • package/tests/conftest.py (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • package/tests/conftest.py

@Czaki Czaki changed the title fix: Fix prepare data for mahotas.haralick to avoid overflow problem fix: Fix preparing data for mahotas.haralick to avoid overflow problem Jul 16, 2024
@Czaki Czaki merged commit e734ebe into develop Jul 16, 2024
@Czaki Czaki deleted the fix_segfault_mahotas_numpy branch July 16, 2024 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip check PR title skip spellcheking PR title

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments