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
Comments
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') |
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') |
Yeah with the first syntax you are requesting element 0 which is a treant.
The later selects a bundle containing a single element. As long as you
always give the getitem [] operator a list like object you will get a
bundle back.
Does this solve your issues?
…On Mon 17. Aug 2020 at 09:01, Sergio Pérez Conesa ***@***.***> wrote:
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')
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#177 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABA2OVTZKHUZ5DWKRFLC2U3SBDIWBANCNFSM4OEZ6JGQ>
.
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:
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:
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
The text was updated successfully, but these errors were encountered: