Support slicing properties as properties (aka. support obj[i:j].shape). #44
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, after
sliced = pims.open(...)[i:j]
, thesliced
object doesn't have a.shape
attribute (#38), even though it does have alen()
and a.frame_shape
(the latter being propagated via propagated_attrs) and even thoughFramesSequence.shape
is actually a property (return (len(self), *self.frame_shape)
).This PR adds the ability to mark properties as being propagated, not as values, but rather as properties in the sliced object too (the decorator name,
@sliceable_property
, can be bikeshedded). This is done by having__getitem__
not return a Slicerator, but a subclass of Slicerator with the relevant properties.While we're at it, "standard" propagated attributes are also implemented using properties now (which directly call getattr on the ancestor, not going through any fget); this is a slight API change in that later changes to the attribute on the ancestor will now be reflected on the sliced object, but the keeping the implementation consistent with sliceable properties seems nice and having these attributes tab-completable (rather than being hidden behind
__getattr__
is good for usability). In any case this could be changed back if the API change is problematic.As a result, with this PR, pims/base_frames.py just needs a small extra patch:
to support
sliced = pims.open(...)[i:j]; sliced.shape
.I can add tests and make the corresponding change in pims if we agree on the design here.