Failed result serialization destroys a previously saved JSON result
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 78/100
Hướng nghiên cứu
Bắt đầu trong src/evaluate/saving.py tại hàm save, nơi dòng 43 chạy json.dump(data, f) sau khi đích đã được mở để ghi. Chạy reproducer trong issue để xác nhận tệp bị cắt cụt, sau đó chuyển việc tuần tự hóa sang lời gọi json.dumps trước khi tệp được mở để một TypeError để nguyên các byte hiện có và không tạo tệp mới. Hoàn thành nghĩa là reproducer in ra Previous result preserved: True, một đích mới vẫn không tồn tại sau khi lỗi, và các bài kiểm thử lưu hiện có vẫn chạy qua trên cả hai stack phụ thuộc; lưu ý rằng người báo cáo cho biết một bản sửa và các ca kiểm thử đã tồn tại, nên hãy kiểm tra công việc đang tiến hành trước.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
evaluate.save() opens an existing result in write mode before it knows whether the new payload can be JSON-serialized. A serialization error can therefore destroy an earlier valid result and leave an incomplete JSON file.
Reproducer (no Hub downloads):
from pathlib import Path
from tempfile import TemporaryDirectory
import traceback
import numpy as np
import evaluate
with TemporaryDirectory() as directory:
destination = Path(directory) / "results.json"
evaluate.save(destination, accuracy=0.75)
previous = destination.read_bytes()
try:
evaluate.save(destination, accuracy=1.0, details={"scores": np.array([1, 2])})
except TypeError:
traceback.print_exc()
print("Previous result preserved:", destination.read_bytes() == previous)
print(destination.read_text(encoding="utf-8"))
Actual output after the exception:
Previous result preserved: False
{"accuracy": 1.0, "details": {"scores":
Expected: still raise TypeError for unsupported JSON values, but preserve the previous file unchanged. For a new destination, a failed serialization should not leave a partial result file. This is not a request to add NumPy encoding support or promise atomic writes against operating-system/process failures.
Full traceback from the standalone reproduction (installation prefixes shortened):
Traceback (most recent call last):
File "repro.py", line 51, in save_failure
evaluate.save(destination, accuracy=1.0, details={"scores": np.array([1, 2])})
File "src/evaluate/saving.py", line 43, in save
json.dump(data, f)
File "python3.11/json/__init__.py", line 179, in dump
for chunk in iterable:
File "python3.11/json/encoder.py", line 432, in _iterencode
yield from _iterencode_dict(o, _current_indent_level)
File "python3.11/json/encoder.py", line 406, in _iterencode_dict
yield from chunks
File "python3.11/json/encoder.py", line 406, in _iterencode_dict
yield from chunks
File "python3.11/json/encoder.py", line 439, in _iterencode
o = _default(o)
^^^^^^^^^^^
File "python3.11/json/encoder.py", line 180, in default
raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type ndarray is not JSON serializable
Reproduced on unchanged main a5db2ad54aaeadf15c7aa1f056bc6f7bbeeb7e5f, macOS 26.6.2 / Darwin 25.6.0, Python 3.11.13, with datasets 2.21.0 / NumPy 1.26.4 and datasets 5.0.1 / NumPy 2.4.6. PyTorch 2.8.0 is installed but is not involved; TensorFlow is not installed.
Searches of open/closed reports for save, overwrite, corruption, serializable, atomic, truncate, and _setup_path found no matching fix. Related #808 handles missing Git and #809 handles dotted directories. The original #7 discusses format choices and JSONL concurrency, not this single-call serialization failure.
A focused fix serializes the payload before opening the destination. Four failure cases cover existing/new files and scalar/nested NumPy values; another case keeps intentional replacement of a valid explicit destination working. These and the existing saving tests pass on both dependency stacks (8 per stack), and repository quality checks pass. All four preservation cases fail on unchanged main.
- Ngôn ngữ chính
- Python
- Star
- 2.5k
- Fork
- 380
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của huggingface/evaluate
-
radar_plot fails on pandas 3 (data.loc with 1-tuple key)Có thể đã có người làm @davrens101 đã nhận 4 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 79/100
huggingface/evaluate#854 · 1 bình luận ·
-
exact_match: ignore_punctuation only removes ASCII punctuationCó thể đã có người làm @reginaldalfret đã nhận 24 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
huggingface/evaluate#836 ·
-
EvaluationSuite.run fails with default args_for_task and mutates supplied kwargsCó thể đã có người làm @ktz03 đã nhận 36 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
huggingface/evaluate#825 ·
-
exact_match scores two different answers as a perfect match when normalization erases both to the same residueCó thể đã có người làm @MahendraMula đã nhận 53 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
huggingface/evaluate#822 ·
-
Perplexity metric fails with GPT-2 tokenizerCó thể đã có người làm @zanvari đã nhận 150 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
huggingface/evaluate#766 · 1 bình luận ·
Tất cả issue của huggingface/evaluate
Issue tương tự
-
agents nolte-linux security skills
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
nolte/claude-shared#732 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Maintainer thường phản hồi trong vòng 2 ngày
-
[Bug] Source archive filter: dry run excludes SystemVerilog (.sv) files with no preflight warningĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
FinanceFlash/unvibecode#906 ·
Maintainer thường phản hồi trong vòng 1 ngày