Skip to content

Commit

Permalink
superintend: rename raise_when_more_errors_than -> raise_if_more_erro…
Browse files Browse the repository at this point in the history
…rs_than
  • Loading branch information
ebonnal committed Nov 30, 2023
1 parent 1c78b84 commit 08a7cc0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions kioss/_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,24 +189,24 @@ def superintend(
self,
n_samples: int = 0,
n_error_samples: int = 8,
raise_when_more_errors_than: int = 0,
raise_if_more_errors_than: int = 0,
) -> List[T]:
"""
Superintend the Pipe:
- iterates over it until it is exhausted,
- logs
- catches exceptions log a sample of them at the end of the iteration
- raises the first encountered error if more exception than `raise_when_more_errors_than` are catched during iteration.
- raises the first encountered error if more exception than `raise_if_more_errors_than` are catched during iteration.
- else returns a sample of the output elements
Args:
n_samples (int, optional): The maximum number of elements to collect in the list (default is infinity).
n_error_samples (int, optional): The maximum number of error samples to log (default is 8).
raise_when_more_errors_than (int, optional): An error will be raised if the number of encountered errors is more than this threshold (default is 0).
raise_if_more_errors_than (int, optional): An error will be raised if the number of encountered errors is more than this threshold (default is 0).
Returns:
List[T]: A list containing the elements of the Pipe truncate to the first `n_samples` ones.
Raises:
RuntimeError: If more exception than `raise_when_more_errors_than` are catched during iteration.
RuntimeError: If more exception than `raise_if_more_errors_than` are catched during iteration.
"""
if not isinstance(self, LogPipe):
plan = self.log("output elements")
Expand All @@ -231,7 +231,7 @@ def register_error_sample(error):
n_error_samples,
list(map(repr, error_samples)),
)
if raise_when_more_errors_than < errors_count:
if raise_if_more_errors_than < errors_count:
raise error_samples[0]

return samples
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='kioss',
version='0.5.0',
version='0.5.1',
packages=['kioss'],
url='http://github.com/bonnal-enzo/kioss',
license='Apache 2.',
Expand Down
4 changes: 2 additions & 2 deletions tests/test_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,11 +433,11 @@ def test_superintend(self):
superintend,
)
# does not raise with sufficient threshold
superintend(raise_when_more_errors_than=1)
superintend(raise_if_more_errors_than=1)
# raise with insufficient threshold
self.assertRaises(
ValueError,
lambda: superintend(raise_when_more_errors_than=0),
lambda: superintend(raise_if_more_errors_than=0),
)

def test_log(self):
Expand Down

0 comments on commit 08a7cc0

Please sign in to comment.