diff --git a/python/fasttext_module/fasttext/FastText.py b/python/fasttext_module/fasttext/FastText.py index c69311f..d4081b4 100644 --- a/python/fasttext_module/fasttext/FastText.py +++ b/python/fasttext_module/fasttext/FastText.py @@ -38,7 +38,7 @@ def score_vs_true(self, label): else: y_scores, y_true = ([], ()) - return np.array(y_scores, copy=False), np.array(y_true, copy=False) + return np.asarray(y_scores), np.asarray(y_true) def precision_recall_curve(self, label=None): """Return precision/recall curve""" @@ -53,7 +53,7 @@ def precision_recall_curve(self, label=None): else: precision, recall = ([], ()) - return np.array(precision, copy=False), np.array(recall, copy=False) + return np.asarray(precision), np.asarray(recall) def precision_at_recall(self, recall, label=None): """Return precision for a given recall""" diff --git a/python/fasttext_module/fasttext/tests/test_meter.py b/python/fasttext_module/fasttext/tests/test_meter.py new file mode 100644 index 0000000..1d0d42d --- /dev/null +++ b/python/fasttext_module/fasttext/tests/test_meter.py @@ -0,0 +1,21 @@ +# SPDX-FileContributor: Arthit Suriyawongkul +# SPDX-FileCopyrightText: 2026-present, fasttext-community +# SPDX-FileType: SOURCE +# SPDX-License-Identifier: MIT + +"""Meter curves must work with NumPy 2 (np.array copy=False raises there).""" + +import numpy as np + +from .helpers import build_supervised_model, get_random_data + + +def test_meter_returns_arrays(tmp_path): + data = get_random_data(100) + # thread=12: thread <= 10 leaves the input matrix partly uninitialized. + model = build_supervised_model(data, {"thread": 12}) + path = tmp_path / "test.txt" + path.write_text("".join(f"__label__{line}\n" for line in data)) + meter = model.get_meter(str(path)) + for pair in (meter.score_vs_true(model.labels[0]), meter.precision_recall_curve()): + assert all(isinstance(a, np.ndarray) for a in pair)