Conversation
|
To be discussed: an even shorter way is to add |
JulietteFrancovich
left a comment
There was a problem hiding this comment.
I think this is a very useful addition. I have added some minor comments.
To be discussed: an even shorter way is to add
sequence.d['filtered impedance']. This reduces the amount of characters needed, but introduces a level of abstraction. I don't think I like it enough to propose it. What do you think, @JulietteFrancovich?
I personally think winning three characters does not weigh up against the decrease in readability when shortening .data to .d. I would refrain from doing so.
| for a, b in itertools.combinations(self._collections, 2): | ||
| if duplicates := set(a) & set(b): | ||
| msg = ( | ||
| f"Duplicate labels ({', '.join(sorted(duplicates))}) found in {a} and {b}. " |
There was a problem hiding this comment.
Consider adding what someone can do (use original interface).
There was a problem hiding this comment.
Thanks for the suggestion!
I've added this as an explanation in the two exceptions about duplicate labels.
(This will only show up in Python 3.11 or higher, because I'm using the notes feature of exceptions introduced in Python 3.11]. I think it's best to keep the exception message short and clear; suggestions for better approaches are also given as exception notes in popular libraries.)
| with pytest.raises(KeyError): | ||
| sequence.data.add(interval_data_object) | ||
|
|
||
| # you can still add through the DataCollection, but this interface will not be available anymore |
There was a problem hiding this comment.
Is this something that is also explained to the user in for instance a docstring?
Co-authored-by: JulietteFrancovich <78535051+JulietteFrancovich@users.noreply.github.com>
…icate labels. These suggestions only work in Python >=3.11, because they use the Exception.add_note() method.
This PR adds a data interface to sequences for easier access to data objects. Instead of
sequence.continuous_data['filtered impedance']one can now usesequence.data['filtered impedance']. Adding data is also easier with `sequence.data.add(object)Other dict function are also implemented, such that
sequence.datacan be used as a conglomeration of all data collections.This improves readability of end user code. The old interface is still intact and usable. To use the interface, all labels have to be unique across all data collections.
Fixes #363