Title: [Bug]: `ValueError` upon deepcopy of a `Figure` object · Issue #21554 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: `ValueError` upon deepcopy of a `Figure` object · Issue #21554 · matplotlib/matplotlib
X Title: [Bug]: `ValueError` upon deepcopy of a `Figure` object · Issue #21554 · matplotlib/matplotlib
Description: Bug summary A deepcopy of a Figure object results in ValueError: 'Spines' object does not contain a '__deepcopy__' spine. This issue surfaced in a bug report of schemdraw: https://bitbucket.org/cdelker/schemdraw/issues/56/copydeepcopy-dr...
Open Graph Description: Bug summary A deepcopy of a Figure object results in ValueError: 'Spines' object does not contain a '__deepcopy__' spine. This issue surfaced in a bug report of schemdraw: https://bitbucket.org/cde...
X Description: Bug summary A deepcopy of a Figure object results in ValueError: 'Spines' object does not contain a '__deepcopy__' spine. This issue surfaced in a bug report of schemdraw: https://b...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/21554
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: `ValueError` upon deepcopy of a `Figure` object","articleBody":"### Bug summary\r\n\r\nA deepcopy of a `Figure` object results in `ValueError: 'Spines' object does not contain a '__deepcopy__' spine`.\r\n\r\nThis issue surfaced in a bug report of `schemdraw`: https://bitbucket.org/cdelker/schemdraw/issues/56/copydeepcopy-drawing-fails Nevertheless, the current issue is unrelated to `schemdraw`. I'm just mentioning this to illustrate a relevant use case leading to this problem.\r\n\r\n\r\n### Code for reproduction\r\n\r\n```python\r\nimport matplotlib.pyplot as plt\r\nimport copy\r\nfig, ax = plt.subplots()\r\ncopy.deepcopy(fig)\r\n```\r\n\r\nDisclaimer: this is taken from a message of `cdelker` on https://bitbucket.org/cdelker/schemdraw/issues/56/copydeepcopy-drawing-fails\r\n\r\n\r\n### Actual outcome\r\n\r\n```\r\nTraceback (most recent call last):\r\n File \"/usr/lib64/python3.9/site-packages/matplotlib/spines.py\", line 551, in __getattr__\r\n return self._dict[name]\r\nKeyError: '__deepcopy__'\r\n\r\nDuring handling of the above exception, another exception occurred:\r\n\r\nTraceback (most recent call last):\r\n File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\r\n File \"/usr/lib64/python3.9/copy.py\", line 172, in deepcopy\r\n y = _reconstruct(x, memo, *rv)\r\n File \"/usr/lib64/python3.9/copy.py\", line 270, in _reconstruct\r\n state = deepcopy(state, memo)\r\n File \"/usr/lib64/python3.9/copy.py\", line 146, in deepcopy\r\n y = copier(x, memo)\r\n File \"/usr/lib64/python3.9/copy.py\", line 230, in _deepcopy_dict\r\n y[deepcopy(key, memo)] = deepcopy(value, memo)\r\n File \"/usr/lib64/python3.9/copy.py\", line 172, in deepcopy\r\n y = _reconstruct(x, memo, *rv)\r\n File \"/usr/lib64/python3.9/copy.py\", line 270, in _reconstruct\r\n state = deepcopy(state, memo)\r\n File \"/usr/lib64/python3.9/copy.py\", line 146, in deepcopy\r\n y = copier(x, memo)\r\n File \"/usr/lib64/python3.9/copy.py\", line 230, in _deepcopy_dict\r\n y[deepcopy(key, memo)] = deepcopy(value, memo)\r\n File \"/usr/lib64/python3.9/copy.py\", line 146, in deepcopy\r\n y = copier(x, memo)\r\n File \"/usr/lib64/python3.9/copy.py\", line 205, in _deepcopy_list\r\n append(deepcopy(a, memo))\r\n File \"/usr/lib64/python3.9/copy.py\", line 146, in deepcopy\r\n y = copier(x, memo)\r\n File \"/usr/lib64/python3.9/copy.py\", line 210, in _deepcopy_tuple\r\n y = [deepcopy(a, memo) for a in x]\r\n File \"/usr/lib64/python3.9/copy.py\", line 210, in \u003clistcomp\u003e\r\n y = [deepcopy(a, memo) for a in x]\r\n File \"/usr/lib64/python3.9/copy.py\", line 172, in deepcopy\r\n y = _reconstruct(x, memo, *rv)\r\n File \"/usr/lib64/python3.9/copy.py\", line 270, in _reconstruct\r\n state = deepcopy(state, memo)\r\n File \"/usr/lib64/python3.9/copy.py\", line 146, in deepcopy\r\n y = copier(x, memo)\r\n File \"/usr/lib64/python3.9/copy.py\", line 230, in _deepcopy_dict\r\n y[deepcopy(key, memo)] = deepcopy(value, memo)\r\n File \"/usr/lib64/python3.9/copy.py\", line 151, in deepcopy\r\n copier = getattr(x, \"__deepcopy__\", None)\r\n File \"/usr/lib64/python3.9/site-packages/matplotlib/spines.py\", line 553, in __getattr__\r\n raise ValueError(\r\nValueError: 'Spines' object does not contain a '__deepcopy__' spine\r\n```\r\n\r\n### Expected outcome\r\n\r\nEither a deepcopy of the figure or a meaningful error message explaining that this operation is not supported.\r\n\r\n### Operating system\r\n\r\nFedora Linux\r\n\r\n### Matplotlib Version\r\n\r\n3.4.3\r\n\r\n### Matplotlib Backend\r\n\r\nQt5Agg\r\n\r\n### Python version\r\n\r\n3.9.7\r\n\r\n### Jupyter version\r\n\r\n6.1.6, (not installed)\r\n\r\n### Other libraries\r\n\r\nNone\r\n\r\n### Installation\r\n\r\nLinux package manager (Debian/Fedora/etc.)\r\n\r\n### Conda channel\r\n\r\n_No response_","author":{"url":"https://github.com/tovrstra","@type":"Person","name":"tovrstra"},"datePublished":"2021-11-06T17:57:08.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":11},"url":"https://github.com/21554/matplotlib/issues/21554"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:f0c182cb-4d18-1933-9a68-7d104c1c7779 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8B38:1BD726:AF948:EBB5B:6A53D4D7 |
| html-safe-nonce | 83458e3730dfbe8125ae7257118effeffb1e00170bb26a6ae51ece26dec2996f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QjM4OjFCRDcyNjpBRjk0ODpFQkI1Qjo2QTUzRDRENyIsInZpc2l0b3JfaWQiOiI3MzkwMzQ3NDk2NDExODc4NjE1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 1570c5dcd65fd9ba014544eb9f379e8d518223966b854dae61072ae9f90aaced |
| hovercard-subject-tag | issue:1046563156 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/matplotlib/matplotlib/21554/issue_layout |
| twitter:image | https://opengraph.githubassets.com/462a7d49661c80bc64f0c7d41f93f352deb2a78f7d02a7ac0af461aff7c7d200/matplotlib/matplotlib/issues/21554 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/462a7d49661c80bc64f0c7d41f93f352deb2a78f7d02a7ac0af461aff7c7d200/matplotlib/matplotlib/issues/21554 |
| og:image:alt | Bug summary A deepcopy of a Figure object results in ValueError: 'Spines' object does not contain a '__deepcopy__' spine. This issue surfaced in a bug report of schemdraw: https://bitbucket.org/cde... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | tovrstra |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| go-import | github.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git |
| octolytics-dimension-user_id | 215947 |
| octolytics-dimension-user_login | matplotlib |
| octolytics-dimension-repository_id | 1385122 |
| octolytics-dimension-repository_nwo | matplotlib/matplotlib |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1385122 |
| octolytics-dimension-repository_network_root_nwo | matplotlib/matplotlib |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 07a982c1d40157c619b364352b704c3ce66bb332 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width