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

Looping over bundles with one element #177

Open
sperezconesa opened this issue Jun 22, 2020 · 3 comments
Open

Looping over bundles with one element #177

sperezconesa opened this issue Jun 22, 2020 · 3 comments

Comments

@sperezconesa
Copy link

Hello,

I have a small suggestion that I think could improve the usability of datreant in workflows that can vary the number of members of a bundle. I normally have this kind of structures in my notebooks:

for treant in my_bundle:
      process the treant

The problem is that if I have done some filtering of the bundle and I end up with a single treant in the bundle. This gives an error. I normally patch this problem by doing:

for treant in [my_bundle[0]]:
      process the treant

But of course I have to modify again if I change the bundle size. Am I missing a better way to do this? If not, maybe there is a simple solution that can be implemented in the code so that the top code works regardless of size?

Thanks a lot for your help and keep up the good work!
Best,
Sergio

@kain88-de
Copy link
Contributor

Sorry for the late reply. Which version are you running? I cannot reproduce this from the current development branch.

To test I created a bundle with only two treants and selected a single one with boolean selection, everything boils down to boolean selection internally.

import datreant as dtr
t1 = dtr.Treant('a')
t2 = dtr.Treant('aa')
b = dtr.Bundle(t1,t2)
for c in b[[True, False]]:
    print('xxx')

@sperezconesa
Copy link
Author

sperezconesa commented Aug 17, 2020

Ahh. I think I missunderstood how bundles work because this doesn't work for me either:

import datreant as dtr
t1 = dtr.Treant('a')
t2 = dtr.Treant('aa')
b = dtr.Bundle(t1,t2)
for c in b[0]:
    print('xxx')

But this does:

import datreant as dtr
t1 = dtr.Treant('a')
t2 = dtr.Treant('aa')
b = dtr.Bundle(t1,t2)
for c in b[[0]]:
    print('xxx')

@kain88-de
Copy link
Contributor

kain88-de commented Aug 18, 2020 via email

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

2 participants