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

Fix params #2173

Merged
merged 7 commits into from
Dec 3, 2024
Merged

Fix params #2173

merged 7 commits into from
Dec 3, 2024

Conversation

ternaus
Copy link
Collaborator

@ternaus ternaus commented Dec 3, 2024

Summary by Sourcery

Refactor the codebase to improve readability and maintainability by reordering transformations, breaking down long lines, and updating import statements. Fix validation logic for normalization parameters. Enhance test coverage by adding new test cases for auto_contrast and updating existing tests. Update pre-commit configuration to use the latest tool versions.

Bug Fixes:

  • Fix the validation logic for normalization parameters to ensure correct error handling when parameters are missing.

Enhancements:

  • Reorder and update the list of transformations in the transforms module to include new transformations and remove deprecated ones.
  • Refactor the code to improve readability by breaking down long lines and adding line breaks for better formatting.

Tests:

  • Add new test cases to verify the functionality of the auto_contrast function, ensuring it handles various image types correctly.
  • Update existing tests to improve coverage and ensure compatibility with the refactored code.

Chores:

  • Update the pre-commit configuration to use the latest versions of tools like Ruff and markdownlint.
  • Reorganize import statements across multiple modules to follow a consistent order.

Copy link
Contributor

sourcery-ai bot commented Dec 3, 2024

Reviewer's Guide by Sourcery

The changes focus on improving code organization and readability through parameter validation refinement, function signature formatting, and alphabetical sorting of imports and exports. The main implementation changes include fixing parameter validation logic in transforms, updating pre-commit hooks, and reorganizing transformation lists.

Class diagram for updated parameter validation

classDiagram
    class ImageCompression {
        +tuple[int, int] quality_range
        +validate_ranges() Self
        +apply(np.ndarray img, int quality, Literal[".jpg", ".webp"] image_type, **params: Any) np.ndarray
    }
    class RandomSnow {
        +tuple[float, float] snow_point_range
        +validate_ranges() Self
        +apply(np.ndarray img, float snow_point, float brightness_coeff, np.ndarray snow_texture, np.ndarray sparkle_mask) np.ndarray
    }
    class Posterize {
        +int | tuple[int, int] | list[tuple[int, int]] num_bits
        +validate_num_bits(Any num_bits) tuple[int, int] | list[tuple[int, int]]
        +apply(np.ndarray img, int num_bits, **params: Any) np.ndarray
    }
Loading

Class diagram for updated noise parameters

classDiagram
    class AdditiveNoise {
        +Literal["uniform", "gaussian", "laplace", "beta"] noise_type
        +Literal["constant", "per_pixel", "shared"] spatial_mode
        +dict[str, Any] | None noise_params
        +apply(np.ndarray img, np.ndarray noise_map, **params: Any) np.ndarray
    }
    class UniformParams {
        +list[Sequence[float]] ranges
        +validate_ranges(list[Sequence[float]] v) list[tuple[float, float]]
    }
    class GaussianParams {
        +Sequence[float] mean_range
        +Sequence[float] std_range
    }
    class LaplaceParams {
        +Sequence[float] mean_range
        +Sequence[float] scale_range
    }
    class BetaParams {
        +Sequence[float] alpha_range
        +Sequence[float] beta_range
        +Sequence[float] scale_range
    }
Loading

File-Level Changes

Change Details Files
Refactor function signatures for better readability
  • Split long function signatures into multiple lines
  • Add consistent indentation for multi-line parameters
  • Improve parameter alignment in complex function definitions
albumentations/augmentations/transforms.py
albumentations/augmentations/functional.py
Fix parameter validation logic
  • Fix condition in normalization validation to properly check max_pixel_value
  • Improve error messages for parameter validation
  • Update validation logic for snow_point_range and fog_coef_range
  • Fix validation for quality_range in ImageCompression
albumentations/augmentations/transforms.py
Reorganize transformation lists and imports
  • Sort transformation lists alphabetically for better organization
  • Reorder import statements alphabetically
  • Update all lists to be alphabetically sorted
albumentations/augmentations/transforms.py
albumentations/augmentations/functional.py
albumentations/augmentations/geometric/transforms.py
albumentations/core/composition.py
Update build configuration and dependencies
  • Update ruff pre-commit hook to v0.8.1
  • Update markdownlint-cli to v0.43.0
  • Modify ruff linting rules in pyproject.toml
.pre-commit-config.yaml
pyproject.toml

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

@ternaus ternaus marked this pull request as draft December 3, 2024 00:16
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.

Hey @ternaus - I've reviewed your changes - here's some feedback:

Overall Comments:

  • This PR contains breaking changes: 1) Removed Poisson noise option from noise transforms 2) Modified Posterize transform to no longer accept 0 bits. Please document these changes in the changelog.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟡 Testing: 2 issues 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.

albumentations/augmentations/functional.py Show resolved Hide resolved
tests/test_serialization.py Show resolved Hide resolved
tests/aug_definitions.py Show resolved Hide resolved
tests/test_serialization.py Show resolved Hide resolved
Copy link

codecov bot commented Dec 3, 2024

Codecov Report

Attention: Patch coverage is 85.47718% with 35 lines in your changes missing coverage. Please review.

Project coverage is 89.80%. Comparing base (b1a79c2) to head (9291e0d).
Report is 298 commits behind head on main.

Files with missing lines Patch % Lines
albumentations/augmentations/transforms.py 86.25% 22 Missing ⚠️
albumentations/augmentations/functional.py 82.66% 13 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##           main    #2173       +/-   ##
=========================================
+ Coverage      0   89.80%   +89.80%     
=========================================
  Files         0       47       +47     
  Lines         0     8478     +8478     
=========================================
+ Hits          0     7614     +7614     
- Misses        0      864      +864     

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

@ternaus ternaus marked this pull request as ready for review December 3, 2024 03:40
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.

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

Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟡 Testing: 3 issues 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.

albumentations/augmentations/functional.py Show resolved Hide resolved
tests/test_serialization.py Show resolved Hide resolved
tests/test_serialization.py Show resolved Hide resolved
tests/functional/test_functional.py Show resolved Hide resolved
tests/functional/test_functional.py Show resolved Hide resolved
tests/functional/test_functional.py Show resolved Hide resolved
tests/functional/test_functional.py Show resolved Hide resolved
tests/functional/test_functional.py Show resolved Hide resolved
tests/functional/test_functional.py Show resolved Hide resolved
tests/test_serialization.py Show resolved Hide resolved
@ternaus ternaus merged commit db7204a into main Dec 3, 2024
16 checks passed
@ternaus ternaus deleted the fix_params branch December 3, 2024 03:45
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.

1 participant