From 98f25df82a7275260f9588830cae727c2a21c0d5 Mon Sep 17 00:00:00 2001 From: Denis Stalz-John Date: Wed, 18 Oct 2023 10:21:26 +0200 Subject: [PATCH] fix: Replace lambda `class_extractor` in `DirClsDataInfoListing` with a private function because lambdas are not pickable (#85) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 📥 Pull Request Description Replace lambda `class_extractor` in `DirClsDataInfoListing` with a private function because lambdas are not pickable ## 📝 Checklist Please make sure you've completed the following tasks before submitting this pull request: - [x] Pre-commit hooks were executed - [x] Changes have been reviewed by at least one other developer - [ ] Tests have been added or updated to cover the changes (only necessary if the changes affect the executable code) - [x] All tests ran successfully - [x] All merge conflicts are resolved - [ ] Documentation has been updated to reflect the changes - [ ] Any necessary migrations have been run --- niceml/data/datainfolistings/clsdatainfolisting.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/niceml/data/datainfolistings/clsdatainfolisting.py b/niceml/data/datainfolistings/clsdatainfolisting.py index 2a9eb1f3..59aba75a 100644 --- a/niceml/data/datainfolistings/clsdatainfolisting.py +++ b/niceml/data/datainfolistings/clsdatainfolisting.py @@ -31,12 +31,14 @@ def __init__( label_suffix: str = ".json", image_suffixes: Optional[List[str]] = None, ): + """Init method of LabelClsDataInfoListing""" self.sub_dir = sub_dir self.data_location = data_location self.label_suffix = label_suffix self.image_suffixes = image_suffixes or [".png", ".jpg", ".jpeg"] def list(self, data_description: DataDescription) -> List[ClsDataInfo]: + """Lists all data infos""" output_data_description: OutputVectorDataDescription = check_instance( data_description, OutputVectorDataDescription ) @@ -73,6 +75,11 @@ def list(self, data_description: DataDescription) -> List[ClsDataInfo]: return new_data_info_list +def _default_class_extractor(input_str: str) -> str: + """Default class extractor for DirClsDataInfoListing""" + return splitext(input_str)[0].rsplit("_", maxsplit=1)[-1] + + class DirClsDataInfoListing( DataInfoListing ): # pylint: disable=too-few-public-methods, too-many-arguments @@ -85,14 +92,14 @@ def __init__( class_extractor: Optional[Callable] = None, image_suffixes: Optional[List[str]] = None, ): + """Init method of DirClsDataInfoListing""" self.sub_dir = sub_dir self.location = location - self.class_extractor = class_extractor or ( - lambda x: splitext(x)[0].rsplit("_", maxsplit=1)[-1] - ) + self.class_extractor = class_extractor or _default_class_extractor self.image_suffixes = image_suffixes or [".png", ".jpg", ".jpeg"] def list(self, data_description: DataDescription) -> List[ClsDataInfo]: + """Lists all data infos""" output_data_description: OutputVectorDataDescription = check_instance( data_description, OutputVectorDataDescription )