Title: [Bug]: `plt.pcolormesh` crashes when called with `Int64` nullable dtype · Issue #23991 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: `plt.pcolormesh` crashes when called with `Int64` nullable dtype · Issue #23991 · matplotlib/matplotlib
X Title: [Bug]: `plt.pcolormesh` crashes when called with `Int64` nullable dtype · Issue #23991 · matplotlib/matplotlib
Description: Bug summary When calling plt.pcolormesh with a dataframe containing either of the pandas nullable dtypes (Int64 or Float64) it crashes. Code for reproduction import matplotlib.pyplot as plt import pandas as pd df = pd.DataFrame({ 'foo' :...
Open Graph Description: Bug summary When calling plt.pcolormesh with a dataframe containing either of the pandas nullable dtypes (Int64 or Float64) it crashes. Code for reproduction import matplotlib.pyplot as plt import ...
X Description: Bug summary When calling plt.pcolormesh with a dataframe containing either of the pandas nullable dtypes (Int64 or Float64) it crashes. Code for reproduction import matplotlib.pyplot as plt import ...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/23991
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: `plt.pcolormesh` crashes when called with `Int64` nullable dtype","articleBody":"### Bug summary\n\nWhen calling `plt.pcolormesh` with a dataframe containing either of the pandas nullable dtypes (`Int64` or `Float64`) it crashes.\n\n### Code for reproduction\n\n```python\nimport matplotlib.pyplot as plt\r\nimport pandas as pd\r\n\r\ndf = pd.DataFrame({\r\n 'foo' : [1,2],\r\n 'bar' : [3,np.nan]\r\n })\r\n\r\n# works as expected\r\nplt.pcolormesh(df)\r\n\r\n# crashes\r\nplt.pcolormesh(df.astype('Int64'))\n```\n\n\n### Actual outcome\n\n```\r\n---------------------------------------------------------------------------\r\nTypeError Traceback (most recent call last)\r\nInput In [28], in \u003ccell line: 13\u003e()\r\n 10 plt.pcolormesh(df)\r\n 12 # crashes\r\n---\u003e 13 plt.pcolormesh(df.astype('Int64'))\r\n\r\nFile ~/.virtualenvs/teaching/lib/python3.10/site-packages/matplotlib/pyplot.py:2728, in pcolormesh(alpha, norm, cmap, vmin, vmax, shading, antialiased, data, *args, **kwargs)\r\n 2723 @_copy_docstring_and_deprecators(Axes.pcolormesh)\r\n 2724 def pcolormesh(\r\n 2725 *args, alpha=None, norm=None, cmap=None, vmin=None,\r\n 2726 vmax=None, shading=None, antialiased=False, data=None,\r\n 2727 **kwargs):\r\n-\u003e 2728 __ret = gca().pcolormesh(\r\n 2729 *args, alpha=alpha, norm=norm, cmap=cmap, vmin=vmin,\r\n 2730 vmax=vmax, shading=shading, antialiased=antialiased,\r\n 2731 **({\"data\": data} if data is not None else {}), **kwargs)\r\n 2732 sci(__ret)\r\n 2733 return __ret\r\n\r\nFile ~/.virtualenvs/teaching/lib/python3.10/site-packages/matplotlib/__init__.py:1414, in _preprocess_data.\u003clocals\u003e.inner(ax, data, *args, **kwargs)\r\n 1411 @functools.wraps(func)\r\n 1412 def inner(ax, *args, data=None, **kwargs):\r\n 1413 if data is None:\r\n-\u003e 1414 return func(ax, *map(sanitize_sequence, args), **kwargs)\r\n 1416 bound = new_sig.bind(ax, *args, **kwargs)\r\n 1417 auto_label = (bound.arguments.get(label_namer)\r\n 1418 or bound.kwargs.get(label_namer))\r\n\r\nFile ~/.virtualenvs/teaching/lib/python3.10/site-packages/matplotlib/axes/_axes.py:6072, in Axes.pcolormesh(self, alpha, norm, cmap, vmin, vmax, shading, antialiased, *args, **kwargs)\r\n 6068 C = C.ravel()\r\n 6070 kwargs.setdefault('snap', rcParams['pcolormesh.snap'])\r\n-\u003e 6072 collection = mcoll.QuadMesh(\r\n 6073 coords, antialiased=antialiased, shading=shading,\r\n 6074 array=C, cmap=cmap, norm=norm, alpha=alpha, **kwargs)\r\n 6075 collection._scale_norm(norm, vmin, vmax)\r\n 6076 self._pcolor_grid_deprecation_helper()\r\n\r\nFile ~/.virtualenvs/teaching/lib/python3.10/site-packages/matplotlib/collections.py:2015, in QuadMesh.__init__(self, *args, **kwargs)\r\n 2012 self._bbox.update_from_data_xy(self._coordinates.reshape(-1, 2))\r\n 2013 # super init delayed after own init because array kwarg requires\r\n 2014 # self._coordinates and self._shading\r\n-\u003e 2015 super().__init__(**kwargs)\r\n 2016 self.mouseover = False\r\n\r\nFile ~/.virtualenvs/teaching/lib/python3.10/site-packages/matplotlib/collections.py:217, in Collection.__init__(self, edgecolors, facecolors, linewidths, linestyles, capstyle, joinstyle, antialiaseds, offsets, transOffset, norm, cmap, pickradius, hatch, urls, zorder, **kwargs)\r\n 214 self._transOffset = transOffset\r\n 216 self._path_effects = None\r\n--\u003e 217 self.update(kwargs)\r\n 218 self._paths = None\r\n\r\nFile ~/.virtualenvs/teaching/lib/python3.10/site-packages/matplotlib/artist.py:1069, in Artist.update(self, props)\r\n 1066 if not callable(func):\r\n 1067 raise AttributeError(f\"{type(self).__name__!r} object \"\r\n 1068 f\"has no property {k!r}\")\r\n-\u003e 1069 ret.append(func(v))\r\n 1070 if ret:\r\n 1071 self.pchanged()\r\n\r\nFile ~/.virtualenvs/teaching/lib/python3.10/site-packages/matplotlib/collections.py:2077, in QuadMesh.set_array(self, A)\r\n 2072 if faulty_data:\r\n 2073 raise TypeError(\r\n 2074 f\"Dimensions of A {A.shape} are incompatible with \"\r\n 2075 f\"X ({width}) and/or Y ({height})\")\r\n-\u003e 2077 return super().set_array(A)\r\n\r\nFile ~/.virtualenvs/teaching/lib/python3.10/site-packages/matplotlib/cm.py:477, in ScalarMappable.set_array(self, A)\r\n 475 A = cbook.safe_masked_invalid(A, copy=True)\r\n 476 if not np.can_cast(A.dtype, float, \"same_kind\"):\r\n--\u003e 477 raise TypeError(f\"Image data of dtype {A.dtype} cannot be \"\r\n 478 \"converted to float\")\r\n 480 self._A = A\r\n\r\nTypeError: Image data of dtype object cannot be converted to float\r\n```\n\n### Expected outcome\n\n\r\n\n\n### Additional information\n\nNoticed via seaborn https://github.com/mwaskom/seaborn/issues/3042.\n\n### Operating system\n\nlubuntu\n\n### Matplotlib Version\n\n3.5.3\n\n### Matplotlib Backend\n\nmodule://matplotlib_inline.backend_inline\n\n### Python version\n\n3.10.4\n\n### Jupyter version\n\n6.4.12\n\n### Installation\n\npip","author":{"url":"https://github.com/mojones","@type":"Person","name":"mojones"},"datePublished":"2022-09-23T13:52:50.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":16},"url":"https://github.com/23991/matplotlib/issues/23991"}
| 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:4a6f6ab3-4e11-120e-e202-c32de16da482 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B3A8:1FBDE0:1A61B2:23AFE9:6A52E287 |
| html-safe-nonce | 82d3ea422b90083c3ff725c75eb2d590e41eb84bfbea901d8835ab6d26779ce1 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCM0E4OjFGQkRFMDoxQTYxQjI6MjNBRkU5OjZBNTJFMjg3IiwidmlzaXRvcl9pZCI6IjQ0MzM5MjE1MzI4OTc3MTQ4MjQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 03adc1bab3d3a1042982eddb4f9ff3b476c6875009c6632ce6c8246a5194e716 |
| hovercard-subject-tag | issue:1383844151 |
| 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/23991/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4a9c1a69821e0e16e812f40bbf9917f2c7197f0d03689b51f5c0bef73d59f523/matplotlib/matplotlib/issues/23991 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4a9c1a69821e0e16e812f40bbf9917f2c7197f0d03689b51f5c0bef73d59f523/matplotlib/matplotlib/issues/23991 |
| og:image:alt | Bug summary When calling plt.pcolormesh with a dataframe containing either of the pandas nullable dtypes (Int64 or Float64) it crashes. Code for reproduction import matplotlib.pyplot as plt import ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mojones |
| 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