Skip to content
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

Improve Coord and Cube attributes printout #4528

Merged
merged 4 commits into from
Jan 27, 2022

Conversation

pp-mo
Copy link
Member

@pp-mo pp-mo commented Jan 25, 2022

During development of #4499, and discussion in #4501, it was suggested that when printing cube components with names/units/attributes (i.e. derived from CFVariableMixin) we should be listing any attributes in a one-per-line fashion, as Cube.__str__ already does.

This wasn't initially done in #4499 as I was concerned it introduced more change to an already complex PR.

On subsequent investigation though, it isn't really that complex, so this PR introduces that.
Results go from looking (schematically) like

DimCoord :  name / (units)
 . . .
    long_name: 'thing'
    dtype: float64
    attributes: {'string': 'this', 'array': [1.0 2.0 3.0], 'really_long_string': 'long long long long thing', 'float':3.2}
    circular: True

to

DimCoord :  thing / (units)
 . . .
    long_name: 'thing'
    dtype: float64
    attributes:
        string     'this'
        array      [1.0 2.0 3.0]
        long_name  'long long long long thing'
        float      3.2
    circular: True

Comparing the output of attributes in Cube listings to those in Coords, I also came to the conclusion that it would be better to always quote strings when they appear as attribute values -- that is, in Cube listings also.
Luckily that is very easy to do -- though there were quite a few tests to fix, so it's a bit noisy.

@pp-mo pp-mo marked this pull request as ready for review January 25, 2022 23:12
@pp-mo pp-mo marked this pull request as draft January 25, 2022 23:13
@pp-mo pp-mo marked this pull request as ready for review January 26, 2022 07:55
@pp-mo pp-mo changed the title Coord print attrs Improve Coord attributes printout Jan 26, 2022
@pp-mo pp-mo changed the title Improve Coord attributes printout Improve Coord and Cube attributes printout Jan 26, 2022
@pp-mo
Copy link
Member Author

pp-mo commented Jan 27, 2022

Added code to clip over-long strings, as in previous comments.

Copy link
Member

@lbdreyer lbdreyer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thanks @pp-mo !

@lbdreyer lbdreyer merged commit 9dca7eb into SciTools:main Jan 27, 2022
wjbenfold pushed a commit that referenced this pull request Jan 28, 2022
tkknight added a commit to tkknight/iris that referenced this pull request Mar 16, 2022
* main: (64 commits)
  [pre-commit.ci] pre-commit autoupdate (SciTools#4587)
  fix test (SciTools#4585)
  Loading Benchmarks (SciTools#4477)
  Fix refresh lockfile worrkflow pull request title (SciTools#4579)
  gha: lockfiles labels and auto-pr details (SciTools#4578)
  Bump actions/script from 4 to 5.1.0 (SciTools#4576)
  Bump actions/stale from 4.0.0 to 4.1.0 (SciTools#4575)
  Bump peter-evans/create-pull-request from 3.8.2 to 3.12.1 (SciTools#4577)
  adopt dependabot GHA (SciTools#4568)
  New tool-agnostic ASV environment management (SciTools#4571)
  Updated environment lockfiles (SciTools#4567)
  Update version to 3.3.dev0 (SciTools#4565)
  Reset whats new (SciTools#4563)
  docs: move whatsnew (SciTools#4540)
  Deprecate regrids (SciTools#4548)
  Update latest.rst (SciTools#4556)
  Updated environment lockfiles (SciTools#4555)
  Added whatsnew for SciTools#4551. (SciTools#4553)
  Update SciTools#4505 doctests for SciTools#4528. (SciTools#4554)
  minor optimisations (SciTools#4549)
  ...
@pp-mo pp-mo deleted the coord_print_attrs branch March 18, 2022 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants