Skip to content

Convert np.str_ to regular str in Annotations? #13922

Closed

Description

@cbrnr

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.

WDYT?

Activity

  1. changed the title [-]Convert np.str_ to regular str in Annotations?[/-] [+]Convert `np.str_` to regular `str` in Annotations?[/+] on May 26, 2026
  2. cbrnr commented on May 26, 2026

    @cbrnr
    ContributorAuthor

    OK, vectorized boolean masking only works with NumPy arrays, so we probably might want to keep it. However, the drop_log question still stands.

  3. drammock commented on May 26, 2026

    @drammock
    Member

    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

  4. drammock commented on May 26, 2026

    @drammock
    Member

    you're better off casting as pure python strings at critical moments (e.g. before save/pickle/etc or before repr)

  5. cbrnr commented on May 26, 2026

    @cbrnr
    ContributorAuthor

    Yes, that's what I suspected. So OK with casting to str for the drop_log for now?

    Also, I noticed that the onset, duration, and description attributes are missing in the docs. OK to add in a separate PR?

  6. drammock commented on May 26, 2026

    @drammock
    Member
    • cast-to-str for drop log 👍🏻
    • add attributes to docs: that's more complicated; in order to show up they'd need to be added as
    @property
    def onset(self):
       ...
    
    @onset.setter
    def onset(self, ...):
       ...

    I think it's a worthwhile change but heads up it's maybe a bigger refactor than you were imagining.

  7. cbrnr commented on May 26, 2026

    @cbrnr
    ContributorAuthor

    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!

  8. larsoner commented on May 26, 2026

    @larsoner
    Member

    For the param stuff there is already some related effort underway in #13680

  9. cbrnr commented on May 26, 2026

    @cbrnr
    ContributorAuthor

    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.

  10. linked a pull request that will close this issueFix drop_log dtype #13923on May 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions