Unicode strings and Mantid Tables

Expected behavior

I can access a table column as a list with the syntax MyTable.column[“f0.A”], even if writing code that is Python 3 compatible

Actual behavior

An error from Mantid that it doesn’t like Unicode strings as column headers:

TypeError: No registered converter was able to produce a C++ rvalue of type int from this Python object of type unicode
  File "<string>", line 14, in <module>

Steps to reproduce the behavior

Create a table (for example a results table from Muon Analysis)
Open a new script tab in Workbench. Add the following after the standard headers (change the actual table and column names as appropriate):

tab=mtd["ResultsTable"]
colY=tab.column("f0.A")
print (colY)

Note that removing the “unicode_literals” from the future statement makes the script work as intended.

Platforms affected

Workbench 4.2 (found on Windows, probably all platforms)

This should be fixed when Mantid is upgraded to Python 3. I have still raised an issue in case we get a chance to fix this: Unicode not supported for Column access to TableWS · Issue #27555 · mantidproject/mantid · GitHub

The work around for now seems to be
colY=tab.column(str("f0.A"))
I think this will still work as intended in real Python 3.

1 Like