Title: Incorrect uses of is_numlike · Issue #7795 · matplotlib/matplotlib · GitHub
Open Graph Title: Incorrect uses of is_numlike · Issue #7795 · matplotlib/matplotlib
X Title: Incorrect uses of is_numlike · Issue #7795 · matplotlib/matplotlib
Description: cbook.is_numlike(obj) is implemented by checking whether obj + 1 raises. In particular, this means that numpy numeric arrays are considered as numlikes, which appears to be unintended in most cases. As an example (not the only one), whil...
Open Graph Description: cbook.is_numlike(obj) is implemented by checking whether obj + 1 raises. In particular, this means that numpy numeric arrays are considered as numlikes, which appears to be unintended in most cases...
X Description: cbook.is_numlike(obj) is implemented by checking whether obj + 1 raises. In particular, this means that numpy numeric arrays are considered as numlikes, which appears to be unintended in most cases...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/7795
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Incorrect uses of is_numlike","articleBody":"`cbook.is_numlike(obj)` is implemented by checking whether `obj + 1` raises. In particular, this means that numpy numeric arrays are considered as numlikes, which appears to be unintended in most cases.\r\n\r\nAs an example (not the only one), while\r\n```\r\nplt.scatter([0], [0], marker=[[0, 0], [0, 1], [1, 1]])\r\n```\r\nworks as expected,\r\n```\r\nplt.scatter([0], [0], marker=np.array([[0, 0], [0, 1], [1, 1]]))\r\n```\r\nraises an exception because code in `markers` checks (effectively, in this case) for whether `markers` is \"numlike\", and, if so, considers it to be a number of sides for a polygon marker (at the beginning of `_set_tuple_marker`).\r\n\r\nIn my never-ending push to get rid of as much of `cbook` as possible :-), I would suggest replacing calls to `is_numlike` to either `np.issubdtype(type(obj), np.number)` (if we were using numpy\u003e=1.9.0, this could be `isinstance(obj, abc.Number)`) or, if it was actually intended to accept arrays, `np.issubtype(np.asarray(obj).dtype, np.number)` -- we may as well distinguish explicitly between the two cases.\r\n\r\nEdit: Actually one can just define somewhere `Number = (abc.Number, np.number)`, then `isinstance(obj, Number)` will work even for older numpys (I guess).","author":{"url":"https://github.com/anntzer","@type":"Person","name":"anntzer"},"datePublished":"2017-01-10T23:26:36.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":6},"url":"https://github.com/7795/matplotlib/issues/7795"}
| 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:2a3277a8-6dc6-d88e-41a4-9bbc451f8452 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C36E:35558F:158E8F5:1F3A8A5:6A54CB76 |
| html-safe-nonce | 7a3873cc8f1dc5f49cf874ba4d46473579868337f37e8312293d1d488ccff904 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMzZFOjM1NTU4RjoxNThFOEY1OjFGM0E4QTU6NkE1NENCNzYiLCJ2aXNpdG9yX2lkIjoiNTQ0NjMwNTYzODc5MDc3NzcxOSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | f62bbd3d06fe9c8ed23fad8b323d4bafc328285cb5df6a918dc69d8935f24587 |
| hovercard-subject-tag | issue:199962759 |
| 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/7795/issue_layout |
| twitter:image | https://opengraph.githubassets.com/afd7ee86f5a2f464ff95bfb3eddc66da2490eed2851eb00d18de6535782566c2/matplotlib/matplotlib/issues/7795 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/afd7ee86f5a2f464ff95bfb3eddc66da2490eed2851eb00d18de6535782566c2/matplotlib/matplotlib/issues/7795 |
| og:image:alt | cbook.is_numlike(obj) is implemented by checking whether obj + 1 raises. In particular, this means that numpy numeric arrays are considered as numlikes, which appears to be unintended in most cases... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | anntzer |
| hostname | github.com |
| expected-hostname | github.com |
| None | 6e5f2e6ff3f430aa60a674066f957bca9f2106017e1b68126417422b58ce6e1e |
| 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 | be4d48619391052c9d312c7b587bb2ac38a97f57 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width