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

Cannot flatten lists of tuples containing lists #342

Open
maffoo opened this issue Jul 24, 2017 · 0 comments
Open

Cannot flatten lists of tuples containing lists #342

maffoo opened this issue Jul 24, 2017 · 0 comments

Comments

@maffoo
Copy link
Contributor

maffoo commented Jul 24, 2017

When flattening python data into labrad format, pylabrad tries to infer the correct python type as it goes. This can become complicated when flattening lists of more complicated structures, because lists must be homogeneous so that each element has the same type, but the final type may need to be refined as we visit more elements in the list. We ran into the following edge case, where we want to flatten a list of clusters of two lists of strings:

>>> data1 = [([],), (['a'],), ([],)]
>>> print(labrad.types.flatten(data1).tag)
*(*s)

>>> data2 = [([], []), ([], ['a']), (['a'], [])]
>>> print(labrad.types.flatten(data2).tag)
FlatteningError: (12345) Could not flatten 'a' to _. [payload=none]

>>> print(labrad.types.flatten(data2, '*(*s*s)').tag
*(*s*s)

The first example with clusters containing one list works fine; the flattening code infers that the list contains strings after it sees the second element. But the next example with clusters containing two lists does not work as expected. If we provide an explicit type as in the last example, everything flattens just fine, but it should work even if we don't provide an explicit type to flatten to.

@maffoo maffoo changed the title Cannot lists of tuples containing lists Cannot flatten lists of tuples containing lists Jul 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant