Writing to an existing directory whose name has a dot fails with "Invalid format"
Đá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
- 35/100
Hướng nghiên cứu
Read coerce_for_js and determine_path, along with the existing test_determine_path_directory_with_suffix test. Reproduce the failure with an existing directory whose name contains dots, then check that the result writes Sales.png inside it and that a directory named plots.svg keeps the default PNG format. An open pull request already addresses this issue.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
write_fig accepts a directory as path and generates a filename from the figure title. When the directory name contains a dot, for example a date-named folder like reports/2024.01.31, the render fails with ValueError: Invalid format '31' and no file is written.
coerce_for_js reads the image format from path.suffix without checking whether path is a directory. determine_path already treats an existing directory with a suffix-like name as a directory (see test_determine_path_directory_with_suffix), so the two functions disagree.
With the default cancel_on_error=False, the error is returned in the result tuple rather than raised, so the call looks like it succeeds and the directory stays empty.
A directory named like a format, such as plots.svg, silently switches the output format to SVG instead of the default PNG.
Steps to reproduce
import pathlib
import tempfile
import kaleido
d = pathlib.Path(tempfile.mkdtemp()) / "2024.01.31"
d.mkdir()
fig = {"data": [{"type": "bar", "x": ["a", "b"], "y": [1, 2]}], "layout": {"title": {"text": "Sales"}}}
print(kaleido.write_fig_sync(fig, path=d))
print(list(d.iterdir()))
Actual result
(ValueError("Invalid format '31'.\nSupported formats: ('png', 'jpg', 'jpeg', 'webp', 'svg', 'json', 'pdf')"),)
[]
Expected result
The image is written as 2024.01.31/Sales.png, the same as for a directory without a dot.
Environment
kaleido main (a517ccc, v1.5.0), Python 3.12, Linux.
- Ngôn ngữ chính
- Python
- Star
- 504
- Fork
- 65
- Merge trung bình
- 6 ngày 9 giờ
- Pull request đã merge (30 ngày)
- 2
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
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 plotly/kaleido
-
Deterministic Rendering ChallengesCó thể làm lại được @camdecoster đã nhận 67 ngày trước và không có pull request nào đang mở. Đang mởenhancement feature P2 size: 5
-
[FEATURE]: Embed custom fonts into vector exports (no system install)Có thể đã có người làm @camdecoster đã nhận 124 ngày trước. Đang mởenhancement P3 size: 3
-
enhancement feature P3 size: 5
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
-
GlobalKaleidoServer is not thread-safeCó thể đã có người làm @talleibman đã nhận 249 ngày trước. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
-
[BUG]: to_image gets stuck very rarelyCó thể đã có người làm @AndrushaUt đã nhận 216 ngày trước. Đang mởbug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
Tất cả issue của plotly/kaleido
Issue tương tự
-
DBFS append mode silently overwrites existing filesCó thể đã có người làm @IlyaKhalafi đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
fsspec/filesystem_spec#2429 ·
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 78/100
volcengine/OpenViking#7014 ·
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 68/100
fedora-copr/copr#4600 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
ansys/pydpf-core#3620 ·
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 78/100
Maintainer thường phản hồi trong vòng 1 ngày