Skip to content

Commit

Permalink
Prevent Mean of empty slice warning in `fiddy.success.Consistency.m…
Browse files Browse the repository at this point in the history
…ethod` (#55)

Fixes #52.
  • Loading branch information
dweindl authored Oct 15, 2024
1 parent 8f92753 commit df57f29
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions fiddy/success.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import abc
from collections.abc import Callable
from typing import Any, Union
from typing import Any

import numpy as np

Expand Down Expand Up @@ -97,25 +97,26 @@ def method(
equal_nan=self.equal_nan,
).all()

consistent_results = [
np.nanmean(list(results_by_size[size].values()), axis=0)
for size, success in success_by_size.items()
if success
]

success = False
value = np.nanmean(np.array(consistent_results), axis=0)
if consistent_results:
success = (
np.isclose(
consistent_results,
value,
rtol=self.rtol,
atol=self.atol,
equal_nan=self.equal_nan,
).all()
and not np.isnan(consistent_results).all()
)
value = np.average(np.array(consistent_results), axis=0)
consistent_results = np.array(
[
np.nanmean(list(results_by_size[size].values()), axis=0)
for size, success in success_by_size.items()
if success
]
)

if len(consistent_results) == 0:
return False, np.nan

value = np.nanmean(consistent_results, axis=0)
success = (
np.isclose(
consistent_results,
value,
rtol=self.rtol,
atol=self.atol,
equal_nan=self.equal_nan,
).all()
and not np.isnan(consistent_results).all()
)
return success, value

0 comments on commit df57f29

Please sign in to comment.