René's URL Explorer Experiment


Title: [BUG]: Timezone-aware pandas DatetimeIndex as x makes figure creation and to_json() ~30x slower · Issue #5864 · plotly/plotly.py · GitHub

Open Graph Title: [BUG]: Timezone-aware pandas DatetimeIndex as x makes figure creation and to_json() ~30x slower · Issue #5864 · plotly/plotly.py

X Title: [BUG]: Timezone-aware pandas DatetimeIndex as x makes figure creation and to_json() ~30x slower · Issue #5864 · plotly/plotly.py

Description: Description Plotting a timeseries the usual way, go.Scatter(x=series.index, y=series), is very slow if the index is a timezone-aware pd.DatetimeIndex. For 100,000 points, go.Figure(...) plus fig.to_json() takes about 2.3 s. With the same...

Open Graph Description: Description Plotting a timeseries the usual way, go.Scatter(x=series.index, y=series), is very slow if the index is a timezone-aware pd.DatetimeIndex. For 100,000 points, go.Figure(...) plus fig.to...

X Description: Description Plotting a timeseries the usual way, go.Scatter(x=series.index, y=series), is very slow if the index is a timezone-aware pd.DatetimeIndex. For 100,000 points, go.Figure(...) plus fig.to...

Opengraph URL: https://github.com/plotly/plotly.py/issues/5864

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[BUG]: Timezone-aware pandas DatetimeIndex as x makes figure creation and to_json() ~30x slower","articleBody":"### Description\n\nPlotting a timeseries the usual way, `go.Scatter(x=series.index, y=series)`, is very slow if the index is a\ntimezone-aware `pd.DatetimeIndex`. For 100,000 points, `go.Figure(...)` plus `fig.to_json()` takes about 2.3 s.\nWith the same timestamps as a timezone-aware `pd.Series`, or as a timezone-naive `DatetimeIndex`, it takes\nabout 0.05 to 0.08 s.\n\nTimezone-aware indexes are common: data from databases, APIs or `pd.to_datetime(..., utc=True)` usually comes with\n`datetime64[ns, UTC]` timestamps, and `series.index` is what most code passes as `x`.\n\n#4250 reported that a `pandas.Index` slows down figure creation. It was closed after the switch to narwhals in\nplotly 6, based on measurements with a timezone-naive index. The reporter had mentioned timezone-aware\nindexes, but that case was not measured again. It is still slow in plotly 6.9.0 and 7.1.0.\n\n### Screenshots/Video\n\nNot applicable, this is about performance.\n\n### Steps to reproduce\n\nRun this script:\n\n```python\nimport time\n\nimport numpy as np\nimport pandas as pd\nimport plotly\nimport plotly.graph_objects as go\nimport plotly.io as pio\n\nn = 100_000\nindex = pd.date_range(\"2024-01-01\", periods=n, freq=\"min\", tz=\"Europe/Berlin\")\ny = np.random.default_rng(0).standard_normal(n)\n\n\ndef bench(label, x):\n    t0 = time.perf_counter()\n    fig = go.Figure(go.Scatter(x=x, y=y))\n    t1 = time.perf_counter()\n    fig.to_json()\n    t2 = time.perf_counter()\n    print(f\"{label:\u003c24} x dtype: {str(fig.data[0].x.dtype):\u003c15} Figure(): {t1 - t0:6.3f} s   to_json(): {t2 - t1:6.3f} s\")\n\n\nprint(\"plotly\", plotly.__version__, \"| pandas\", pd.__version__, \"| json engine\", pio.json.config.default_engine)\nbench(\"tz-naive DatetimeIndex\", index.tz_localize(None))\nbench(\"tz-aware Series\", index.to_series())\nbench(\"tz-aware DatetimeIndex\", index)\n```\n\nOutput (Python 3.14, Linux):\n\n```\nplotly 6.9.0 | pandas 3.1.0 | json engine auto\ntz-naive DatetimeIndex   x dtype: datetime64[us]  Figure():  0.035 s   to_json():  0.042 s\ntz-aware Series          x dtype: datetime64[us]  Figure():  0.008 s   to_json():  0.039 s\ntz-aware DatetimeIndex   x dtype: object          Figure():  0.902 s   to_json():  1.363 s\n\nplotly 7.1.0 | pandas 3.1.0 | json engine auto\ntz-naive DatetimeIndex   x dtype: datetime64[us]  Figure():  0.033 s   to_json():  0.042 s\ntz-aware Series          x dtype: datetime64[us]  Figure():  0.008 s   to_json():  0.038 s\ntz-aware DatetimeIndex   x dtype: object          Figure():  0.894 s   to_json():  1.372 s\n```\n\nIt is the same with pandas 2.3.3 (0.42 s + 0.72 s for the timezone-aware index), and with orjson installed\n(0.91 s + 1.01 s).\n\n### Notes\n\n#### Cause\n\n`copy_to_readonly_numpy_array` in `_plotly_utils/basevalidators.py` converts the values with narwhals.\nFor a timezone-aware datetime Series, it calls `replace_time_zone(None)` (\"so that local time is displayed\")\nand gets a `datetime64` array. A `pd.Index` is not a narwhals Series, so `nw.from_native(..., pass_through=True)`\nreturns it unchanged, and `np.array(v)` then gives an object array of `pd.Timestamp`.\n\nThat object array is handled one element at a time:\n\n- `copy.deepcopy` copies every `Timestamp` in `BaseFigure.__init__` and again in `to_dict()`, which `to_json()` calls.\n- `PlotlyJSONEncoder.default` encodes every `Timestamp`, going through `encode_as_pandas`, `encode_as_numpy` and\n  `encode_as_datetime` for each one.\n\n#### Expected behavior\n\nA timezone-aware `DatetimeIndex` should be as fast as a timezone-aware Series.\n\nThe plot would not change. Today the index is serialized as strings with UTC offset, like\n`\"2024-01-01T00:00:00+01:00\"`. plotly.js ignores the offset and shows the wall-clock time, which is exactly what the\nSeries path produces with `replace_time_zone(None)`. Only the JSON would change, losing the offset suffix.\n\n#### Possible fix\n\nIn `copy_to_readonly_numpy_array`, handle a timezone-aware pandas `DatetimeIndex` like the Series path does:\n\n```python\npd = get_module(\"pandas\", should_load=False)\nif pd is not None and isinstance(v, pd.DatetimeIndex) and v.tz is not None:\n    # Remove time zone so that local time is displayed, like for Series\n    v = v.tz_localize(None)\n```\n\nPlaced directly before `nw.from_native(...)`, this brings the timezone-aware index in the example above down to\n0.002 s for `Figure()` and 0.038 s for `to_json()`. Alternatively, convert any pandas `Index` to a Series before\n`nw.from_native`, so that indexes always take the same path as Series.\n\nWorkaround until then: pass `x=series.index.tz_localize(None)` or `x=series.index.to_series()`.\n\n#### Related\n\n- #4250: \"Usage of a pandas.Index slows down figure generation of plotly\". Closed for plotly 6.0.0rc0, measured with a\n  timezone-naive index.\n- #4836 / #4790: switched the Series path to narwhals and `datetime64`. This made Series and naive indexes fast, but\n  not timezone-aware indexes.\n- #5813 (open): serializes figures without deep copying them. This would reduce the `to_json()` part, but the index\n  would still be an object array of Timestamps, deep-copied in `Figure()` and encoded one by one.\n\n#### Disclaimer\nClaude Code helped in finding, analyzing, reproducing and in writting this issue. I personally checked the reproduction code and will answer personally to questions!","author":{"url":"https://github.com/stewit","@type":"Person","name":"stewit"},"datePublished":"2026-11-02T08:08:06Z","url":"https://github.com/plotly/plotly.py/issues/5864"}

