-
Notifications
You must be signed in to change notification settings - Fork 163
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
Sort input extensions #2705
Sort input extensions #2705
Conversation
Isn't it easier to just tell the user to add the needed extension before the extension that generates the error?. I think this is easier to mantain and document. I also like it makes the dependency graph explicit on the list. All of this only matters if the dependency graph of the extensions is meant to become more complicated. If not, then either solution should work just fine. If we go the way of parsing the dependency tree and re-order it as we do here we should be careful to not alter the list that the user passes as they might use it for something else and get an error because we modified their state. In concrete, we should copy at the beginning. |
You could be right. The error reporting also helps the user be aware of the parent/child structure which might help overall understanding. If we use an error reporting method, it could:
Yes, good point thanks! So I shouldn't have edited extensions - I'll change on the next update. |
I think it's not a mistake to pass |
I've updated it so that So the other issue comes down to whether |
I believe this should be allowed and it's not an error from the user! Especially when passing a dict as input to the compute, re-sorting the dict according to dependencies is unnecessarily complex |
assert sorted_extensions_4 == {"templates": {}, "random_spikes": {}, "waveforms": {}, "quality_metrics": {}} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should have "random_spikes" at the first place no ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello. Yes, the tests were all useless since dict equality doesn't care about order. So, at the testing stage, I've made them OrderedDicts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dict is now ordered by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but equality doesn't care about the ordering, for backward compatibility. The following
a = {1: 3, 2: 4}
b = {2: 4, 1: 3}
a == b
outputs True
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes of course. We should do
list(a.key()) == list(b.keys())
no ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, both seem to work, but if that's standard practice then let's go for keys. I've updated the tests, including getting rid of the "magic" sorted dictionaries.
Hi Chris. |
merci! |
Automatically sorts a list of extensions, for computation, so that all parents are “on the left” of their children. Improvement suggested by @alejoe91 .
For example, the SortingAnalyzer extension
waveforms
depends onrandom_spikes
. If you runthis fails as the compute function scans left to right. It’s a bit annoying since the user has tried to include
random_spikes
. It’s also easy to image a user runningsorting_analyzer.compute([“waveforms”])
. si tells the user they need to haverandom_spikes
and they naturally add it on the right of the list. So: worth improving!This change would automatically sort the inputted list so that all parents are on the left of their children. The function itself doesn’t check if the whole list is valid (i.e. it doesn’t return an error if
random_spikes
isn’t there when calculatingwaveforms
), it only sorts it. These checks happen downstream.The function I’ve written is a bit awkward, because the compute parameters are dictionaries (if you input a list, this gets converted to a dictionary internally, so kwargs can be easily handled.). And dictionaries aren’t really meant to have an order: so insertions at given indices are tricky etc. Here, I turn the dict into two lists, do the sorting, then zip. If anyone thinks of a cleaner algorithm, let me know.
Also added tests.