cobrapy
cobrapy copied to clipboard
feat: add repr to dictlist
- [x] fix #1277
- [x] description of feature/fix
It would be nice to have a neater representation of the model objects - metabolites, reactions, genes, etc. For example,

- [ ] tests added/passed
- [ ] add an entry to the next release
Codecov Report
Attention: Patch coverage is 39.13043% with 14 lines in your changes are missing coverage. Please review.
Project coverage is 84.13%. Comparing base (
b438d2f) to head (28376e6). Report is 70 commits behind head on devel.
:exclamation: Current head 28376e6 differs from pull request most recent head 5b45b1f. Consider uploading reports for the commit 5b45b1f to get more accurate results
| Files | Patch % | Lines |
|---|---|---|
| src/cobra/core/dictlist.py | 17.64% | 14 Missing :warning: |
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
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
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 DictList classes here called _repr_tr which returns a representation of itself wrapped in <tr></tr> so that it can be included easily? Guess we'd also need a class method _repr_th_ then for the column headers.
Of course, your approach has the benefit of easily transforming to a data frame which may have more general benefits.