From 91fa367c48c286a1eb8f5538dd1147418b17f25c Mon Sep 17 00:00:00 2001 From: Denis Stalz-John Date: Tue, 17 Oct 2023 15:04:30 +0200 Subject: [PATCH] datasets and all components need to be pickable, and lambdas are not --- 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 )