Skip to content

Commit 9958b46

Browse files
bugfix: Move warning to correct function, extension of #624 (#635)
* bugfix: Move warning to correct function, extension of #624 * add changelog entry * Update webknossos/Changelog.md Co-authored-by: Philipp Otto <[email protected]>
1 parent ce1c608 commit 9958b46

File tree

4 files changed

+15
-17
lines changed

4 files changed

+15
-17
lines changed

webknossos/Changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ For upgrade instructions, please check the respective *Breaking Changes* section
1717
### Added
1818

1919
### Changed
20+
- Dataset: Moved the deprecation warning from `get_color_layers()` to the actually deprecated method `get_color_layer()`.
21+
[#635](https://github.com/scalableminds/webknossos-libs/pull/635)
2022
- Inconsistent writes to datasets properties (e.g., caused due to multiprocessing) are detected automatically. The warning can be escalated to an exception with `warnings.filterwarnings("error", module="webknossos", message=r"\[WARNING\]")`. [#633](https://github.com/scalableminds/webknossos-libs/pull/633)
2123

2224
### Fixed

webknossos/tests/test_dataset.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1758,13 +1758,11 @@ def test_get_or_add_layer_by_type(tmp_path: Path) -> None:
17581758
) # adds another layer
17591759
assert len(ds.get_segmentation_layers()) == 2
17601760

1761-
with pytest.raises(IndexError):
1762-
ds.get_color_layer() # fails
1761+
assert len(ds.get_color_layers()) == 0
17631762
_ = ds.add_layer("color", COLOR_CATEGORY) # adds layer
1764-
_ = ds.get_color_layer() # works
1763+
assert len(ds.get_color_layers()) == 1
17651764
_ = ds.add_layer("different_color", COLOR_CATEGORY) # adds another layer
1766-
with pytest.raises(IndexError):
1767-
ds.get_color_layer() # fails
1765+
assert len(ds.get_color_layers()) == 2
17681766

17691767
assure_exported_properties(ds)
17701768

webknossos/tests/test_dataset_deprecated.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1745,13 +1745,11 @@ def test_get_or_add_layer_by_type(tmp_path: Path) -> None:
17451745
) # adds another layer
17461746
assert len(ds.get_segmentation_layers()) == 2
17471747

1748-
with pytest.raises(IndexError):
1749-
ds.get_color_layer() # fails
1748+
assert len(ds.get_color_layers()) == 0
17501749
_ = ds.add_layer("color", COLOR_CATEGORY) # adds layer
1751-
_ = ds.get_color_layer() # works
1750+
assert len(ds.get_color_layers()) == 1
17521751
_ = ds.add_layer("different_color", COLOR_CATEGORY) # adds another layer
1753-
with pytest.raises(IndexError):
1754-
ds.get_color_layer() # fails
1752+
assert len(ds.get_color_layers()) == 2
17551753

17561754
assure_exported_properties(ds)
17571755

webknossos/webknossos/dataset/dataset.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -498,9 +498,9 @@ def add_layer_for_existing_files(
498498

499499
def get_segmentation_layer(self) -> SegmentationLayer:
500500
"""
501-
Returns the only segmentation layer. Prefer `get_segmentation_layers`,
502-
because multiple segmentation layers can exist.
501+
Deprecated, please use `get_segmentation_layers()`.
503502
503+
Returns the only segmentation layer.
504504
Fails with a IndexError if there are multiple segmentation layers or none.
505505
"""
506506

@@ -524,20 +524,20 @@ def get_segmentation_layers(self) -> List[SegmentationLayer]:
524524

525525
def get_color_layer(self) -> Layer:
526526
"""
527-
Returns the only color layer. Prefer `get_color_layers`, because multiple
528-
color layers can exist.
527+
Deprecated, please use `get_color_layers()`.
529528
529+
Returns the only color layer.
530530
Fails with a RuntimeError if there are multiple color layers or none.
531531
"""
532+
warnings.warn(
533+
"[DEPRECATION] get_color_layer() fails if no or more than one color layer exists. Prefer get_color_layers()."
534+
)
532535
return self._get_layer_by_category(COLOR_CATEGORY)
533536

534537
def get_color_layers(self) -> List[Layer]:
535538
"""
536539
Returns all color layers.
537540
"""
538-
warnings.warn(
539-
"[DEPRECATION] get_color_layer() fails if no or more than one color layer exists. Prefer get_color_layers()."
540-
)
541541
return [
542542
cast(Layer, layer)
543543
for layer in self.layers.values()

0 commit comments

Comments
 (0)