Title: Is `v = np.array(v.dt.to_pydatetime())` still necessary? · Issue #4836 · plotly/plotly.py · GitHub
Open Graph Title: Is `v = np.array(v.dt.to_pydatetime())` still necessary? · Issue #4836 · plotly/plotly.py
X Title: Is `v = np.array(v.dt.to_pydatetime())` still necessary? · Issue #4836 · plotly/plotly.py
Description: As far as I can tell, the lines plotly.py/packages/python/plotly/_plotly_utils/basevalidators.py Lines 101 to 108 in 960adb9 elif v.dtype.kind == "M": # Convert datetime Series/Index to numpy array of datetimes if isinstance(v, pd.Series...
Open Graph Description: As far as I can tell, the lines plotly.py/packages/python/plotly/_plotly_utils/basevalidators.py Lines 101 to 108 in 960adb9 elif v.dtype.kind == "M": # Convert datetime Series/Index to numpy array...
X Description: As far as I can tell, the lines plotly.py/packages/python/plotly/_plotly_utils/basevalidators.py Lines 101 to 108 in 960adb9 elif v.dtype.kind == "M": # Convert datetime Series/Index to n...
Opengraph URL: https://github.com/plotly/plotly.py/issues/4836
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Is `v = np.array(v.dt.to_pydatetime())` still necessary?","articleBody":"As far as I can tell, the lines\n\nhttps://github.com/plotly/plotly.py/blob/960adb9b9a89387d05343497de1df5d3df592698/packages/python/plotly/_plotly_utils/basevalidators.py#L101-L108\n\nwere introduced in https://github.com/plotly/plotly.py/pull/1163 to introduce issues with displaying numpy datetime64 arrays\n\nHowever, have the numpy datetime64 issues since been fixed? From having built Polars from source, then here's what I see on the master branch:\n\n\n\nLooks like it displays fine\n\nIf I apply the diff\n```diff\n--- a/packages/python/plotly/_plotly_utils/basevalidators.py\n+++ b/packages/python/plotly/_plotly_utils/basevalidators.py\n@@ -95,20 +95,7 @@ def copy_to_readonly_numpy_array(v, kind=None, force_numeric=False):\n \n # Handle pandas Series and Index objects\n if pd and isinstance(v, (pd.Series, pd.Index)):\n- if v.dtype.kind in numeric_kinds:\n- # Get the numeric numpy array so we use fast path below\n- v = v.values\n- elif v.dtype.kind == \"M\":\n- # Convert datetime Series/Index to numpy array of datetimes\n- if isinstance(v, pd.Series):\n- with warnings.catch_warnings():\n- warnings.simplefilter(\"ignore\", FutureWarning)\n- # Series.dt.to_pydatetime will return Index[object]\n- # https://github.com/pandas-dev/pandas/pull/52459\n- v = np.array(v.dt.to_pydatetime())\n- else:\n- # DatetimeIndex\n- v = v.to_pydatetime()\n+ v = v.values\n```\nthen it looks like pandas datetime Series still display fine\n\n\n\n---\n\nAsking in the context of https://github.com/plotly/plotly.py/pull/4790, as `copy_to_readonly_numpy_array` would need to handle other kinds of inputs (not just pandas series / index)\n\nA plain conversion to numpy would be a lot faster than going via stdlib datetime objects\n```\nIn [23]: %time np.array(s.dt.to_pydatetime())\nCPU times: user 325 ms, sys: 8.34 ms, total: 333 ms\nWall time: 360 ms\nOut[23]:\narray([datetime.datetime(2000, 1, 1, 0, 0),\n datetime.datetime(2000, 1, 1, 1, 0),\n datetime.datetime(2000, 1, 1, 2, 0), ...,\n datetime.datetime(2114, 1, 29, 13, 0),\n datetime.datetime(2114, 1, 29, 14, 0),\n datetime.datetime(2114, 1, 29, 15, 0)], dtype=object)\n\nIn [24]: %time s.to_numpy()\nCPU times: user 46 μs, sys: 0 ns, total: 46 μs\nWall time: 51.5 μs\nOut[24]:\narray(['2000-01-01T00:00:00.000000000', '2000-01-01T01:00:00.000000000',\n '2000-01-01T02:00:00.000000000', ...,\n '2114-01-29T13:00:00.000000000', '2114-01-29T14:00:00.000000000',\n '2114-01-29T15:00:00.000000000'], dtype='datetime64[ns]')\n```","author":{"url":"https://github.com/MarcoGorelli","@type":"Person","name":"MarcoGorelli"},"datePublished":"2024-10-27T09:07:54Z","url":"https://github.com/plotly/plotly.py/issues/4836"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:26202897-71a0-6fd0-4e00-6962c1979bd1 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 888C:215B92:1E242DE:2816C9C:6B017073 |
| html-safe-nonce | 563e79eb7ea8ec527a2049e7392adeda6d95c5b21651259b5d87dd2e5286c947 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4ODhDOjIxNUI5MjoxRTI0MkRFOjI4MTZDOUM6NkIwMTcwNzMiLCJ2aXNpdG9yX2lkIjoiMzUzNDM3Mzc1OTg0NDcwODQ2NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 0eed1338b349b16ea81378e1d6b2412d949c09b67f1abf04ee97fa522ea196e8 |
| hovercard-subject-tag | issue:2616438099 |
| 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/plotly/plotly.py/4836/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a74b8dfe177b2ccf6bc5650344cff82a69e7dfdcd06236a72e6353d434bc6e87/plotly/plotly.py/issues/4836 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a74b8dfe177b2ccf6bc5650344cff82a69e7dfdcd06236a72e6353d434bc6e87/plotly/plotly.py/issues/4836 |
| og:image:alt | As far as I can tell, the lines plotly.py/packages/python/plotly/_plotly_utils/basevalidators.py Lines 101 to 108 in 960adb9 elif v.dtype.kind == "M": # Convert datetime Series/Index to numpy array... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | MarcoGorelli |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/plotly/plotly.py git https://github.com/plotly/plotly.py.git |
| octolytics-dimension-user_id | 5997976 |
| octolytics-dimension-user_login | plotly |
| octolytics-dimension-repository_id | 14579099 |
| octolytics-dimension-repository_nwo | plotly/plotly.py |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 14579099 |
| octolytics-dimension-repository_network_root_nwo | plotly/plotly.py |
| 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 | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width