-
Notifications
You must be signed in to change notification settings - Fork 218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add repr to dictlist #1278
base: devel
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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,