Skip to content

Commit

Permalink
Sourcery fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladimir Iglovikov committed Dec 13, 2024
1 parent ea609b8 commit dff606c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 22 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ Spatial-level transforms will simultaneously change both an input image as well

### 3D transforms

3D transforms operate on volumetric data and can modify both the input volume and associated 3D mask
3D transforms operate on volumetric data and can modify both the input volume and associated 3D mask.

| Transform | Image | Mask |
| -------------------------------------------------------------------------- | :---: | :--: |
Expand Down
2 changes: 1 addition & 1 deletion albumentations/core/composition.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ def _check_masks_data(data_name: str, data: Any) -> tuple[int, int]:
raise ValueError(f"{data_name} cannot be empty")

Check warning on line 561 in albumentations/core/composition.py

View check run for this annotation

Codecov / codecov/patch

albumentations/core/composition.py#L561

Added line #L561 was not covered by tests
if not all(isinstance(m, np.ndarray) for m in data):
raise TypeError(f"All elements in {data_name} must be numpy arrays")
if not all(m.ndim in [2, 3] for m in data):
if any(m.ndim not in [2, 3] for m in data):
raise TypeError(f"All masks in {data_name} must be 2D or 3D numpy arrays")
return data[0].shape[:2]

Expand Down
12 changes: 5 additions & 7 deletions tests/test_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,18 @@ def get_targets_from_methods(cls):

def extract_targets_from_docstring(cls):
# Access the class's docstring
docstring = cls.__doc__
if not docstring:
if not (docstring := cls.__doc__):
return [] # Return an empty list if there's no docstring

# Regular expression to match the 'Targets:' section in the docstring
targets_pattern = r"Targets:\s*([^\n]+)"

# Search for the pattern in the docstring
matches = re.search(targets_pattern, docstring)
if matches:
# Search for the pattern in the docstring and extract targets if found
if matches := re.search(targets_pattern, docstring):
# Extract the targets string and split it by commas or spaces
targets_str = matches.group(1)
targets = re.split(r"[,\s]+", targets_str) # Split by comma or whitespace
targets = re.split(r"[,\s]+", matches[1]) # Using subscript notation instead of group()
return [target.strip() for target in targets if target.strip()] # Remove any extra whitespace

return [] # Return an empty list if the 'Targets:' section isn't found


Expand Down
24 changes: 11 additions & 13 deletions tools/make_transforms_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,11 @@ def get_image_only_transforms_info():
for name, cls in members:
if (inspect.isclass(cls) and
issubclass(cls, albumentations.ImageOnlyTransform) and
not issubclass(cls, albumentations.Transform3D) and # Exclude 3D transforms
name not in IGNORED_CLASSES):
if not is_deprecated(cls):
image_only_info[name] = {
"docs_link": make_augmentation_docs_link(cls)
}
not issubclass(cls, albumentations.Transform3D) and
name not in IGNORED_CLASSES) and not is_deprecated(cls):
image_only_info[name] = {
"docs_link": make_augmentation_docs_link(cls)
}
return image_only_info


Expand All @@ -95,13 +94,12 @@ def get_3d_transforms_info():
members = inspect.getmembers(albumentations)
for name, cls in members:
if (inspect.isclass(cls) and
issubclass(cls, albumentations.Transform3D) and # Check for Transform3D parent
name not in IGNORED_CLASSES):
if not is_deprecated(cls):
transforms_3d_info[name] = {
"targets": cls._targets,
"docs_link": make_augmentation_docs_link(cls)
}
issubclass(cls, albumentations.Transform3D) and
name not in IGNORED_CLASSES) and not is_deprecated(cls):
transforms_3d_info[name] = {
"targets": cls._targets,
"docs_link": make_augmentation_docs_link(cls)
}
return transforms_3d_info


Expand Down

0 comments on commit dff606c

Please sign in to comment.