react-profiling0
react-import-mapreact,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-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:23a0efd0-da67-908b-1a98-0ed2b49d1730
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idC196:D5AA4:1DC4A30:279D1E9:6B0162B2
html-safe-noncefdcf43f149f13e802f80d96337de003870f6dc1a808b418f57d6612bc8d2825b
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMTk2OkQ1QUE0OjFEQzRBMzA6Mjc5RDFFOTo2QjAxNjJCMiIsInZpc2l0b3JfaWQiOiI1NzYxMTUzOTU3Nzg0MDUwNDIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac5305f64cb36afeb891ee6d3fc787c576f7176d271c44acaad1d8a98113a79bd9
hovercard-subject-tagissue:6158676468
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/plotly/plotly.py/5864/issue_layout
twitter:imagehttps://opengraph.githubassets.com/9cff279d63151c40c5af35788faec6ff1cce90786831aa84805003cb4c74d653/plotly/plotly.py/issues/5864
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/9cff279d63151c40c5af35788faec6ff1cce90786831aa84805003cb4c74d653/plotly/plotly.py/issues/5864
og:image:altDescription Plotting a timeseries the usual way, go.Scatter(x=series.index, y=series), is very slow if the index is a timezone-aware pd.DatetimeIndex. For 100,000 points, go.Figure(...) plus fig.to...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamestewit
hostnamegithub.com
expected-hostnamegithub.com
Nonecc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c
turbo-cache-controlno-preview
go-importgithub.com/plotly/plotly.py git https://github.com/plotly/plotly.py.git
octolytics-dimension-user_id5997976
octolytics-dimension-user_loginplotly
octolytics-dimension-repository_id14579099
octolytics-dimension-repository_nwoplotly/plotly.py
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id14579099
octolytics-dimension-repository_network_root_nwoplotly/plotly.py
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release8c77c9e8439031ad54c75a250694842892f693e1
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/plotly/plotly.py/issues/5864#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fplotly%2Fplotly.py%2Fissues%2F5864
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fplotly%2Fplotly.py%2Fissues%2F5864
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=plotly%2Fplotly.py
Reloadhttps://github.com/plotly/plotly.py/issues/5864
Reloadhttps://github.com/plotly/plotly.py/issues/5864
Reloadhttps://github.com/plotly/plotly.py/issues/5864
plotlyhttps://github.com/plotly
plotly.pyhttps://github.com/plotly/plotly.py
Codehttps://github.com/plotly/plotly.py
Issues650 (650)https://github.com/plotly/plotly.py/issues
Pull requests83 (83)https://github.com/plotly/plotly.py/pulls
Actionshttps://github.com/plotly/plotly.py/actions
Security and qualityhttps://github.com/plotly/plotly.py/security
Insightshttps://github.com/plotly/plotly.py/insights
https://github.com/plotly/plotly.py
New issuehttps://github.com/login?return_to=https://github.com/plotly/plotly.py/issues/5864
New issuehttps://github.com/login?return_to=https://github.com/plotly/plotly.py/issues/5864
#5870https://github.com/plotly/plotly.py/pull/5870
[BUG]: Timezone-aware pandas DatetimeIndex as x makes figure creation and to_json() ~30x slowerhttps://github.com/plotly/plotly.py/issues/5864#top
#5870https://github.com/plotly/plotly.py/pull/5870
P3backloghttps://github.com/plotly/plotly.py/issues?q=state%3Aopen%20label%3A%22P3%22
bugsomething brokenhttps://github.com/plotly/plotly.py/issues?q=state%3Aopen%20label%3A%22bug%22
size: 3https://github.com/plotly/plotly.py/issues?q=state%3Aopen%20label%3A%22size%3A%203%22
https://github.com/stewit
stewithttps://github.com/stewit
on Nov 2, 2026https://github.com/plotly/plotly.py/issues/5864#issue-6158676468
#4250https://github.com/plotly/plotly.py/issues/4250
Usage of a pandas.Index slows down figure generation of plotly #4250https://github.com/plotly/plotly.py/issues/4250
Is v = np.array(v.dt.to_pydatetime()) still necessary? #4836https://github.com/plotly/plotly.py/issues/4836
feat: make plotly-express dataframe agnostic via narwhals #4790https://github.com/plotly/plotly.py/pull/4790
Serialize figures without deep copying them, add a msgspec engine #5813https://github.com/plotly/plotly.py/pull/5813
stewithttps://github.com/stewit
bugsomething brokenhttps://github.com/plotly/plotly.py/issues?q=state%3Aopen%20label%3A%22bug%22
on Nov 2, 2026https://github.com/plotly/plotly.py/issues/5864#event-34887466181
https://github.com/MarcoGorelli
MarcoGorellihttps://github.com/MarcoGorelli
on Nov 2, 2026https://github.com/plotly/plotly.py/issues/5864#issuecomment-6574905980
https://github.com/KoolADE85
KoolADE85https://github.com/KoolADE85
on Nov 2, 2026https://github.com/plotly/plotly.py/issues/5864#issuecomment-6587546064
libraries-dashboardhttps://github.com/apps/libraries-dashboard
P3backloghttps://github.com/plotly/plotly.py/issues?q=state%3Aopen%20label%3A%22P3%22
size: 3https://github.com/plotly/plotly.py/issues?q=state%3Aopen%20label%3A%22size%3A%203%22
on Nov 2, 2026https://github.com/plotly/plotly.py/issues/5864#event-34951654049
Sign up for freehttps://github.com/signup?return_to=https://github.com/plotly/plotly.py/issues/5864
Sign in to commenthttps://github.com/login?return_to=https://github.com/plotly/plotly.py/issues/5864
P3backloghttps://github.com/plotly/plotly.py/issues?q=state%3Aopen%20label%3A%22P3%22
bugsomething brokenhttps://github.com/plotly/plotly.py/issues?q=state%3Aopen%20label%3A%22bug%22
size: 3https://github.com/plotly/plotly.py/issues?q=state%3Aopen%20label%3A%22size%3A%203%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.