René's URL Explorer Experiment


Title: `PlotlyJSONEncoder` always casts values to float64 due to using `tolist()` · Issue #3232 · plotly/plotly.py · GitHub

Open Graph Title: `PlotlyJSONEncoder` always casts values to float64 due to using `tolist()` · Issue #3232 · plotly/plotly.py

X Title: `PlotlyJSONEncoder` always casts values to float64 due to using `tolist()` · Issue #3232 · plotly/plotly.py

Description: Regarding the numpy floating point precision and that PlotlyJSONEncoder always casts those to float64 due to using tolist()... This had always bugged me, as it resulted in much larger exports (i.e. html / ipynb file sizes) than necessary...

Open Graph Description: Regarding the numpy floating point precision and that PlotlyJSONEncoder always casts those to float64 due to using tolist()... This had always bugged me, as it resulted in much larger exports (i.e....

X Description: Regarding the numpy floating point precision and that PlotlyJSONEncoder always casts those to float64 due to using tolist()... This had always bugged me, as it resulted in much larger exports (i.e....

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`PlotlyJSONEncoder` always casts values to float64 due to using `tolist()`","articleBody":"Regarding the numpy floating point precision and that `PlotlyJSONEncoder` always casts those to float64 due to using `tolist()`...\r\n\r\nThis had always bugged me, as it resulted in much larger exports (i.e. html / ipynb file sizes) than necessary (when float16 or float32 is sufficient) and affected not only coordinate data, but also marker sizes, meta info, etc.\r\n\r\nJust in case the plotly.py devs or others are interested: I had found a way to avoid this number inflation by modifying (& monkey patching) the [`encode_as_list` method](https://github.com/plotly/plotly.py/blob/340aed33bf116530a574badde64e867175c067ad/packages/python/plotly/_plotly_utils/utils.py#L147):\r\n\r\n```python\r\n@staticmethod\r\ndef encode_as_list_patch(obj):\r\n    \"\"\"Attempt to use `tolist` method to convert to normal Python list.\"\"\"\r\n    if hasattr(obj, \"tolist\"):\r\n\r\n        numpy = get_module(\"numpy\")\r\n        try:\r\n            if isinstance(obj, numpy.ndarray) \\\r\n               and obj.dtype == numpy.float32 or obj.dtype == numpy.float16 \\\r\n               and obj.flags.contiguous:\r\n                return [float('%s' % x) for x in obj]\r\n        except AttributeError:\r\n            raise NotEncodable\r\n\r\n        return obj.tolist()\r\n    else:\r\n        raise NotEncodable\r\n```\r\nIt's about 30-50x slower than `.tolist()`, but - being in the order of a few μs - still much faster than the json encoding, with the benefit of ~3x smaller exports.\r\n\r\nI always wanted to report this, and this PR revived the topic. Could this be relevant for a new issue (especially since orjson will not become the default)?\r\n\r\nFYI: for reference, a quick search revealed that a patch of encode_as_list was already suggested before: https://github.com/plotly/plotly.py/issues/1842#issuecomment-549401190, in the context of treating inf & NaN, which got brought up again in https://github.com/plotly/plotly.py/pull/2880#issuecomment-726860782.\r\n\r\n_Originally posted by @mherrmann3 in https://github.com/plotly/plotly.py/issues/2955#issuecomment-856651213_","author":{"url":"https://github.com/nicolaskruchten","@type":"Person","name":"nicolaskruchten"},"datePublished":"2021-06-08T11:58:14Z","url":"https://github.com/plotly/plotly.py/issues/3232"}

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:d546e268-c880-2685-551b-3ac1c8b9683a
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idCB90:25598F:153B5AA:1C08207:6B012C2D
html-safe-nonce3becd32295be586f69356226b9ecde12d9ec41fc5cff4203a328a7c561cfe44c
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQjkwOjI1NTk4RjoxNTNCNUFBOjFDMDgyMDc6NkIwMTJDMkQiLCJ2aXNpdG9yX2lkIjoiMTM2MTc1MDIzMzc0MjEyNjEyNSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacb7fb700ebd0bc2d17cbe18184dbc10a8b12c29779cc97058694a03e1d3914f3c
hovercard-subject-tagissue:914919082
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/3232/issue_layout
twitter:imagehttps://opengraph.githubassets.com/df1072c1247583de727d450acfb12ce545b86555f35308477f78172b43707a88/plotly/plotly.py/issues/3232
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/df1072c1247583de727d450acfb12ce545b86555f35308477f78172b43707a88/plotly/plotly.py/issues/3232
og:image:altRegarding the numpy floating point precision and that PlotlyJSONEncoder always casts those to float64 due to using tolist()... This had always bugged me, as it resulted in much larger exports (i.e....
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamenicolaskruchten
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/3232#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fplotly%2Fplotly.py%2Fissues%2F3232
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%2F3232
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/3232
Reloadhttps://github.com/plotly/plotly.py/issues/3232
Reloadhttps://github.com/plotly/plotly.py/issues/3232
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/3232
New issuehttps://github.com/login?return_to=https://github.com/plotly/plotly.py/issues/3232
PlotlyJSONEncoder always casts values to float64 due to using tolist()https://github.com/plotly/plotly.py/issues/3232#top
P3backloghttps://github.com/plotly/plotly.py/issues?q=state%3Aopen%20label%3A%22P3%22
featuresomething newhttps://github.com/plotly/plotly.py/issues?q=state%3Aopen%20label%3A%22feature%22
https://github.com/nicolaskruchten
nicolaskruchtenhttps://github.com/nicolaskruchten
on Jun 8, 2021https://github.com/plotly/plotly.py/issues/3232#issue-914919082
encode_as_list methodhttps://github.com/plotly/plotly.py/blob/340aed33bf116530a574badde64e867175c067ad/packages/python/plotly/_plotly_utils/utils.py#L147
#1842 (comment)https://github.com/plotly/plotly.py/issues/1842#issuecomment-549401190
#2880 (comment)https://github.com/plotly/plotly.py/pull/2880#issuecomment-726860782
@mherrmann3https://github.com/mherrmann3
#2955 (comment)https://github.com/plotly/plotly.py/pull/2955#issuecomment-856651213
https://github.com/RRiva
RRivahttps://github.com/RRiva
on Sep 28, 2022https://github.com/plotly/plotly.py/issues/3232#issuecomment-1260542606
@nicolaskruchtenhttps://github.com/nicolaskruchten
https://github.com/gvwilson
gvwilsonhttps://github.com/gvwilson
on Jul 5, 2024https://github.com/plotly/plotly.py/issues/3232#issuecomment-2210796869
@gvwilsonhttps://github.com/gvwilson
gvwilsonhttps://github.com/gvwilson
completedhttps://github.com/plotly/plotly.py/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Jul 5, 2024https://github.com/plotly/plotly.py/issues/3232#event-13405616632
https://github.com/RRiva
RRivahttps://github.com/RRiva
on Jul 8, 2024https://github.com/plotly/plotly.py/issues/3232#issuecomment-2213187856
@gvwilsonhttps://github.com/gvwilson
https://github.com/gvwilson
gvwilsonhttps://github.com/gvwilson
on Jul 8, 2024https://github.com/plotly/plotly.py/issues/3232#issuecomment-2213781346
@RRivahttps://github.com/RRiva
@gvwilsonhttps://github.com/gvwilson
gvwilsonhttps://github.com/gvwilson
on Jul 8, 2024https://github.com/plotly/plotly.py/issues/3232#event-13422467502
gvwilsonhttps://github.com/gvwilson
marthacryanhttps://github.com/marthacryan
on Jul 8, 2024https://github.com/plotly/plotly.py/issues/3232#event-13422470817
https://github.com/RRiva
RRivahttps://github.com/RRiva
on Jul 8, 2024https://github.com/plotly/plotly.py/issues/3232#issuecomment-2213785486
gvwilsonhttps://github.com/gvwilson
P3backloghttps://github.com/plotly/plotly.py/issues?q=state%3Aopen%20label%3A%22P3%22
on Aug 12, 2024https://github.com/plotly/plotly.py/issues/3232#event-13849377512
gvwilsonhttps://github.com/gvwilson
on Aug 12, 2024https://github.com/plotly/plotly.py/issues/3232#event-13851738965
gvwilsonhttps://github.com/gvwilson
marthacryanhttps://github.com/marthacryan
on Aug 12, 2024https://github.com/plotly/plotly.py/issues/3232#event-13851739768
gvwilsonhttps://github.com/gvwilson
featuresomething newhttps://github.com/plotly/plotly.py/issues?q=state%3Aopen%20label%3A%22feature%22
on Aug 12, 2024https://github.com/plotly/plotly.py/issues/3232#event-13851740797
Sign up for freehttps://github.com/signup?return_to=https://github.com/plotly/plotly.py/issues/3232
Sign in to commenthttps://github.com/login?return_to=https://github.com/plotly/plotly.py/issues/3232
P3backloghttps://github.com/plotly/plotly.py/issues?q=state%3Aopen%20label%3A%22P3%22
featuresomething newhttps://github.com/plotly/plotly.py/issues?q=state%3Aopen%20label%3A%22feature%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.