Repository navigation
fix(pptx): read the series of every chart plot - #4811
DanielNg0729 merged 5 commits into
Conversation
python-pptx has no plot class for 3-D bar, line and pie, stock, surface and bar-of-pie plots. The backend skipped the series of such a plot and classified it as other_chart. python-pptx also has no series class for a 3-D area plot, so that chart stopped the conversion of the whole presentation with NotImplementedError. Every c:ser element has the same structure, so a python-pptx series class reads the series of any plot. Read the categories from the first series, as python-pptx does. Classify each plot by its tag, as the Word and Excel backends do, so bar3DChart is a bar chart. Signed-off-by: Daniel Nguyen <danielnguyenh07@gmail.com>
Slide 2 of pptx_chart.pptx holds a 3-D clustered column chart (c:bar3DChart). It changes from "other_chart" with no data table to "bar_chart" with its data: one series "2026" with 10, 20 and 30 over Q1 to Q3. These are the values in the chart's data cache. Signed-off-by: Daniel Nguyen <danielnguyenh07@gmail.com>
|
✅ DCO Check Passed Thanks @DanielNg0729, all your commits are properly signed off. 🎉 |
Merge Protections🟢 All 2 merge protections satisfied — ready to merge. Show 2 satisfied protections🟢 Enforce conventional commitMake sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
🟢 Require two reviewer for test updatesWhen test data is updated, we require two reviewers
|
AI triage (advisory)Checked commit The PowerPoint backend now reads the series of every chart plot through the XML tag. 3-D bar, line and pie plots keep their type and data, and a 3-D area chart no longer stops the conversion of the whole presentation. CI safety: no concern found. A maintainer must still approve CI. 4 related pull request(s) in the same code
Reference data changes
Assessment: expected. The PR now reads the data of the The |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
One blocker, plus a follow-up suggestion. Blocker: a malformed series in a 3-D, stock, surface or bar-of-pie plot now fails the whole presentation.
The fix is to add Suggestion (not blocking): Classifying by tag aligns the PowerPoint backend with Word and Excel, which is good. Using |
The backend now reads the series and categories of 3-D, stock, surface and bar-of-pie plots. When a c:ser has no c:order, or a c:pt has no c:v, python-pptx raises InvalidXmlError. The call site did not catch this error, so one malformed chart stopped the conversion of the whole presentation. A bar chart with the same defects failed on main too. Catch InvalidXmlError where the chart data is read. The chart keeps its classification without a data table, and a warning names the missing element. Signed-off-by: Daniel Nguyen <danielnguyenh07@gmail.com>
…tock-plots Signed-off-by: Daniel Nguyen <danielnguyenh07@gmail.com>
|
hi Dr @dolfim-ibm, thank you very much, i have added some commit to resolve your point for this PR as well. This PR is ready for your review again when you have a moment. Thanks again! |
|
#4812 is now merged, and this PR conflicts with This PR also covers the |
…tock-plots Signed-off-by: Daniel Nguyen <danielnguyenh07@gmail.com>
|
Thank you very much @dolfim-ibm, I merged the latest |
chrikrah
left a comment
There was a problem hiding this comment.
@DanielNg0729 closing my #4380 for this was the right call: the c:area3DChart deck I attached there now converts with its data table, where mine kept only a picture. The InvalidXmlError path @dolfim-ibm flagged degrades to a chart without a table, and I'd merge this at d572724.
$ PYTHONPATH=$PWD python -m pytest tests/test_backend_pptx.py tests/test_backend_pptx_charts.py -q
72 passed in 12.54s
# same tests, docling/backend/mspowerpoint_backend.py taken from merge base 0b62ddd2
12 failed, 60 passed in 10.57s
# area3DChart at base: NotImplementedError "series class ... not yet implemented",
# then RuntimeError: Pipeline SimplePipeline failed
# ruff 0.15.12 check and format: clean; python-pptx 1.0.2, pytest 9.0.3
# not run: suites beyond the pptx backend
non-blocking: slide 2 of pptx_chart.pptx changes from "Other chart" with no table to "Bar chart" with one. Anyone filtering on OTHER_CHART for 3-D bars will see that move, so it deserves a line in the release notes.
@PeterStaar-IBM, Mergify wants a second approval for the ground-truth update, the same rule you cleared on #4812. @ceberam, slide 2 comes from your #3972, so the move to "Bar chart" may want your view. Could one of you review it this week?
Summary
This is a follow-up to #4773 (issue #4772).
python-pptx has no plot class for some plot types: 3-D bar, 3-D line, 3-D pie, stock, surface and bar-of-pie. #4773 classifies such a plot as
other_chartand skips its series with a warning. A chart that has only such a plot therefore has no data table.python-pptx has a plot class for a 3-D area plot, but no series class for it. When the backend reads its series, python-pptx raises
NotImplementedError. The backend does not catch this error, so one 3-D area chart stops the conversion of the whole presentation (RuntimeError: Pipeline SimplePipeline failed).This PR changes the PowerPoint backend only.
c:serelements have thesame structure, so one python-pptx series class can read the series of any
plot type.
XySeriesreads scatter and bubble plots, which keep theirvalues in
c:yVal.BarSeriesreads all other plots, which keep theirvalues in
c:val.plot.categoriesdoes the same. A multi-level axis still gives the labels ofits leaf level.
in the Word and Excel backends.
bar3DChartis nowbar_chart,line3DChartisline_chart, andpie3DChartispie_chart. Stock,surface, 3-D area and bar-of-pie plots stay
other_chart, as they are inWord and Excel.
skip a plot now.
The output does not change for the plot types that python-pptx could already read. I compared column, line, pie, doughnut, area, radar, scatter, bubble and multi-level category charts before and after this change.
Change in the reference data
Slide 2 of
tests/data/pptx/sources/pptx_chart.pptxhas a 3-D clustered column chart (c:bar3DChart). This PR changes its output inpptx_chart.pptx.jsonandpptx_chart.pptx.md:Before: "Other chart", with no data table.
After: "Bar chart", with this data table:
These values are the values in the data cache of the chart (
ppt/charts/chart2.xml). The.itxtfile does not change. The otherreference files do not change. The second commit contains only this reference-data change.
Tests
test_plot_without_a_python_pptx_class_keeps_its_datamakes one chart foreach plot type: 3-D bar, 3-D line, 3-D pie, 3-D area, bar-of-pie, stock,
surface and 3-D surface. Each chart must keep its label and its data. All 8
cases fail on
main. The 3-D area case fails with the pipeline error.test_stock_plot_keeps_its_series_next_to_the_other_plotsreplacestest_unreadable_plot_keeps_the_data_of_the_other_plots. The stock seriesnow come after the column series in the data table.
test_chart_parsed_as_classified_picture_with_datanow checks theclassification and the data of slide 2.
Related PR
PR #4380 by @chrikrah fixes the same 3-D area error. It catches
NotImplementedError, so the chart is kept but has no data. With this PR, the chart keeps its data too. #4380 is based on the code before #4773. I can help to coordinate the two PRs if the maintainers prefer a different order.Checklist: