Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to get elements by (unique made) names from line.get_table() #561

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

eltos
Copy link
Member

@eltos eltos commented Dec 2, 2024

Description

Unique names from line.get_table() (and survey and ...) cause an error if trying to get the corresponding element via line[name].

While for line.get_table() there is env_names to help out, for survey there is nothing. Also, this is quite unintuitive behaviour.

line = xt.Line(
        elements = {"obm": xt.Bend(length=0.5)},
        element_names= ["obm","obm"]
    )
print(line.get_table())
line["obm::0"]
Table: 3 rows, 8 cols
name                   s element_type isthick isreplica parent_name iscollective env_name  
obm::0                 0 Bend            True     False None               False obm       
obm::1               0.5 Bend            True     False None               False obm       
_end_point             1                False     False None               False _end_point
KeyError: 'Name obm::0 not found'

The PR fixes this. See xsuite/xplt#31 (comment)

Closes xsuite/xplt#31

Checklist

Mandatory:

  • I have added tests to cover my changes
  • All the tests are passing, including my new ones
  • I described my changes in this PR description

Optional:

  • The code I wrote follows good style practices (see PEP 8 and PEP 20).
  • I have updated the docs in relation to my changes, if applicable
  • I have tested also GPU contexts

@eltos eltos changed the title Test line.get_table() unique names Allow to get elements by (unique made) names from line.get_table() Dec 2, 2024
@giadarol
Copy link
Member

giadarol commented Dec 6, 2024

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FloorPlot Repeated Elements
2 participants