-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Truncate long lines in repr of Dataset.attrs #1319
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
Comments
OK, I'm not opposed to this. Truncating at 500 characters was basically a minimal sanity check -- we could certainly go further than this. Anyone else have opinions here about sane default behavior? I don't work with files with lots of long attributes. |
As long as we can explicitly obtain the |
I am in favor of truncating the attrs too. |
Sounds like there is support here. @Zac-HD Any interest in putting together a pull request? See here for the existing logic: xarray/xarray/core/formatting.py Line 255 in b3fc6c4
|
Sure, I'd be happy to. The above example will look much nicer, especially in wrapping environments:
|
When loading from NetCDF,
Dataset.attrs
often has a few long strings, which may even have embedded newlines (eg a multi-paragraphsummary
orreferences
section). It's lovely that these are available, but they tend to make the repr very long and poorly formatted - to the point that many Jupyter notebooks begin by discarding theattrs
, which makes it rather pointless to store or display metadata at all!Given that these values are already truncated at 500 characters (including the indicative
...
, but not the start point), I propose that they should instead be truncated to 80 characters including the indentation and key (asvalues
are). For the sake of pretty-printing, this should also replace newlines or tabs with spaces and truncate early if an empty line is encountered.Another solution would be add appropriate indentation following newlines or wrapping, so that the structure remains clear. However, I think that it is better to print a fairly minimal representation of the metadata by default.
The text was updated successfully, but these errors were encountered: