Title: axes.bar fails when x is int-indexed pandas.Series · Issue #15162 · matplotlib/matplotlib · GitHub
Open Graph Title: axes.bar fails when x is int-indexed pandas.Series · Issue #15162 · matplotlib/matplotlib
X Title: axes.bar fails when x is int-indexed pandas.Series · Issue #15162 · matplotlib/matplotlib
Description: Bug report Bug summary The following codes fail in matplotlib 3.1.1, while work properly in 3.0.3 case 1 Code for reproduction import pandas as pd from matplotlib import pyplot as plt df = pd.DataFrame({"x":[1,2,3],"width":[.2,.4,.6]},in...
Open Graph Description: Bug report Bug summary The following codes fail in matplotlib 3.1.1, while work properly in 3.0.3 case 1 Code for reproduction import pandas as pd from matplotlib import pyplot as plt df = pd.DataF...
X Description: Bug report Bug summary The following codes fail in matplotlib 3.1.1, while work properly in 3.0.3 case 1 Code for reproduction import pandas as pd from matplotlib import pyplot as plt df = pd.DataF...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/15162
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"axes.bar fails when x is int-indexed pandas.Series","articleBody":"### Bug report\r\n\r\n#### Bug summary\r\nThe following codes fail in matplotlib 3.1.1, while work properly in 3.0.3\r\n\r\n#### case 1\r\n**Code for reproduction**\r\n```python\r\nimport pandas as pd\r\nfrom matplotlib import pyplot as plt\r\n\r\ndf = pd.DataFrame({\"x\":[1,2,3],\"width\":[.2,.4,.6]},index=[1,2,3])\r\n\r\nplt.figure()\r\nplt.bar(df.x, 1, width=df.width)\r\nplt.show()\r\n```\r\n\r\n**Actual outcome**\r\n```\r\nTraceback (most recent call last):\r\n File \"/Desktop/fail_example.py\", line 7, in \u003cmodule\u003e\r\n plt.bar(df.x, 1, width=df.width)\r\n File \"/.pyenv/versions/3.7.3/lib/python3.7/site-packages/matplotlib/pyplot.py\", line 2440, in bar\r\n **({\"data\": data} if data is not None else {}), **kwargs)\r\n File \"/.pyenv/versions/3.7.3/lib/python3.7/site-packages/matplotlib/__init__.py\", line 1601, in inner\r\n return func(ax, *map(sanitize_sequence, args), **kwargs)\r\n File \"/.pyenv/versions/3.7.3/lib/python3.7/site-packages/matplotlib/axes/_axes.py\", line 2430, in bar\r\n label='_nolegend_',\r\n File \"/.pyenv/versions/3.7.3/lib/python3.7/site-packages/matplotlib/patches.py\", line 707, in __init__\r\n Patch.__init__(self, **kwargs)\r\n File \"/.pyenv/versions/3.7.3/lib/python3.7/site-packages/matplotlib/patches.py\", line 89, in __init__\r\n self.set_linewidth(linewidth)\r\n File \"/.pyenv/versions/3.7.3/lib/python3.7/site-packages/matplotlib/patches.py\", line 368, in set_linewidth\r\n self._linewidth = float(w)\r\n```\r\n\r\n**Expected outcome**\r\nOutcome in 3.0.3:\r\n\r\n\r\n\r\n#### case 2\r\n**Code for reproduction**\r\n```python\r\nimport pandas as pd\r\nfrom matplotlib import pyplot as plt\r\n\r\ndf = pd.DataFrame({\"x\":[1,3,10]},index=[1000,2000,3000])\r\n\r\nplt.figure()\r\nplt.bar(df.x, 1, width=.2)\r\nplt.show()\r\n```\r\n\r\n**Actual outcome**\r\n\r\n\r\n**Expected outcome**\r\nOutcome in 3.0.3:\r\n\r\n\r\n\r\n\r\n**Matplotlib version**\r\n\u003c!--Please specify your platform and versions of the relevant libraries you are using:--\u003e\r\n * Operating system: MacOSX\r\n * Matplotlib version: 3.1.1 (installed from pip)\r\n * Matplotlib backend (`print(matplotlib.get_backend())`): MacOSX\r\n * Python version: 3.7.3\r\n * Jupyter version (if applicable):\r\n * Other libraries: pandas 0.24.2\r\n\r\n**Cause of the bug**\r\n```\r\n_axes.py, line 2363 in bar:\r\n x0 = x\r\n x = np.asarray(self.convert_xunits(x))\r\n width = self._convert_dx(width, x0, x, self.convert_xunits)\r\n_axes.py, line 2166 in _convert_dx: \r\n try:\r\n x0 = x0[0]\r\n except (TypeError, IndexError, KeyError):\r\n x0 = x0\r\n```\r\nI guess x0 is expected to be a scalar after this line, However when x0 is an int-indexed (and 0 is not in its indices) pandas.Series, it is continued to be pandas.Series and causes chained disorders to end in the error above.\r\nTo evidence, they worked properly when rewritten as (ugly!):\r\n```\r\n try:\r\n x0 = x0[0]\r\n except (TypeError, IndexError, KeyError):\r\n try:\r\n x0 = x0.iat[0]\r\n except:\r\n x0 = x0\r\n```","author":{"url":"https://github.com/infrub","@type":"Person","name":"infrub"},"datePublished":"2019-08-31T10:18:03.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":9},"url":"https://github.com/15162/matplotlib/issues/15162"}
| 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:61158f90-fd78-a2a2-07eb-588b8c105887 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 97EE:32747A:3A91405:53451E1:6A569D1F |
| html-safe-nonce | a2f6fb5c74118877d8fb7031f4891738bdcb103adf78b732be58f9657b6914a6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5N0VFOjMyNzQ3QTozQTkxNDA1OjUzNDUxRTE6NkE1NjlEMUYiLCJ2aXNpdG9yX2lkIjoiNzE2MDE4MTQwMDQ4Njk0NTU5IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 0ba91ba77153a78a87a505a475eeec300a0379e0245fe049fd8d09fc01b88f42 |
| hovercard-subject-tag | issue:487755069 |
| 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/15162/issue_layout |
| twitter:image | https://opengraph.githubassets.com/07dda069a0e93396eb2b35136defae8302b885138f41783b6c7ce15906f1ae27/matplotlib/matplotlib/issues/15162 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/07dda069a0e93396eb2b35136defae8302b885138f41783b6c7ce15906f1ae27/matplotlib/matplotlib/issues/15162 |
| og:image:alt | Bug report Bug summary The following codes fail in matplotlib 3.1.1, while work properly in 3.0.3 case 1 Code for reproduction import pandas as pd from matplotlib import pyplot as plt df = pd.DataF... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | infrub |
| hostname | github.com |
| expected-hostname | github.com |
| None | 647a25f437e2f54eccdd162bd007c8ae70f4235c4125dba0f4518747cc8b9615 |
| 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 | 05adb86a60ce3d701e556eded3ab26300ec6bcc4 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width