Title: Usage of a pandas.Index slows down figure generation of plotly · Issue #4250 · plotly/plotly.py · GitHub
Open Graph Title: Usage of a pandas.Index slows down figure generation of plotly · Issue #4250 · plotly/plotly.py
X Title: Usage of a pandas.Index slows down figure generation of plotly · Issue #4250 · plotly/plotly.py
Description: Hello everyone, I have noticed that the generation of a plotly figure takes ~20 longer if using the index of a pandas DataFrame. I have generated a minimal working example: import pandas as pd import numpy as np from plotly.subplots impo...
Open Graph Description: Hello everyone, I have noticed that the generation of a plotly figure takes ~20 longer if using the index of a pandas DataFrame. I have generated a minimal working example: import pandas as pd impo...
X Description: Hello everyone, I have noticed that the generation of a plotly figure takes ~20 longer if using the index of a pandas DataFrame. I have generated a minimal working example: import pandas as pd impo...
Opengraph URL: https://github.com/plotly/plotly.py/issues/4250
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Usage of a pandas.Index slows down figure generation of plotly","articleBody":"Hello everyone,\r\n\r\nI have noticed that the generation of a plotly figure takes ~20 longer if using the index of a pandas DataFrame. I have generated a minimal working example:\r\n\r\n```\r\nimport pandas as pd\r\nimport numpy as np\r\nfrom plotly.subplots import make_subplots\r\nimport plotly.graph_objects as go\r\nfrom datetime import datetime\r\nimport time\r\n\r\nsize = 10000\r\ndf = pd.DataFrame({\"col1\": np.random.random(size),\r\n \"col2\": np.random.random(size),\r\n \"col3\": np.random.random(size),\r\n \"col4\": np.random.random(size)}, index=pd.date_range(datetime(2020, 1, 1), periods=size))\r\n\r\n# Preloads some plotly routines, which would otherwise be in the timing.\r\nfig = make_subplots()\r\n\r\ndef basic1(data):\r\n start_time = time.perf_counter()\r\n # fig = go.Figure()\r\n fig = make_subplots()\r\n for col in data:\r\n fig.add_trace(go.Scattergl(x=data.index, y=data[col], name=\"ist_mpe\"))\r\n # fig.show(\"browser\")\r\n print(f\"Elapsed time: {time.perf_counter() - start_time}\")\r\n\r\n# Using the pandas DataFrame index\r\nbasic1(df)\r\n\r\n\r\ndef basic2(data):\r\n start_time = time.perf_counter()\r\n # fig = go.Figure()\r\n fig = make_subplots()\r\n for col in data:\r\n fig.add_trace(go.Scattergl(x=data.index.values, y=data[col], name=\"ist_mpe\"))\r\n # fig.show(\"browser\")\r\n print(f\"Elapsed time: {time.perf_counter() - start_time}\")\r\n\r\n# Manually changing the index to a numpy array\r\nbasic2(df)\r\n```\r\n\r\nOn my machine I get the following output:\r\n\r\n```\r\nElapsed time: 0.11946500000000004\r\nElapsed time: 0.0073545000000000416\r\n```\r\n\r\nThe second approach, in which I manually transform the pandas Index to a numpy array, is > 10 times faster. Internally plotly saves data as DataFrames, it seems weird that the use of the index has such an impact.\r\n\r\nNote, when using a tz-aware DatetimeIndex, the above approach will firstly transform the dates to UTC+0. \r\n\r\nUsed Versions:\r\n\r\n\r\n```\r\nPackage Version\r\n--------------- -------\r\nDateTime 5.1\r\nnumpy 1.24.3\r\npackaging 23.1\r\npandas 2.0.2\r\npip 23.0.1\r\nplotly 5.15.0\r\npython-dateutil 2.8.2\r\npytz 2023.3\r\nsetuptools 67.6.1\r\nsix 1.16.0\r\ntenacity 8.2.2\r\ntzdata 2023.3\r\nwheel 0.40.0\r\nzope.interface 6.0\r\n```\r\n","author":{"url":"https://github.com/SergejKr","@type":"Person","name":"SergejKr"},"datePublished":"2023-06-15T14:01:41Z","url":"https://github.com/plotly/plotly.py/issues/4250"}
| 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:475837af-2286-cabc-9740-5f2416060586 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D4D0:2EF149:4CA734:64705E:6B01775A |
| html-safe-nonce | 40c19c9636dbd60ff03bce31dc49d4c2496e5d0b2a600135290b241878605870 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENEQwOjJFRjE0OTo0Q0E3MzQ6NjQ3MDVFOjZCMDE3NzVBIiwidmlzaXRvcl9pZCI6IjY1MDAzODA5MDIwNDI5OTA0MjYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 8e23ccf75b38287a16573ce64df850f54fa3bcbdccc0ec95a76ee0908772a8e2 |
| hovercard-subject-tag | issue:1758910812 |
| 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/4250/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ef75ea8ea73442e945adee53914809a2e1bc905794b2219820c98c489ab62350/plotly/plotly.py/issues/4250 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ef75ea8ea73442e945adee53914809a2e1bc905794b2219820c98c489ab62350/plotly/plotly.py/issues/4250 |
| og:image:alt | Hello everyone, I have noticed that the generation of a plotly figure takes ~20 longer if using the index of a pandas DataFrame. I have generated a minimal working example: import pandas as pd impo... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | SergejKr |
| 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