-
Notifications
You must be signed in to change notification settings - Fork 14
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
Use pprint to represent DataContainers, not forcing HDFStubs #1057
Conversation
to_builtin got a new argument load_stubs=True such that loading HDFStubs can be avoided.
With these changes, the dc = DataContainer({"a": 1, "b": 2, 'c':{'A':1}}) we get with the current main DataContainer({'a': 1, 'b': 2, 'c': DataContainer({'A': 1})}) but with these changes we would get DataContainer({"a": 1, "b": 2, 'c':{'A':1}}) Furthermore, it (currently) omits everything nested deeper than the first two levels by '...'. |
@@ -451,50 +439,53 @@ def _read_only_error(cls): | |||
"finished.".format(cls.__name__) | |||
) | |||
|
|||
def to_builtin(self, stringify=False): | |||
def to_builtin(self, stringify=False, load_stubs=True, _no_str_keys=False): |
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.
load_stubs
should have a short documentation even though it's fairly obvious. If I see correctly _no_str_keys
is not used.
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.
Yes, documentation is missing and I forgot to pass the _no_str_keys
to the sub groups. However, it is used and switches off the key conversion such that the keys stay e.g. int if they are.
I have a slight preference to keep the class name in the output to differentiate true dict members from |
I agree, however, the pprint does not naively work on the |
name = self.__class__.__name__ | ||
plain = f"{name}({json.dumps(self.to_builtin(stringify=True), indent=2, default=str)})" | ||
return "<pre>" + plain + "</pre>" | ||
return self.to_builtin(stringify=True, load_stubs=False) |
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.
Also a bit the question: Do we want to not load the stubs in this case? Also the nice jupyter lab interface would not show the full container from the beginning but the stubs. To have the full view one would need to call to_builtin beforehand.
See also the second answer from the SO link and this POTW. Those manage without subclassing, by doing |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
to_builtin got a new argument load_stubs=True such that loading HDFStubs can be avoided.
Might close #1031