Added set-like methods to Session#984
Added set-like methods to Session#984gdementen wants to merge 1 commit intolarray-project:masterfrom
Conversation
2a82022 to
ddfd1d2
Compare
alixdamman
left a comment
There was a problem hiding this comment.
As a general remark: update the tutorial ?
| ^^^^^^^^^^^^ | ||
|
|
||
| * implemented :py:obj:`Session.union()`, :py:obj:`Session.intersection()` and :py:obj:`Session.difference()` to combine | ||
| several sessions into one using set operations (closes :issue:`22`). |
There was a problem hiding this comment.
Update the tutorial ?
During the last few months, I had the opportunity to discuss with some of our (unexperimented) users. They truly consider the tutorial as a Bible (not sure it's a good thing...).
There was a problem hiding this comment.
Yes, I should and I will. I don't like doing that but if it's not in the tutorial, it might as well not exist for some (most?) of our users.
| return Session([(k, func(v, *args, **kwargs) if isinstance(v, kind) else v) for k, v in self.items()]) | ||
|
|
||
| def union(self, other): | ||
| """Returns session with the (set) union of this session objects with other objects. |
There was a problem hiding this comment.
Add a warning telling that using this method on two CheckedSession objects will return a normal Session.
| return self[[k for k in self.keys() if k in other_keys]] | ||
|
|
||
| def difference(self, other): | ||
| """Returns session with the (set) difference of this session objects and other objects. |
There was a problem hiding this comment.
same remark as for union()
| return res | ||
|
|
||
| def intersection(self, other): | ||
| """Returns session with the (set) intersection of this session objects with other objects. |
There was a problem hiding this comment.
same remark as for union()
| >>> s1.intersection(['arr2', 'arr1']) | ||
| Session(arr1, arr2) | ||
| """ | ||
| other_keys = set(other.keys() if isinstance(other, Session) else other) |
There was a problem hiding this comment.
Have you tested with CheckedSession objects ?
CheckedSession inherits from Session so I see no reason it doesn't work but we never know.
There was a problem hiding this comment.
No, I didn't think of that. This is a VERY old branch I cleaned up and documented in the train. Didn't think of CheckedSession since they didn't exist at the time 😉.
No description provided.