-
Notifications
You must be signed in to change notification settings - Fork 124
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
FIX: Make lists and dicts hashable #684
FIX: Make lists and dicts hashable #684
Conversation
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.
LGTM, thanks. I'm wondering if we should kill off the 'dir'
and 'id'
return types in the next major (breaking) release... they seem to cause a lot of problems, and the efficiency gains are probably not meaningful compared to just looping over objects. But we can take that up elsewhere.
9fb388b
to
0b7dcfc
Compare
6455905
to
c48076f
Compare
Rebased on top of #695 - please merge that one first. |
I think #694 was the discussion that postponed this decision. I've also forgotten some context here... |
Oh, right, thanks. I'll try to work up the proposal I suggested there. |
@oesteban, @effigies and I chatted and decided that the Do you agree? If so I think we can close this PR. |
First things first, and as I told @tyarkoni on one of the related issues, I'm likely not going to maintain this. So you shouldn't take it if you think this will be too onerous to maintain (although, honestly, I don't see a big burden - but I'm not to decide). That said, I think the flattening solution only addresses the inner part of the problem and conflates two different indefinitions of BIDS: i) the one about whether one can define dicts as metadata values; and ii) whether it is allowed to name a metadata piece with the same name of an entity. Both problems arise in pybids under this unhashable type (ii only if there are dicts defined, but there's the question of whether pybids returns the adequate values when it doesn't crash in this case). Flattening dictionaries would address i) and incidentally solve ii) partially. But it is just a data representation problem of which the user doesn't need to know. This means, are we going to "unflatten" when returning these values? Because I bet users will be more comfortable receiving a dict RatherThanSomeCamelCaseFlatteningOfSomething (which we don't know yet the whole domain of possible values nested and number of nestings, btw). Nipype's results file had to deal with a similar situation, and the resulting code is a bit brittle and hard to maintain. I wonder if alquemy would take frozen dicts right away. Then there is the question of having to return unique values of a given entity. I honestly think that returning something that looks like a dict, behaves like a dict and (if we cast the dict back before returning) is sometimes an actual dict is more convenient/intuitive to the user than the flattened values. This also ensures the sanity of the values in all
In this case, to give the user something useful, we don't even need to apply the entity's regexp to return the right thing. It would be more difficult when the "session" in the TSV+JSON file is some string value:
But none of the other solutions would solve this problem, as it stems directly from the indefinition of BIDS. I admit though that this solution does nothing to fix the problem of inserting dicts in the db. Unless, inserting frozen dicts would be an acceptable option, which would doubly justify this PR. And this is my 2ct. |
Oscar, thanks for the spirited defense. To be clear, my suggestion to solve (ii) with respect to "shorthand" functions for BIDS entity is primarily dealt by #749. I think this PR (or flattening dicts) takes care of (i) (how to represent hashable types).
For this example, I prefer the results of #749:
For shorthand functions (i.e. Arguably, Also, since filtering happens only on the If we agree on #749, then the question is how to represent dicts for actual meta-data (to avoid crashing on shorthand functions such as Three questions remain for me about frozendicts:
If 1) and 2) are not problems with |
I'm trying to wrap my head around rebasing this, @effigies . I thought it would be more straightforward, but the new "id" and "dir" filtering is not so clear to me yet. |
c48076f
to
80e9d2e
Compare
I think this is it. I have removed one level of branching which I hope doesn't break tests. There is one new unit test that was made the code fail with cc/ @effigies |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #684 +/- ##
==========================================
+ Coverage 86.03% 86.07% +0.03%
==========================================
Files 35 35
Lines 3924 3934 +10
Branches 1017 1023 +6
==========================================
+ Hits 3376 3386 +10
- Misses 355 356 +1
+ Partials 193 192 -1 ☔ View full report in Codecov by Sentry. |
Any roadmap for that fix to be merged? |
Oof, this probably needs a major re-write since it's a pretty old PR. @oesteban any recollection as to why this wasn't merged despite getting a PR approval? |
hehehe I don't remember 😓 |
Resolves: #683.