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
Convert np.str_ to regular str in Annotations? #13922
When creating an Epochs object with "bad" annotations, the non-empty drop log entries currently look like this (tuples of np.str_):
(np.str_('bad_segment'),)
With NumPy 1.x, these entries were regular Python strings, which I think was more readable and more intuitive.
I'm happy to submit a PR to revert the entries to plain strings. Alternatively, we could also consider changing Annotations.description from an np.ndarray with dtype=np.str_ to a plain list[str]. I can't think of a good reason why this field has to be a NumPy array, so I'd really prefer to make this change, which would automatically fix the drop log.
I believe with numpy 1.x, those were still np.str_ instances, but the repr didn't make that obvious. Regardless, it will be a bit of a pain to switch to using pure list[str] because of e.g., how sorting is implemented
Alright, I'll create two PRs then! I think the attributes are definitely worth adding, because the whole point of the Annotations class is to provide the three arrays, and these are nowhere to be seen in the docs!
Thanks for the heads up @larsoner! I'll see if I can continue from there, or just start from scratch (which might be easier, let's see), or maybe just help get the linked PR finished.
Activity
[-]Convert np.str_ to regular str in Annotations?[/-][+]Convert `np.str_` to regular `str` in Annotations?[/+]cbrnr commentedon May 26, 2026
OK, vectorized boolean masking only works with NumPy arrays, so we probably might want to keep it. However, the
drop_logquestion still stands.drammock commentedon May 26, 2026
I believe with numpy 1.x, those were still np.str_ instances, but the repr didn't make that obvious. Regardless, it will be a bit of a pain to switch to using pure list[str] because of e.g., how sorting is implemented
drammock commentedon May 26, 2026
you're better off casting as pure python strings at critical moments (e.g. before save/pickle/etc or before repr)
cbrnr commentedon May 26, 2026
Yes, that's what I suspected. So OK with casting to
strfor thedrop_logfor now?Also, I noticed that the
onset,duration, anddescriptionattributes are missing in the docs. OK to add in a separate PR?drammock commentedon May 26, 2026
I think it's a worthwhile change but heads up it's maybe a bigger refactor than you were imagining.
cbrnr commentedon May 26, 2026
Alright, I'll create two PRs then! I think the attributes are definitely worth adding, because the whole point of the
Annotationsclass is to provide the three arrays, and these are nowhere to be seen in the docs!larsoner commentedon May 26, 2026
For the param stuff there is already some related effort underway in #13680
cbrnr commentedon May 26, 2026
Thanks for the heads up @larsoner! I'll see if I can continue from there, or just start from scratch (which might be easier, let's see), or maybe just help get the linked PR finished.