feat: add repr to dictlist#1278
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## devel #1278 +/- ##
==========================================
- Coverage 84.40% 84.13% -0.28%
==========================================
Files 66 66
Lines 5497 5520 +23
Branches 1265 1269 +4
==========================================
+ Hits 4640 4644 +4
- Misses 551 570 +19
Partials 306 306 ☔ View full report in Codecov by Sentry. |
|
An alternative approach would be to have DictList inspect its own element type and map the printed columns based on that. Not great for encapsulation, but that does not break the pickling of models. Not sure what would be the best strategy. |
|
I thought on similar lines as well is what attributes would go in best. But I think sticking to this style made me feel that reliance on instance specific df wouldn't be so concerning. |
|
I must admit, I'm not fully convinced by this approach. What if we added a new method to all the Of course, your approach has the benefit of easily transforming to a data frame which may have more general benefits. |
|
|
||
| for item in self: | ||
| ids.append(item.id) | ||
| data.append([getattr(item, attr) for attr in columns]) |
There was a problem hiding this comment.
| for item in self: | |
| ids.append(item.id) | |
| data.append([getattr(item, attr) for attr in columns]) | |
| from operator import attrgetter | |
| column_getter = attrgetter(*columns) | |
| for item in self: | |
| ids.append(item.id) | |
| data.append(column_getter(item)) |
| item = None | ||
| columns = [] | ||
|
|
||
| if self: |
There was a problem hiding this comment.
Maybe it's clearer to say
| if self: | |
| if not self.empty(): |
It would be nice to have a neater representation of the model objects - metabolites, reactions, genes, etc. For example,
