| 1 | { |
| 2 | "task_id": "matplotlib__matplotlib-23476", |
| 3 | "setup_info": { |
| 4 | "repo_path": "/media/media0/yuntong/SWE-bench/testbed/matplotlib__matplotlib/setup_matplotlib__matplotlib__3.5", |
| 5 | "env_name": "setup_matplotlib__matplotlib__3.5", |
| 6 | "pre_install": [], |
| 7 | "install": "python -m pip install -e .", |
| 8 | "test_cmd": "pytest --no-header -rA --tb=no -p no:cacheprovider lib/matplotlib/tests/test_figure.py" |
| 9 | }, |
| 10 | "task_info": { |
| 11 | "instance_id": "matplotlib__matplotlib-23476", |
| 12 | "base_commit": "33a0599711d26dc2b79f851c6daed4947df7c167", |
| 13 | "hints_text": "I suspect this will also affect anything that know how to deal with high-dpi screens.\r\n\r\nFor, .... reasons..., when we handle high-dpi cases by doubling the dpi on the figure (we have ideas how to fix this, but it is a fair amount of work) when we show it. We are saving the doubled dpi which when re-loaded in doubled again.\r\n\r\nI think there is an easy fix.....", |
| 14 | "created_at": "2022-07-22T18:58:22Z", |
| 15 | "test_patch": "diff --git a/lib/matplotlib/tests/test_figure.py b/lib/matplotlib/tests/test_figure.py\n--- a/lib/matplotlib/tests/test_figure.py\n+++ b/lib/matplotlib/tests/test_figure.py\n@@ -2,6 +2,7 @@\n from datetime import datetime\n import io\n from pathlib import Path\n+import pickle\n import platform\n from threading import Timer\n from types import SimpleNamespace\n@@ -1380,3 +1381,11 @@ def test_deepcopy():\n \n assert ax.get_xlim() == (1e-1, 1e2)\n assert fig2.axes[0].get_xlim() == (0, 1)\n+\n+\n+def test_unpickle_with_device_pixel_ratio():\n+ fig = Figure(dpi=42)\n+ fig.canvas._set_device_pixel_ratio(7)\n+ assert fig.dpi == 42*7\n+ fig2 = pickle.loads(pickle.dumps(fig))\n+ assert fig2.dpi == 42\n", |
| 16 | "repo": "matplotlib/matplotlib", |
| 17 | "problem_statement": "[Bug]: DPI of a figure is doubled after unpickling on M1 Mac\n### Bug summary\r\n\r\nWhen a figure is unpickled, it's dpi is doubled. This behaviour happens every time and if done in a loop it can cause an `OverflowError`.\r\n\r\n### Code for reproduction\r\n\r\n```python\r\nimport numpy as np\r\nimport matplotlib\r\nimport matplotlib.pyplot as plt\r\nimport pickle\r\nimport platform\r\n\r\nprint(matplotlib.get_backend())\r\nprint('Matplotlib ver:', matplotlib.__version__)\r\nprint('Platform:', platform.platform())\r\nprint('System:', platform.system())\r\nprint('Release:', platform.release())\r\nprint('Python ver:', platform.python_version())\r\n\r\n\r\ndef dump_load_get_dpi(fig):\r\n with open('sinus.pickle','wb') as file:\r\n pickle.dump(fig, file)\r\n\r\n with open('sinus.pickle', 'rb') as blob:\r\n fig2 = pickle.load(blob)\r\n return fig2, fig2.dpi\r\n\r\n\r\ndef run():\r\n fig = plt.figure()\r\n x = np.linspace(0,2*np.pi)\r\n y = np.sin(x)\r\n\r\n for i in range(32):\r\n print(f'{i}: {fig.dpi}')\r\n fig, dpi = dump_load_get_dpi(fig)\r\n\r\n\r\nif __name__ == '__main__':\r\n run()\r\n```\r\n\r\n\r\n### Actual outcome\r\n\r\n```\r\nMacOSX\r\nMatplotlib ver: 3.5.2\r\nPlatform: macOS-12.4-arm64-arm-64bit\r\nSystem: Darwin\r\nRelease: 21.5.0\r\nPython ver: 3.9.12\r\n0: 200.0\r\n1: 400.0\r\n2: 800.0\r\n3: 1600.0\r\n4: 3200.0\r\n5: 6400.0\r\n6: 12800.0\r\n7: 25600.0\r\n8: 51200.0\r\n9: 102400.0\r\n10: 204800.0\r\n11: 409600.0\r\n12: 819200.0\r\n13: 1638400.0\r\n14: 3276800.0\r\n15: 6553600.0\r\n16: 13107200.0\r\n17: 26214400.0\r\n18: 52428800.0\r\n19: 104857600.0\r\n20: 209715200.0\r\n21: 419430400.0\r\nTraceback (most recent call last):\r\n File \"/Users/wsykala/projects/matplotlib/example.py\", line 34, in <module>\r\n run()\r\n File \"/Users/wsykala/projects/matplotlib/example.py\", line 30, in run\r\n fig, dpi = dump_load_get_dpi(fig)\r\n File \"/Users/wsykala/projects/matplotlib/example.py\", line 20, in dump_load_get_dpi\r\n fig2 = pickle.load(blob)\r\n File \"/Users/wsykala/miniconda3/envs/playground/lib/python3.9/site-packages/matplotlib/figure.py\", line 2911, in __setstate__\r\n mgr = plt._backend_mod.new_figure_manager_given_figure(num, self)\r\n File \"/Users/wsykala/miniconda3/envs/playground/lib/python3.9/site-packages/matplotlib/backend_bases.py\", line 3499, in new_figure_manager_given_figure\r\n canvas = cls.FigureCanvas(figure)\r\n File \"/Users/wsykala/miniconda3/envs/playground/lib/python3.9/site-packages/matplotlib/backends/backend_macosx.py\", line 32, in __init__\r\n _macosx.FigureCanvas.__init__(self, width, height)\r\nOverflowError: signed integer is greater than maximum\r\n```\r\n\r\n### Expected outcome\r\n\r\n```\r\nMacOSX\r\nMatplotlib ver: 3.5.2\r\nPlatform: macOS-12.4-arm64-arm-64bit\r\nSystem: Darwin\r\nRelease: 21.5.0\r\nPython ver: 3.9.12\r\n0: 200.0\r\n1: 200.0\r\n2: 200.0\r\n3: 200.0\r\n4: 200.0\r\n5: 200.0\r\n6: 200.0\r\n7: 200.0\r\n8: 200.0\r\n9: 200.0\r\n10: 200.0\r\n11: 200.0\r\n12: 200.0\r\n13: 200.0\r\n14: 200.0\r\n15: 200.0\r\n16: 200.0\r\n17: 200.0\r\n18: 200.0\r\n19: 200.0\r\n20: 200.0\r\n21: 200.0\r\n22: 200.0\r\n```\r\n\r\n### Additional information\r\n\r\nThis seems to happen only on M1 MacBooks and the version of python doesn't matter.\r\n\r\n### Operating system\r\n\r\nOS/X\r\n\r\n### Matplotlib Version\r\n\r\n3.5.2\r\n\r\n### Matplotlib Backend\r\n\r\nMacOSX\r\n\r\n### Python version\r\n\r\n3.9.12\r\n\r\n### Jupyter version\r\n\r\n_No response_\r\n\r\n### Installation\r\n\r\npip\n", |
| 18 | "version": "3.5", |
| 19 | "FAIL_TO_PASS": [ |
| 20 | "lib/matplotlib/tests/test_figure.py::test_unpickle_with_device_pixel_ratio" |
| 21 | ], |
| 22 | "PASS_TO_PASS": [ |
| 23 | "lib/matplotlib/tests/test_figure.py::TestSubplotMosaic::test_all_nested[png]", |
| 24 | "lib/matplotlib/tests/test_figure.py::TestSubplotMosaic::test_basic[x0-png]", |
| 25 | "lib/matplotlib/tests/test_figure.py::TestSubplotMosaic::test_basic[x1-png]", |
| 26 | "lib/matplotlib/tests/test_figure.py::TestSubplotMosaic::test_empty[x0-None-png]", |
| 27 | "lib/matplotlib/tests/test_figure.py::TestSubplotMosaic::test_empty[x1-SKIP-png]", |
| 28 | "lib/matplotlib/tests/test_figure.py::TestSubplotMosaic::test_empty[x2-0-png]", |
| 29 | "lib/matplotlib/tests/test_figure.py::TestSubplotMosaic::test_empty[x3-None-png]", |
| 30 | "lib/matplotlib/tests/test_figure.py::TestSubplotMosaic::test_empty[x4-SKIP-png]", |
| 31 | "lib/matplotlib/tests/test_figure.py::TestSubplotMosaic::test_empty[x5-0-png]", |
| 32 | "lib/matplotlib/tests/test_figure.py::TestSubplotMosaic::test_fail[AAA\\nc\\nBBB-All", |
| 33 | "lib/matplotlib/tests/test_figure.py::TestSubplotMosaic::test_fail[x0-(?m)we", |
| 34 | "lib/matplotlib/tests/test_figure.py::TestSubplotMosaic::test_fail[x1-There", |
| 35 | "lib/matplotlib/tests/test_figure.py::TestSubplotMosaic::test_fail[x3-All", |
| 36 | "lib/matplotlib/tests/test_figure.py::TestSubplotMosaic::test_fail_list_of_str", |
| 37 | "lib/matplotlib/tests/test_figure.py::TestSubplotMosaic::test_hashable_keys[png]", |
| 38 | "lib/matplotlib/tests/test_figure.py::TestSubplotMosaic::test_nested[png]", |
| 39 | "lib/matplotlib/tests/test_figure.py::TestSubplotMosaic::test_nested_tuple[png]", |
| 40 | "lib/matplotlib/tests/test_figure.py::TestSubplotMosaic::test_nested_user_order", |
| 41 | "lib/matplotlib/tests/test_figure.py::TestSubplotMosaic::test_share_all", |
| 42 | "lib/matplotlib/tests/test_figure.py::TestSubplotMosaic::test_single_str_input[AAA\\nBBB-png]", |
| 43 | "lib/matplotlib/tests/test_figure.py::TestSubplotMosaic::test_single_str_input[ABC\\nDEF-png]", |
| 44 | "lib/matplotlib/tests/test_figure.py::TestSubplotMosaic::test_single_str_input[\\nAAA\\nBBB\\n-png]", |
| 45 | "lib/matplotlib/tests/test_figure.py::TestSubplotMosaic::test_string_parser", |
| 46 | "lib/matplotlib/tests/test_figure.py::TestSubplotMosaic::test_subplot_kw[None-png]", |
| 47 | "lib/matplotlib/tests/test_figure.py::TestSubplotMosaic::test_subplot_kw[subplot_kw0-png]", |
| 48 | "lib/matplotlib/tests/test_figure.py::TestSubplotMosaic::test_subplot_kw[subplot_kw1-png]", |
| 49 | "lib/matplotlib/tests/test_figure.py::TestSubplotMosaic::test_user_order[abc]", |
| 50 | "lib/matplotlib/tests/test_figure.py::TestSubplotMosaic::test_user_order[acb]", |
| 51 | "lib/matplotlib/tests/test_figure.py::TestSubplotMosaic::test_user_order[bac]", |
| 52 | "lib/matplotlib/tests/test_figure.py::TestSubplotMosaic::test_user_order[bca]", |
| 53 | "lib/matplotlib/tests/test_figure.py::TestSubplotMosaic::test_user_order[cab]", |
| 54 | "lib/matplotlib/tests/test_figure.py::TestSubplotMosaic::test_user_order[cba]", |
| 55 | "lib/matplotlib/tests/test_figure.py::test_add_artist[pdf]", |
| 56 | "lib/matplotlib/tests/test_figure.py::test_add_artist[png]", |
| 57 | "lib/matplotlib/tests/test_figure.py::test_add_axes_kwargs", |
| 58 | "lib/matplotlib/tests/test_figure.py::test_add_subplot_invalid", |
| 59 | "lib/matplotlib/tests/test_figure.py::test_add_subplot_kwargs", |
| 60 | "lib/matplotlib/tests/test_figure.py::test_add_subplot_subclass", |
| 61 | "lib/matplotlib/tests/test_figure.py::test_add_subplot_twotuple", |
| 62 | "lib/matplotlib/tests/test_figure.py::test_align_labels[png]", |
| 63 | "lib/matplotlib/tests/test_figure.py::test_align_labels_stray_axes", |
| 64 | "lib/matplotlib/tests/test_figure.py::test_alpha[png]", |
| 65 | "lib/matplotlib/tests/test_figure.py::test_animated_with_canvas_change[eps]", |
| 66 | "lib/matplotlib/tests/test_figure.py::test_animated_with_canvas_change[pdf]", |
| 67 | "lib/matplotlib/tests/test_figure.py::test_animated_with_canvas_change[png]", |
| 68 | "lib/matplotlib/tests/test_figure.py::test_autofmt_xdate[both]", |
| 69 | "lib/matplotlib/tests/test_figure.py::test_autofmt_xdate[major]", |
| 70 | "lib/matplotlib/tests/test_figure.py::test_autofmt_xdate[minor]", |
| 71 | "lib/matplotlib/tests/test_figure.py::test_axes_removal", |
| 72 | "lib/matplotlib/tests/test_figure.py::test_axes_remove", |
| 73 | "lib/matplotlib/tests/test_figure.py::test_change_dpi", |
| 74 | "lib/matplotlib/tests/test_figure.py::test_clf_keyword", |
| 75 | "lib/matplotlib/tests/test_figure.py::test_clf_not_redefined", |
| 76 | "lib/matplotlib/tests/test_figure.py::test_deepcopy", |
| 77 | "lib/matplotlib/tests/test_figure.py::test_figaspect", |
| 78 | "lib/matplotlib/tests/test_figure.py::test_fignum_exists", |
| 79 | "lib/matplotlib/tests/test_figure.py::test_figure[pdf]", |
| 80 | "lib/matplotlib/tests/test_figure.py::test_figure[png]", |
| 81 | "lib/matplotlib/tests/test_figure.py::test_figure_clear[clear]", |
| 82 | "lib/matplotlib/tests/test_figure.py::test_figure_clear[clf]", |
| 83 | "lib/matplotlib/tests/test_figure.py::test_figure_label", |
| 84 | "lib/matplotlib/tests/test_figure.py::test_figure_legend[pdf]", |
| 85 | "lib/matplotlib/tests/test_figure.py::test_figure_legend[png]", |
| 86 | "lib/matplotlib/tests/test_figure.py::test_figure_repr", |
| 87 | "lib/matplotlib/tests/test_figure.py::test_fspath[eps]", |
| 88 | "lib/matplotlib/tests/test_figure.py::test_fspath[pdf]", |
| 89 | "lib/matplotlib/tests/test_figure.py::test_fspath[png]", |
| 90 | "lib/matplotlib/tests/test_figure.py::test_fspath[ps]", |
| 91 | "lib/matplotlib/tests/test_figure.py::test_fspath[svg]", |
| 92 | "lib/matplotlib/tests/test_figure.py::test_gca", |
| 93 | "lib/matplotlib/tests/test_figure.py::test_ginput", |
| 94 | "lib/matplotlib/tests/test_figure.py::test_invalid_figure_add_axes", |
| 95 | "lib/matplotlib/tests/test_figure.py::test_invalid_figure_size[-1-1]", |
| 96 | "lib/matplotlib/tests/test_figure.py::test_invalid_figure_size[1-nan]", |
| 97 | "lib/matplotlib/tests/test_figure.py::test_invalid_figure_size[inf-1]", |
| 98 | "lib/matplotlib/tests/test_figure.py::test_invalid_layouts", |
| 99 | "lib/matplotlib/tests/test_figure.py::test_iterability_axes_argument", |
| 100 | "lib/matplotlib/tests/test_figure.py::test_kwargs_pass", |
| 101 | "lib/matplotlib/tests/test_figure.py::test_picking_does_not_stale", |
| 102 | "lib/matplotlib/tests/test_figure.py::test_removed_axis", |
| 103 | "lib/matplotlib/tests/test_figure.py::test_reused_gridspec", |
| 104 | "lib/matplotlib/tests/test_figure.py::test_savefig", |
| 105 | "lib/matplotlib/tests/test_figure.py::test_savefig_backend", |
| 106 | "lib/matplotlib/tests/test_figure.py::test_savefig_pixel_ratio[Agg]", |
| 107 | "lib/matplotlib/tests/test_figure.py::test_savefig_pixel_ratio[Cairo]", |
| 108 | "lib/matplotlib/tests/test_figure.py::test_savefig_warns", |
| 109 | "lib/matplotlib/tests/test_figure.py::test_set_fig_size", |
| 110 | "lib/matplotlib/tests/test_figure.py::test_subfigure[png]", |
| 111 | "lib/matplotlib/tests/test_figure.py::test_subfigure_double[png]", |
| 112 | "lib/matplotlib/tests/test_figure.py::test_subfigure_dpi", |
| 113 | "lib/matplotlib/tests/test_figure.py::test_subfigure_pdf", |
| 114 | "lib/matplotlib/tests/test_figure.py::test_subfigure_scatter_size[png]", |
| 115 | "lib/matplotlib/tests/test_figure.py::test_subfigure_spanning", |
| 116 | "lib/matplotlib/tests/test_figure.py::test_subfigure_ss[png]", |
| 117 | "lib/matplotlib/tests/test_figure.py::test_subfigure_ticks", |
| 118 | "lib/matplotlib/tests/test_figure.py::test_subfigure_tightbbox", |
| 119 | "lib/matplotlib/tests/test_figure.py::test_subplots_shareax_loglabels", |
| 120 | "lib/matplotlib/tests/test_figure.py::test_suptitle[pdf]", |
| 121 | "lib/matplotlib/tests/test_figure.py::test_suptitle[png]", |
| 122 | "lib/matplotlib/tests/test_figure.py::test_suptitle_fontproperties", |
| 123 | "lib/matplotlib/tests/test_figure.py::test_tightbbox", |
| 124 | "lib/matplotlib/tests/test_figure.py::test_too_many_figures", |
| 125 | "lib/matplotlib/tests/test_figure.py::test_valid_layouts", |
| 126 | "lib/matplotlib/tests/test_figure.py::test_waitforbuttonpress" |
| 127 | ], |
| 128 | "environment_setup_commit": "de98877e3dc45de8dd441d008f23d88738dc015d", |
| 129 | "patch": "diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py\n--- a/lib/matplotlib/figure.py\n+++ b/lib/matplotlib/figure.py\n@@ -3023,6 +3023,9 @@ def __getstate__(self):\n # Set cached renderer to None -- it can't be pickled.\n state[\"_cachedRenderer\"] = None\n \n+ # discard any changes to the dpi due to pixel ratio changes\n+ state[\"_dpi\"] = state.get('_original_dpi', state['_dpi'])\n+\n # add version information to the state\n state['__mpl_version__'] = mpl.__version__\n \n", |
| 130 | "pr_link": "https://github.com/matplotlib/matplotlib/pull/23476" |
| 131 | } |
| 132 | } |