Skip to content

Commit

Permalink
Updated ruff and cleaned rules (#1884)
Browse files Browse the repository at this point in the history
  • Loading branch information
ternaus authored Aug 15, 2024
1 parent bee3a75 commit 5a2abd4
Show file tree
Hide file tree
Showing 24 changed files with 62 additions and 108 deletions.
1 change: 0 additions & 1 deletion albumentations/augmentations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@
from .mixing.transforms import *
from .text.functional import *
from .text.transforms import *

from .transforms import *
from .utils import *
2 changes: 1 addition & 1 deletion albumentations/augmentations/blur/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import random
import warnings
from typing import Any, Literal, cast, Tuple
from typing import Any, Literal, Tuple, cast

import cv2
import numpy as np
Expand Down
4 changes: 1 addition & 3 deletions albumentations/augmentations/crops/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
from typing import Sequence, cast

import cv2
import numpy as np
from albucore.utils import maybe_process_in_chunks, preserve_channel_dim

from albumentations.augmentations.geometric import functional as fgeometric
from albumentations.core.bbox_utils import denormalize_bbox, normalize_bbox
from albumentations.core.types import BoxInternalType, ColorType, KeypointInternalType


import numpy as np

__all__ = [
"get_crop_coords",
"crop_bbox_by_coords",
Expand Down
1 change: 0 additions & 1 deletion albumentations/augmentations/crops/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from pydantic import AfterValidator, Field, field_validator, model_validator
from typing_extensions import Annotated, Self


from albumentations.augmentations.geometric import functional as fgeometric
from albumentations.core.bbox_utils import union_of_bboxes
from albumentations.core.pydantic import (
Expand Down
9 changes: 3 additions & 6 deletions albumentations/augmentations/domain_adaptation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,24 @@

import random
from typing import Any, Callable, Literal, Sequence, Tuple, cast
from typing_extensions import Annotated

import cv2
import numpy as np
from albucore.utils import clip, is_grayscale_image, is_multispectral_image
from pydantic import AfterValidator, field_validator
from typing_extensions import Annotated

from albumentations.augmentations import functional as fmain
from albumentations.augmentations.domain_adaptation_functional import (
adapt_pixel_distribution,
apply_histogram,
fourier_domain_adaptation,
)
from albumentations.augmentations.utils import read_rgb_image
from albumentations.core.transforms_interface import BaseTransformInitSchema, ImageOnlyTransform
from albumentations.augmentations import functional as fmain


from albumentations.core.pydantic import NonNegativeFloatRangeType, check_01, nondecreasing
from albumentations.core.transforms_interface import BaseTransformInitSchema, ImageOnlyTransform
from albumentations.core.types import ScaleFloatType


__all__ = [
"HistogramMatching",
"FDA",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
from skimage.exposure import match_histograms
from typing_extensions import Protocol

import albumentations.augmentations.functional as fmain
from albumentations.augmentations.functional import center
from albumentations.core.types import MONO_CHANNEL_DIMENSIONS, NUM_MULTI_CHANNEL_DIMENSIONS
import albumentations.augmentations.functional as fmain

__all__ = [
"fourier_domain_adaptation",
Expand Down
13 changes: 5 additions & 8 deletions albumentations/augmentations/dropout/channel_dropout.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,17 @@
import random
from typing import Any, Mapping

from typing_extensions import Annotated

from albucore import get_num_channels
from albumentations.core.transforms_interface import BaseTransformInitSchema, ImageOnlyTransform

from .functional import channel_dropout


import numpy as np
from albucore import get_num_channels
from pydantic import Field
from typing_extensions import Annotated

from albumentations.core.pydantic import OnePlusIntRangeType
from albumentations.core.transforms_interface import BaseTransformInitSchema, ImageOnlyTransform
from albumentations.core.types import ColorType

from .functional import channel_dropout

__all__ = ["ChannelDropout"]

MIN_DROPOUT_CHANNEL_LIST_LENGTH = 2
Expand Down
7 changes: 2 additions & 5 deletions albumentations/augmentations/dropout/coarse_dropout.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,17 @@
from typing import Any, Callable, Iterable, Sequence
from warnings import warn

import numpy as np
from pydantic import AfterValidator, Field, model_validator
from typing_extensions import Annotated, Literal, Self

from albumentations.core.pydantic import check_1plus, nondecreasing
from albumentations.core.transforms_interface import BaseTransformInitSchema, DualTransform
from albumentations.core.types import ColorType, KeypointType, NumericType, ScalarType, Targets
from albumentations.random_utils import randint, uniform

from .functional import cutout, keypoint_in_hole


import numpy as np

from albumentations.core.pydantic import check_1plus, nondecreasing

__all__ = ["CoarseDropout"]


Expand Down
7 changes: 2 additions & 5 deletions albumentations/augmentations/dropout/grid_dropout.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,16 @@
from typing import Any, Iterable, Sequence
from warnings import warn

import numpy as np
from pydantic import AfterValidator, Field, model_validator
from typing_extensions import Annotated, Self

from albumentations.core.pydantic import check_0plus, check_1plus, nondecreasing
from albumentations.core.transforms_interface import BaseTransformInitSchema, DualTransform
from albumentations.core.types import MIN_UNIT_SIZE, PAIR, ColorType, Targets

from . import functional as fdropout


import numpy as np

from albumentations.core.pydantic import check_0plus, check_1plus, nondecreasing

__all__ = ["GridDropout"]


Expand Down
4 changes: 1 addition & 3 deletions albumentations/augmentations/dropout/mask_dropout.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@
from skimage.measure import label
from typing_extensions import Literal

from albumentations.core.pydantic import OnePlusIntRangeType
from albumentations.core.transforms_interface import BaseTransformInitSchema, DualTransform
from albumentations.core.types import ScalarType, ScaleIntType, Targets


from albumentations.core.pydantic import OnePlusIntRangeType

__all__ = ["MaskDropout"]


Expand Down
7 changes: 2 additions & 5 deletions albumentations/augmentations/dropout/xy_masking.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,16 @@
import random
from typing import Any, Callable, Sequence, Tuple, cast

import numpy as np
from pydantic import Field, model_validator
from typing_extensions import Self

from albumentations.core.pydantic import NonNegativeIntRangeType
from albumentations.core.transforms_interface import BaseTransformInitSchema, DualTransform
from albumentations.core.types import ColorType, KeypointType, ScaleIntType, Targets

from .functional import cutout, keypoint_in_hole


import numpy as np

from albumentations.core.pydantic import NonNegativeIntRangeType

__all__ = ["XYMasking"]


Expand Down
2 changes: 1 addition & 1 deletion albumentations/augmentations/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
MAX_VALUES_BY_DTYPE,
clip,
clipped,
get_num_channels,
is_grayscale_image,
is_rgb_image,
maybe_process_in_chunks,
preserve_channel_dim,
get_num_channels,
)
from typing_extensions import Literal

Expand Down
2 changes: 1 addition & 1 deletion albumentations/augmentations/geometric/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import cv2
import numpy as np
import skimage.transform
from albucore.utils import clipped, maybe_process_in_chunks, preserve_channel_dim, get_num_channels
from albucore.utils import clipped, get_num_channels, maybe_process_in_chunks, preserve_channel_dim

from albumentations import random_utils
from albumentations.augmentations.functional import center
Expand Down
7 changes: 2 additions & 5 deletions albumentations/augmentations/geometric/resize.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
from typing import Any, List, Sequence, Tuple, Union, cast

import cv2
import numpy as np
from pydantic import Field, ValidationInfo, field_validator

from albumentations.core.pydantic import InterpolationType, ProbabilityType
from albumentations.core.transforms_interface import BaseTransformInitSchema, DualTransform
from albumentations.core.types import (
BoxInternalType,
Expand All @@ -17,11 +19,6 @@

from . import functional as fgeometric


import numpy as np

from albumentations.core.pydantic import InterpolationType, ProbabilityType

__all__ = ["RandomScale", "LongestMaxSize", "SmallestMaxSize", "Resize"]


Expand Down
4 changes: 1 addition & 3 deletions albumentations/augmentations/geometric/rotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from albumentations.augmentations.crops import functional as fcrops
from albumentations.augmentations.functional import center
from albumentations.core.pydantic import BorderModeType, InterpolationType, SymmetricRangeType
from albumentations.core.transforms_interface import BaseTransformInitSchema, DualTransform
from albumentations.core.types import (
BoxInternalType,
Expand All @@ -22,9 +23,6 @@

from . import functional as fgeometric


from albumentations.core.pydantic import BorderModeType, InterpolationType, SymmetricRangeType

__all__ = ["Rotate", "RandomRotate90", "SafeRotate"]

SMALL_NUMBER = 1e-10
Expand Down
18 changes: 8 additions & 10 deletions albumentations/augmentations/geometric/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@
from albumentations.augmentations.functional import bbox_from_mask, center, center_bbox
from albumentations.augmentations.utils import check_range
from albumentations.core.bbox_utils import denormalize_bboxes, normalize_bboxes
from albumentations.core.pydantic import (
BorderModeType,
InterpolationType,
NonNegativeFloatRangeType,
ProbabilityType,
SymmetricRangeType,
check_1plus,
)
from albumentations.core.transforms_interface import BaseTransformInitSchema, DualTransform
from albumentations.core.types import (
BIG_INTEGER,
Expand All @@ -38,16 +46,6 @@

from . import functional as fgeometric


from albumentations.core.pydantic import (
BorderModeType,
InterpolationType,
NonNegativeFloatRangeType,
ProbabilityType,
SymmetricRangeType,
check_1plus,
)

__all__ = [
"ShiftScaleRotate",
"ElasticTransform",
Expand Down
3 changes: 1 addition & 2 deletions albumentations/augmentations/mixing/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import numpy as np
from albucore.functions import add_weighted
from albucore.utils import is_grayscale_image
from pydantic import Field
from typing_extensions import Annotated

from albumentations.augmentations.mixing import functional as fmixing
Expand All @@ -17,8 +18,6 @@
from albumentations.core.types import LENGTH_RAW_BBOX, BoxType, KeypointType, ReferenceImage, SizeType, Targets
from albumentations.random_utils import beta

from pydantic import Field

__all__ = ["MixUp", "OverlayElements"]


Expand Down
2 changes: 1 addition & 1 deletion albumentations/augmentations/text/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from .transforms import *
from .functional import *
from .transforms import *
11 changes: 5 additions & 6 deletions albumentations/augmentations/text/functional.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
from __future__ import annotations

import random
from typing import TYPE_CHECKING, Any, Sequence
from albucore.utils import preserve_channel_dim, MONO_CHANNEL_DIMENSIONS, NUM_MULTI_CHANNEL_DIMENSIONS, NUM_RGB_CHANNELS
import cv2


import cv2
import numpy as np

from albumentations.core.types import PAIR
from albucore.utils import MONO_CHANNEL_DIMENSIONS, NUM_MULTI_CHANNEL_DIMENSIONS, NUM_RGB_CHANNELS, preserve_channel_dim

import albumentations.augmentations.functional as fmain
from albumentations.core.types import PAIR

# Importing wordnet and other dependencies only for type checking
if TYPE_CHECKING:
Expand Down Expand Up @@ -89,7 +88,7 @@ def draw_text_on_pil_image(pil_image: Image, metadata_list: list[dict[str, Any]]
def draw_text_on_multi_channel_image(image: np.ndarray, metadata_list: list[dict[str, Any]]) -> np.ndarray:
"""Draw text on a multi-channel image with more than three channels."""
try:
from PIL import ImageDraw, Image
from PIL import Image, ImageDraw
except ImportError:
raise ImportError("Pillow is not installed") from ImportError

Expand Down
9 changes: 4 additions & 5 deletions albumentations/augmentations/text/transforms.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
from __future__ import annotations

from typing import Any, Literal
import random
import re
from typing import Any, Literal

import numpy as np
from PIL import ImageFont
from pydantic import AfterValidator, model_validator

import albumentations.augmentations.text.functional as ftext
import re
from typing_extensions import Annotated, Self

import albumentations.augmentations.text.functional as ftext
from albumentations.core.bbox_utils import check_bbox, denormalize_bbox
from albumentations.core.pydantic import check_01, nondecreasing
from albumentations.core.transforms_interface import BaseTransformInitSchema, ImageOnlyTransform
from albumentations.core.types import BoxType, ColorType


__all__ = ["TextImage"]


Expand Down
Loading

0 comments on commit 5a2abd4

Please sign in to comment.