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`

Fixes #52.
  • Loading branch information
dweindl committed Oct 9, 2024
1 parent 6aea82e commit c853212
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions fiddy/success.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import abc
from typing import Any, Callable, Union

import numpy as np

from . import analysis, directional_derivative
Expand Down Expand Up @@ -98,25 +97,24 @@ def method(
equal_nan=self.equal_nan,
).all()

consistent_results = [
consistent_results = np.array([
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)

])

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 c853212

Please sign in to comment.