Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent Mean of empty slice warning in fiddy.success.Consistency.method #55

Merged
merged 2 commits into from
Oct 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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