Skip to content

Commit

Permalink
Refactor load_data method to simplify error handling and remove unnec…
Browse files Browse the repository at this point in the history
…essary cache checks

Signed-off-by: elronbandel <[email protected]>
  • Loading branch information
elronbandel committed Feb 6, 2025
1 parent 27f9c4f commit 294eabf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
12 changes: 4 additions & 8 deletions src/unitxt/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,10 @@ def _maybe_set_classification_policy(self):
pass

def load_data(self) -> MultiStream:
iterables = self.__class__._loader_cache.get(str(self), None)
if iterables is None:
try:
iterables = self.load_iterables()
except Exception as e:
raise UnitxtError(f"Error in loader:\n{self}") from e
self.__class__._loader_cache.max_size = settings.loader_cache_size
self.__class__._loader_cache[str(self)] = iterables
try:
iterables = self.load_iterables()
except Exception as e:
raise UnitxtError(f"Error in loader:\n{self}") from e
if isoftype(iterables, Dict[str, ReusableGenerator]):
return MultiStream.from_generators(iterables, copying=True)
return MultiStream.from_iterables(iterables, copying=True)
Expand Down
4 changes: 2 additions & 2 deletions utils/.secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
"filename": "src/unitxt/loaders.py",
"hashed_secret": "840268f77a57d5553add023cfa8a4d1535f49742",
"is_verified": false,
"line_number": 563,
"line_number": 559,
"is_secret": false
}
],
Expand Down Expand Up @@ -184,5 +184,5 @@
}
]
},
"generated_at": "2025-02-06T16:56:01Z"
"generated_at": "2025-02-06T16:59:14Z"
}

0 comments on commit 294eabf

Please sign in to comment.