Skip to content

Commit

Permalink
fix: Replace lambda class_extractor in DirClsDataInfoListing with…
Browse files Browse the repository at this point in the history
… a private function because lambdas are not pickable (#85)

## 📥 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
  • Loading branch information
dstalzjohn authored and aiakide committed Nov 8, 2023
1 parent 5d2d205 commit def7d1a
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions niceml/data/datainfolistings/clsdatainfolisting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -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
Expand All @@ -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
)
Expand Down

0 comments on commit def7d1a

Please sign in to comment.