bug fix: have ops on subclassed datapanels return subclass type #57
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.
Issue
When datapanels are subclasses, ops on these datapanels (getitem, merge, append, etc) returned instances of
mosaic.DataPanel
instead of the subclass typeFix
All class methods can be called from the instance. This will automatically pass the type of the instance (e.g. subclass) to the class method. For example,
When
from_batch
is used from instance methods, we callself.from_batch
instead ofDataPanel.from_batch
.Consequences and stopgap solutions
By calling
self.from_batch
, the initializer of the subclass is called asfrom_batch
callscls(...)
. This can be an issue if there is state in the current instance (e.g.self
) that needs to be passed to the new DataPanel subclass instance.An example of this is
EntityDataPanel
, where theindex_column
should be passed from the current instance to the newly constructed instance. Because there is no way to plumb that information through different calls, the initializer ofEntityDataPanel
gets called withEntityDataPanel(index_column=None)
even if the current instance has an index column. This results in a new column"_ent_index"
being added to the new EntityDataPanel.As a stopgap solution, we have a method that removes the extra
"_ent_idx"
column any time a new data panel is created, but this is not a scalable solution, because there may be many parameters that need to be plumbed through to construct the subclassed data panel.We propose a more long-term solution in #56