Repository navigation
docs: fix examples that raise AttributeError when run as scripts - #5848
Merged
Merged
Conversation
- 3d-mesh: np.DataSource was removed in NumPy 2.0; use np.lib.npyio.DataSource, which also exists in NumPy 1.x - graphing-multiple-chart-types, sankey-diagram: `import urllib` does not load urllib.request, so import the submodule directly
camdecoster
reviewed
Oct 27, 2026
camdecoster
left a comment
Contributor
There was a problem hiding this comment.
Thanks for the fix! It's hard to keep the docs up to date. During review, I noticed that colorscales.md needs the same update. Would you be willing to take care of that here?
Four examples in colorscales.md use `import urllib` and then call urllib.request.urlopen, which raises AttributeError when the example runs on its own.
Contributor
Author
|
Thanks, done in ab658fb. The four examples in I also searched the rest of |
camdecoster
approved these changes
Oct 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Link to issue
No issue. I found these while running the
doc/pythonexamples as plain Python scripts.Description of change
Four doc pages have examples that raise
AttributeErrorwhen run on their own:3d-mesh.md(two examples) callsnp.DataSource(), which was removed in NumPy 2.0. It now usesnp.lib.npyio.DataSource(), which exists in NumPy 2 and also in the NumPy 1.22.4 pinned indoc/requirements.txt.graphing-multiple-chart-types.md(one example),sankey-diagram.md(two examples) andcolorscales.md(four examples) doimport urlliband then callurllib.request.urlopen(...).import urllibdoes not load theurllib.requestsubmodule, so this fails in a fresh interpreter (module 'urllib' has no attribute 'request') and only works when something else has already imported it. They nowimport urllib.request.Demo
Not applicable (no visual change).
Testing strategy
I ran every
pythonblock of3d-mesh.md,graphing-multiple-chart-types.mdandsankey-diagram.mdin order in a fresh interpreter with plotly 7.1.0, NumPy 2.5.4 and pandas, withfig.show()stubbed out. Before the change, each page stopped with theAttributeErrorabove. After it, all blocks on the three pages run. Forcolorscales.md, I ran each of the five blocks that useurllibin its own fresh process: before the change, the four blocks withimport urllibfailed with theAttributeError, and after it all five run. No tests are needed since only documentation examples change.Guidelines