You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Numpy access to ancestral and derived state columns in TreeSequence #2632
I haven't managed to make a direct view of the memory that gets treated as a unicode string.
As a first pass we could just error out of the states aren't all single chars (ascii chars even), and I guess we could just copy the data in a way that's numpy string friendly when we have variable length alleles? I guess it would be good to know if this is possible before painting ourselves into a corner.
No, this doesn't work unfortunately - I think copy=False is a request that numpy does its best to fulfil, when possible. I just tried it out there and the OWNDATA flag is false when you do .astype(str, copy=False).
I don't get why the view dtype=U1 doesn't work though - aren't these UTF-8 encoded single byte strings?
Activity
benjeffery commentedon Nov 8, 2022
tables.sites.ancestral_state.view("S1").astype(str, copy=False)works for me, and I think avoids the copy?jeromekelleher commentedon Nov 9, 2022
No, this doesn't work unfortunately - I think
copy=Falseis a request that numpy does its best to fulfil, when possible. I just tried it out there and the OWNDATA flag is false when you do.astype(str, copy=False).I don't get why the view
dtype=U1doesn't work though - aren't these UTF-8 encoded single byte strings?benjeffery commentedon Nov 17, 2022
numpy.dtype("U1").itemsizeis4as there has to be room for the largest, 4-byte unicode character.numpy.dtype("S1").itemsizeis1. So I don't think we can get to a unicode dtype without a copy or some low-level hacking.benjeffery commentedon Jun 9, 2025
Related to #2426
jeromekelleher commentedon Jun 10, 2025
Note that the current plan for this is to make a numpy stringdype in C
benjeffery commentedon Jun 26, 2025
Closed in #3228