pylhc / omc3

Python 3 codes for beam optics measurements and corrections in circular particle accelerators

Home Page:https://pylhc.github.io/omc3/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fix use of .loc[] in sensitive places for pandas

fsoubelet opened this issue · comments

In some places, the use of .loc[] on pandas dataframes with list objects is a problem as some of the elements might not be found in the Index, which raises since 1.0.0. Example below:

KeyError: "Passing list-likes to .loc or [] with any missing labels is no longer supported.
The following labels were missing: Index(['BPTUH.A4L5.B1', 'BPTDH.A4L5.B1', 'BPTUV.A4L5.B1', 'BPTDV.A4L5.B1',\n       'BPMWK.1L5',\n       ...\n       'BPTUV.A4L2.B1', 'BPTDV.A4L2.B1', 'BPMSW.1L2.B1_DOROS',\n       'BPMSW.1R2.B1_DOROS', 'LHCB1IP3_P_'],\n      dtype='object', length=37).
See https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#deprecate-loc-reindex-listlike"

Clickable link from the error message.

I have encountered the issue in rdt.py and crdt.py for instance.

To add some clarification: this happened to me while using omc3 for optics analysis on MAD-X tracking data.

Even using the omc3-created model itself to define my observation points, by default MAD-X includes the start of machine in trackone and I find myself with a LHCB1IP3_P_ point, which of course is not found in the bpm names when performing the aforementioned operations.

If someone know of a way for MAD-X not to include start of machine point, this could be a workaround to the issue for now.