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

Support numpy 2.0 #57

Merged
merged 2 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
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
10 changes: 5 additions & 5 deletions audmetric/core/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def concordance_cc(
prediction = prediction[mask]

if len(prediction) < 2:
return np.NaN
return np.nan

length = prediction.size
mean_y = np.mean(truth)
Expand Down Expand Up @@ -656,7 +656,7 @@ def linkability(
# Global measure using trapz numerical integration
d_sys = np.trapz(x=bin_centers, y=d * y1)

return d_sys
return float(d_sys)


def mean_absolute_error(
Expand Down Expand Up @@ -764,7 +764,7 @@ def pearson_cc(
prediction = np.array(list(prediction))

if len(prediction) < 2 or prediction.std() == 0:
return np.NaN
return np.nan
else:
return float(np.corrcoef(prediction, truth)[0][1])

Expand Down Expand Up @@ -997,7 +997,7 @@ def unweighted_average_bias(
if denominator == 0:
return np.nan

return bias / denominator
return float(bias / denominator)


def unweighted_average_fscore(
Expand Down Expand Up @@ -1225,7 +1225,7 @@ def word_error_rate(
wer += edit_distance(t, p) / n

num_samples = len(truth) if len(truth) > 1 else 1
return wer / num_samples
return float(wer / num_samples)


def _matching_scores(
Expand Down
4 changes: 2 additions & 2 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def test_accuracy(truth, prediction, labels, to_string):
prediction = [str(w) for w in prediction]

if len(prediction) == 0:
accuracy = np.NaN
accuracy = np.nan
else:
if labels:
mask = np.nonzero(
Expand Down Expand Up @@ -426,7 +426,7 @@ def test_mean_squared_error(value_range, num_elements):
)
def test_pearson_cc(truth, prediction):
if len(prediction) < 2 or prediction.std() == 0:
pcc = np.NaN
pcc = np.nan
else:
pcc = np.corrcoef(list(truth), list(prediction))[0][1]
np.testing.assert_almost_equal(
Expand Down
44 changes: 22 additions & 22 deletions tests/test_concordance_cc.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def expected_ccc(truth, prediction):
+ (prediction.mean() - truth.mean()) ** 2
)
if denominator == 0:
ccc = np.NaN
ccc = np.nan
else:
r = np.corrcoef(list(prediction), list(truth))[0][1]
numerator = 2 * r * prediction.std() * truth.std()
Expand Down Expand Up @@ -82,37 +82,37 @@ def test_concordance_cc(truth, prediction, ignore_nan):
[],
[],
True,
np.NaN,
np.nan,
),
(
[],
[],
False,
np.NaN,
np.nan,
),
(
[0],
[0],
True,
np.NaN,
np.nan,
),
(
[0],
[0],
False,
np.NaN,
np.nan,
),
(
[0, np.NaN],
[0, np.NaN],
[0, np.nan],
[0, np.nan],
True,
np.NaN,
np.nan,
),
(
[0, np.NaN],
[0, np.NaN],
[0, np.nan],
[0, np.nan],
False,
np.NaN,
np.nan,
),
(
[0, 1, 2, 3],
Expand All @@ -121,40 +121,40 @@ def test_concordance_cc(truth, prediction, ignore_nan):
expected_ccc([0, 1, 2, 3], [1, 2, 3, 4]),
),
(
[np.NaN, 1, 2, 3],
[np.NaN, 2, 3, 4],
[np.nan, 1, 2, 3],
[np.nan, 2, 3, 4],
True,
expected_ccc([1, 2, 3], [2, 3, 4]),
),
(
[np.NaN, 1, 2, 3],
[1, 2, 3, np.NaN],
[np.nan, 1, 2, 3],
[1, 2, 3, np.nan],
True,
expected_ccc([1, 2], [2, 3]),
),
(
[0, np.NaN, 2, 3],
[0, np.nan, 2, 3],
[1, 2, 3, 4],
True,
expected_ccc([0, 2, 3], [1, 3, 4]),
),
(
[0, 1, 2, 3],
[1, 2, np.NaN, 4],
[1, 2, np.nan, 4],
True,
expected_ccc([0, 1, 3], [1, 2, 4]),
),
(
[np.NaN, np.NaN, 2, 3],
[1, 2, 3, np.NaN],
[np.nan, np.nan, 2, 3],
[1, 2, 3, np.nan],
True,
expected_ccc([2], [3]),
),
(
[np.NaN, np.NaN, 2, 3],
[1, 2, 3, np.NaN],
[np.nan, np.nan, 2, 3],
[1, 2, 3, np.nan],
False,
np.NaN,
np.nan,
),
],
)
Expand Down
Loading