Title: [Bug]: `ax.hist()` fails on sequence of timedeltas due to comparison with `np.inf` · Issue #31182 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: `ax.hist()` fails on sequence of timedeltas due to comparison with `np.inf` · Issue #31182 · matplotlib/matplotlib
X Title: [Bug]: `ax.hist()` fails on sequence of timedeltas due to comparison with `np.inf` · Issue #31182 · matplotlib/matplotlib
Description: Bug summary I expected ax.hist([sequence of timedeltas]) to Just Work, as it does with ax.hist([sequence of timestamps]). However, there is a comparison with np.inf that works when the sequence is of timestamps and fails when the sequenc...
Open Graph Description: Bug summary I expected ax.hist([sequence of timedeltas]) to Just Work, as it does with ax.hist([sequence of timestamps]). However, there is a comparison with np.inf that works when the sequence is ...
X Description: Bug summary I expected ax.hist([sequence of timedeltas]) to Just Work, as it does with ax.hist([sequence of timestamps]). However, there is a comparison with np.inf that works when the sequence is ...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/31182
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: `ax.hist()` fails on sequence of timedeltas due to comparison with `np.inf`","articleBody":"### Bug summary\n\nI expected `ax.hist([sequence of timedeltas])` to Just Work, as it does with `ax.hist([sequence of timestamps])`. However, there is a comparison with `np.inf` that works when the sequence is of timestamps and fails when the sequence is of timedeltas; numpy cannot promote a `TimeDelta64DType` to a float: https://github.com/matplotlib/matplotlib/blob/main/lib/matplotlib/axes/_axes.py#L7479\n\n### Code for reproduction\n\n```Python\nimport matplotlib.pyplot as plt\nimport pandas as pd\nfig = plt.figure(figsize=(10, 7))\nax = fig.add_subplot(1, 1, 1)\nax.hist(pd.date_range(\"2026-01-01\", \"2026-01-05\", freq=\"D\"))\nax.hist(pd.date_range(\"2026-01-01\", \"2026-01-05\", freq=\"D\").diff(1))\n```\n\n### Actual outcome\n\n```\nnumpy.exceptions.DTypePromotionError: The DType \u003cclass 'numpy.dtypes.TimeDelta64DType'\u003e could not be promoted by \u003cclass 'numpy.dtypes._PyFloatDType'\u003e. This means that no common DType exists for the given inputs. For example they cannot be stored in a single array unless the dtype is `object`. The full list of DTypes is: (\u003cclass 'numpy.dtypes.TimeDelta64DType'\u003e, \u003cclass 'numpy.dtypes._PyFloatDType'\u003e)\n\nThe above exception was the direct cause of the following exception:\n\nTraceback (most recent call last):\n File \"\u003cpython-input-5\u003e\", line 1, in \u003cmodule\u003e\n ax.hist(pd.date_range(\"2026-01-01\", \"2026-01-05\", freq=\"D\").diff(1))\n ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/Users/kylepenner/Documents/numpy/lib/python3.13/site-packages/matplotlib/_api/deprecation.py\", line 477, in wrapper\n return func(*args, **kwargs)\n File \"/Users/kylepenner/Documents/numpy/lib/python3.13/site-packages/matplotlib/__init__.py\", line 1497, in inner\n return func(\n ax,\n *map(cbook.sanitize_sequence, args),\n **{k: cbook.sanitize_sequence(v) for k, v in kwargs.items()})\n File \"/Users/kylepenner/Documents/numpy/lib/python3.13/site-packages/matplotlib/axes/_axes.py\", line 7479, in hist\n xmin = min(xmin, np.nanmin(xi))\nnumpy._core._exceptions._UFuncNoLoopError: ufunc 'less' did not contain a loop with signature matching types (\u003cclass 'numpy.dtypes.TimeDelta64DType'\u003e, \u003cclass 'numpy.dtypes._PyFloatDType'\u003e) -\u003e None\n```\n\n\n### Expected outcome\n\nThere's an easy way around this---convert the timedeltas to floats with `.total_seconds()`---but I do prefer the `hist` call to just work.\n\n### Additional information\n\n_No response_\n\n### Operating system\n\n_No response_\n\n### Matplotlib Version\n\n3.11.0.dev1799+g6dbc0c7cd\n\n### Matplotlib Backend\n\n_No response_\n\n### Python version\n\n_No response_\n\n### Jupyter version\n\n_No response_\n\n### Installation\n\ngit checkout","author":{"url":"https://github.com/kdpenner","@type":"Person","name":"kdpenner"},"datePublished":"2026-02-20T18:36:25.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":15},"url":"https://github.com/31182/matplotlib/issues/31182"}
| 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:a81dc394-3567-bd49-42bd-dcb39eaf2fba |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BBFC:1FCD98:292CF62:36DB94B:6A52175D |
| html-safe-nonce | 79871dc674e0ecf61b2bbd6eac42a4e429396ac10f9ffcb6b34a0af2ce837103 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQkZDOjFGQ0Q5ODoyOTJDRjYyOjM2REI5NEI6NkE1MjE3NUQiLCJ2aXNpdG9yX2lkIjoiODA0MDk3NzcwODIzNzMzMDI2OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 223a74e00834b2452d625ce84470fb5cd114f1c21fcde4e3d3c38ad054064658 |
| hovercard-subject-tag | issue:3969859202 |
| 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/31182/issue_layout |
| twitter:image | https://opengraph.githubassets.com/05ab8fe78bd35cadffc9da127c9dd1988610051de05004d3eda0f6b139eb0f9a/matplotlib/matplotlib/issues/31182 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/05ab8fe78bd35cadffc9da127c9dd1988610051de05004d3eda0f6b139eb0f9a/matplotlib/matplotlib/issues/31182 |
| og:image:alt | Bug summary I expected ax.hist([sequence of timedeltas]) to Just Work, as it does with ax.hist([sequence of timestamps]). However, there is a comparison with np.inf that works when the sequence is ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | kdpenner |
| 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 | 7aed05249554b889eb33d002851a973eebcc7e91 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width