René's URL Explorer Experiment


Title: control.timeresp.TimeResponseData.to_pandas() failing · Issue #1087 · python-control/python-control · GitHub

Open Graph Title: control.timeresp.TimeResponseData.to_pandas() failing · Issue #1087 · python-control/python-control

X Title: control.timeresp.TimeResponseData.to_pandas() failing · Issue #1087 · python-control/python-control

Description: Hi, today I was using some step responses and noticed that the .to_pandas() is not actually working. I managed to workaround it by creating my own function to translate the response into a dataframe. Example of code not working: import c...

Open Graph Description: Hi, today I was using some step responses and noticed that the .to_pandas() is not actually working. I managed to workaround it by creating my own function to translate the response into a datafram...

X Description: Hi, today I was using some step responses and noticed that the .to_pandas() is not actually working. I managed to workaround it by creating my own function to translate the response into a datafram...

Opengraph URL: https://github.com/python-control/python-control/issues/1087

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"control.timeresp.TimeResponseData.to_pandas() failing","articleBody":"Hi, today I was using some step responses and noticed that the `.to_pandas()` is not actually working.\r\n\r\nI managed to workaround it by creating my own function to translate the response into a dataframe.\r\n\r\nExample of code not working:\r\n\r\n```Python\r\nimport control as ct\r\nimport numpy as np\r\n\r\nmodel = ct.rss(states=['x0', 'x1'], outputs=['y0', 'y1'], inputs=['u0', 'u1'], name='My Model')\r\n\r\nT = np.linspace(0, 10, 100, endpoint=False)\r\nX0 = np.zeros(model.nstates)\r\n\r\nres = ct.step_response(model, T=T, X0=X0, input=0)\r\n\r\ndf = res.to_pandas()\r\n```\r\n\r\nError:\r\n\r\n```python\r\n---------------------------------------------------------------------------\r\nValueError                                Traceback (most recent call last)\r\nCell In[140], line 6\r\n      3 T = np.linspace(0, 10, 100, endpoint=False)\r\n      4 X0 = np.zeros(model.nstates)\r\n----\u003e 6 res = ct.step_response(model, T=T, X0=X0, input=0).to_pandas()\r\n\r\nFile ~.env/lib/python3.10/site-packages/control/timeresp.py:723, in TimeResponseData.to_pandas(self)\r\n    719 if self.nstates \u003e 0:\r\n    720     data.update(\r\n    721         {name: self.x[i] for i, name in enumerate(self.state_labels)})\r\n--\u003e 723 return pandas.DataFrame(data)\r\n\r\nFile ~.env/lib/python3.10/site-packages/pandas/core/frame.py:778, in DataFrame.__init__(self, data, index, columns, dtype, copy)\r\n    772     mgr = self._init_mgr(\r\n    773         data, axes={\"index\": index, \"columns\": columns}, dtype=dtype, copy=copy\r\n    774     )\r\n    776 elif isinstance(data, dict):\r\n    777     # GH#38939 de facto copy defaults to False only in non-dict cases\r\n--\u003e 778     mgr = dict_to_mgr(data, index, columns, dtype=dtype, copy=copy, typ=manager)\r\n    779 elif isinstance(data, ma.MaskedArray):\r\n    780     from numpy.ma import mrecords\r\n\r\nFile ~.env/lib/python3.10/site-packages/pandas/core/internals/construction.py:503, in dict_to_mgr(data, index, columns, dtype, typ, copy)\r\n    499     else:\r\n    500         # dtype check to exclude e.g. range objects, scalars\r\n    501         arrays = [x.copy() if hasattr(x, \"dtype\") else x for x in arrays]\r\n--\u003e 503 return arrays_to_mgr(arrays, columns, index, dtype=dtype, typ=typ, consolidate=copy)\r\n\r\nFile ~.env/lib/python3.10/site-packages/pandas/core/internals/construction.py:114, in arrays_to_mgr(arrays, columns, index, dtype, verify_integrity, typ, consolidate)\r\n    111 if verify_integrity:\r\n    112     # figure out the index, if necessary\r\n    113     if index is None:\r\n--\u003e 114         index = _extract_index(arrays)\r\n    115     else:\r\n    116         index = ensure_index(index)\r\n\r\nFile ~.env/lib/python3.10/site-packages/pandas/core/internals/construction.py:664, in _extract_index(data)\r\n    662         raw_lengths.append(len(val))\r\n    663     elif isinstance(val, np.ndarray) and val.ndim \u003e 1:\r\n--\u003e 664         raise ValueError(\"Per-column arrays must each be 1-dimensional\")\r\n    666 if not indexes and not raw_lengths:\r\n    667     raise ValueError(\"If using all scalar values, you must pass an index\")\r\n\r\nValueError: Per-column arrays must each be 1-dimensional\r\n```\r\n\r\n---\r\n\r\nThe code I'm using to workaround it is the following:\r\n\r\n```Python\r\n\r\nimport matplotlib.pyplot as plt\r\nimport control as ct\r\nimport numpy as np\r\n\r\ndef step_response_to_pandas(step_response):\r\n    return pd.DataFrame(\r\n        {'trace_label': np.array([[label] * (len(res.time)) for label in res.trace_labels]).ravel()} |\r\n        {'time': res.time.repeat(len(res.trace_labels))} |\r\n        {label: res.inputs[i].ravel() for i,label in enumerate(res.input_labels)} |\r\n        {label: res.outputs[i].ravel() for i,label in enumerate(res.output_labels)} |\r\n        {label: res.states[i].ravel() for i,label in enumerate(res.state_labels)}\r\n    )\r\n\r\ndef plot_step_response_dataframe(df):\r\n    grouped = df.groupby(level='trace_label')\r\n    row_size = 1\r\n\r\n    for trace_label, group in grouped:\r\n        fig, axes = plt.subplots(len(group.columns), 1, figsize=(6.4, len(group.columns) * row_size), sharex=True)\r\n        fig.suptitle(f'Trace: {trace_label}', fontsize=16)\r\n        \r\n        if len(group.columns) == 1:\r\n            axes = [axes]\r\n        \r\n        for ax, (signal_name, signal_data) in zip(axes, group.items()):\r\n            ax.plot(group.index.get_level_values('time'), signal_data, label=signal_name)\r\n            ax.grid(True)\r\n            ax.set_ylabel(signal_name)\r\n        \r\n        axes[-1].set_xlabel('Time')\r\n        \r\n        plt.tight_layout()\r\n        plt.show()\r\n\r\n\r\nmodel = ct.rss(states=['x0', 'x1'], outputs=['y0', 'y1'], inputs=['u0', 'u1'], name='My Model')\r\n\r\nT = np.linspace(0, 10, 100, endpoint=False)\r\nX0 = np.zeros(model.nstates)\r\n\r\nres = ct.step_response(model, T=T, X0=X0)\r\n\r\ndf = step_response_to_pandas(res)\r\ndf = df.set_index(['trace_label', 'time'])\r\n\r\nplot_step_response_dataframe(df)\r\n\r\ndisplay(df)\r\n\r\n```\r\n\r\nExample of output:\r\n\r\n![image](https://github.com/user-attachments/assets/caf0cbf0-29af-4478-adc1-14169a36013c)\r\n![image](https://github.com/user-attachments/assets/5028e6e8-4a29-46cb-aeef-a4233cfea04c)\r\n![image](https://github.com/user-attachments/assets/29ea4ddf-325c-45d8-9470-1f993ec20283)\r\n\r\n\r\n---\r\n\r\nThanks!\r\n","author":{"url":"https://github.com/joaoantoniocardoso","@type":"Person","name":"joaoantoniocardoso"},"datePublished":"2024-12-30T19:41:30.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/1087/python-control/issues/1087"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:aaecc92e-8586-c8f6-bc2e-777fa16e8bb2
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idD764:2F02EE:2A12D2C:39209C8:6979B906
html-safe-nonce8e40d55a1c024314dcda64aa17360954f97ace36dc61285e37f8fdd5a0f2d2a2
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENzY0OjJGMDJFRToyQTEyRDJDOjM5MjA5Qzg6Njk3OUI5MDYiLCJ2aXNpdG9yX2lkIjoiMzc2OTc5OTk3MjgyOTA4NDIyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmacdf0c0a487364635aac24d7d7a44b2bd5e00dba43bc150e177921708dfed5c184
hovercard-subject-tagissue:2763624510
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/python-control/python-control/1087/issue_layout
twitter:imagehttps://opengraph.githubassets.com/daf1a22120acc89e873c6bc97888ccfc86be8c832a858db57383e01bcce4c5e7/python-control/python-control/issues/1087
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/daf1a22120acc89e873c6bc97888ccfc86be8c832a858db57383e01bcce4c5e7/python-control/python-control/issues/1087
og:image:altHi, today I was using some step responses and noticed that the .to_pandas() is not actually working. I managed to workaround it by creating my own function to translate the response into a datafram...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamejoaoantoniocardoso
hostnamegithub.com
expected-hostnamegithub.com
Nonec049b65ec7e54cbf2521f5a560b6527714c612b0bd169188e2ea6e16f83bd5f4
turbo-cache-controlno-preview
go-importgithub.com/python-control/python-control git https://github.com/python-control/python-control.git
octolytics-dimension-user_id2285872
octolytics-dimension-user_loginpython-control
octolytics-dimension-repository_id22791752
octolytics-dimension-repository_nwopython-control/python-control
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id22791752
octolytics-dimension-repository_network_root_nwopython-control/python-control
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
release87b137883e35e2766c3d0f6a257c4044f6390b83
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python-control/python-control/issues/1087#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython-control%2Fpython-control%2Fissues%2F1087
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
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
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://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/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython-control%2Fpython-control%2Fissues%2F1087
Sign up https://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=python-control%2Fpython-control
Reloadhttps://github.com/python-control/python-control/issues/1087
Reloadhttps://github.com/python-control/python-control/issues/1087
Reloadhttps://github.com/python-control/python-control/issues/1087
python-control https://github.com/python-control
python-controlhttps://github.com/python-control/python-control
Notifications https://github.com/login?return_to=%2Fpython-control%2Fpython-control
Fork 447 https://github.com/login?return_to=%2Fpython-control%2Fpython-control
Star 2k https://github.com/login?return_to=%2Fpython-control%2Fpython-control
Code https://github.com/python-control/python-control
Issues 87 https://github.com/python-control/python-control/issues
Pull requests 8 https://github.com/python-control/python-control/pulls
Discussions https://github.com/python-control/python-control/discussions
Actions https://github.com/python-control/python-control/actions
Projects 0 https://github.com/python-control/python-control/projects
Wiki https://github.com/python-control/python-control/wiki
Security 0 https://github.com/python-control/python-control/security
Insights https://github.com/python-control/python-control/pulse
Code https://github.com/python-control/python-control
Issues https://github.com/python-control/python-control/issues
Pull requests https://github.com/python-control/python-control/pulls
Discussions https://github.com/python-control/python-control/discussions
Actions https://github.com/python-control/python-control/actions
Projects https://github.com/python-control/python-control/projects
Wiki https://github.com/python-control/python-control/wiki
Security https://github.com/python-control/python-control/security
Insights https://github.com/python-control/python-control/pulse
New issuehttps://github.com/login?return_to=https://github.com/python-control/python-control/issues/1087
New issuehttps://github.com/login?return_to=https://github.com/python-control/python-control/issues/1087
#1088https://github.com/python-control/python-control/pull/1088
control.timeresp.TimeResponseData.to_pandas() failinghttps://github.com/python-control/python-control/issues/1087#top
#1088https://github.com/python-control/python-control/pull/1088
https://github.com/murrayrm
bughttps://github.com/python-control/python-control/issues?q=state%3Aopen%20label%3A%22bug%22
https://github.com/joaoantoniocardoso
https://github.com/joaoantoniocardoso
joaoantoniocardosohttps://github.com/joaoantoniocardoso
on Dec 30, 2024https://github.com/python-control/python-control/issues/1087#issue-2763624510
https://private-user-images.githubusercontent.com/5920286/399360404-caf0cbf0-29af-4478-adc1-14169a36013c.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Njk1ODUyMDMsIm5iZiI6MTc2OTU4NDkwMywicGF0aCI6Ii81OTIwMjg2LzM5OTM2MDQwNC1jYWYwY2JmMC0yOWFmLTQ0NzgtYWRjMS0xNDE2OWEzNjAxM2MucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI2MDEyOCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNjAxMjhUMDcyMTQzWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MzhhZDUwNGNhMTczZDg0MTc5NzcwNGJkNmVhNWQ0NWJmMjYxMGQ1ZTAyYzExNmMyZDQ3YjUxM2VhZTY4NGMwNiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.YdfA6NR2TQhiPe6uRMRqEWdAvRSqd_tLHDuuG64eNOo
https://private-user-images.githubusercontent.com/5920286/399360425-5028e6e8-4a29-46cb-aeef-a4233cfea04c.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Njk1ODUyMDMsIm5iZiI6MTc2OTU4N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TVkOGI5OTAxZTIyMDQzNjU4MmE4YTVlMDQ5MDk0ZmM5YmNlN2UzNjcxNDEwOTgxOGQ4MzdhNjk4NzdhOGM5ZCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.RQWPyLiYiMncWS-Qhg_mC5SOTFBclt4WgiEtXHFZXfY
murrayrmhttps://github.com/murrayrm
bughttps://github.com/python-control/python-control/issues?q=state%3Aopen%20label%3A%22bug%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.