home / github / issue_comments

Menu
  • Search all tables
  • GraphQL API

issue_comments: 874209908

This data as json

html_url issue_url id node_id user created_at updated_at author_association body reactions performed_via_github_app issue
https://github.com/pydata/xarray/issues/5545#issuecomment-874209908 https://api.github.com/repos/pydata/xarray/issues/5545 874209908 MDEyOklzc3VlQ29tbWVudDg3NDIwOTkwOA== 28786187 2021-07-05T15:58:00Z 2021-07-05T17:43:09Z CONTRIBUTOR

Hi, @max-sixty I could give it a try, but my time is quite limited. Would you be fine with a diff? That would save me a bit from setting up a fork and new repo.

Anyway, here is a quick diff, I tried to keep it small and basically moved the max_rows setting to dataset_repr, only coords_repr takes a new keyword argument, so that should be backwards compatible. The tests would need to be updated. Maybe it is a good idea to not test _mapping_repr, but instead test coords_repr, data_vars_repr, attrs_repr, and dataset_repr separately, to check that they do what they are supposed to do regardless of their implementation?

Edit: Never mind, I am preparing a PR with updated tests.

```diff diff --git a/xarray/core/formatting.py b/xarray/core/formatting.py index 07864e81..ab30facf 100644
--- a/xarray/core/formatting.py
+++ b/xarray/core/formatting.py @@ -377,14 +377,12 @@ def _mapping_repr(
):
if col_width is None: col_width = _calculate_col_width(mapping) - if max_rows is None:
- max_rows = OPTIONS["display_max_rows"]
summary = [f"{title}:"] if mapping:
len_mapping = len(mapping) if not _get_boolean_with_default(expand_option_name, default=True): summary = [f"{summary[0]} ({len_mapping})"] - elif len_mapping > max_rows:
+ elif max_rows is not None and len_mapping > max_rows:
summary = [f"{summary[0]} ({max_rows}/{len_mapping})"] first_rows = max_rows // 2 + max_rows % 2 items = list(mapping.items())
@@ -416,7 +414,7 @@ attrs_repr = functools.partial(
)

-def coords_repr(coords, col_width=None):
+def coords_repr(coords, col_width=None, max_rows=None):
if col_width is None: col_width = _calculate_col_width(_get_col_items(coords)) return _mapping_repr( @@ -425,6 +423,7 @@ def coords_repr(coords, col_width=None): summarizer=summarize_coord, expand_option_name="display_expand_coords", col_width=col_width, + max_rows=max_rows, ) @@ -542,21 +541,22 @@ def dataset_repr(ds): summary = ["<xarray.{}>".format(type(ds).name)]

 col_width = _calculate_col_width(_get_col_items(ds.variables))
  • max_rows = OPTIONS["display_max_rows"]

    dims_start = pretty_print("Dimensions:", col_width) summary.append("{}({})".format(dims_start, dim_summary(ds)))

    if ds.coords: - summary.append(coords_repr(ds.coords, col_width=col_width)) + summary.append(coords_repr(ds.coords, col_width=col_width, max_rows=max_rows))

    unindexed_dims_str = unindexed_dims_repr(ds.dims, ds.coords) if unindexed_dims_str: summary.append(unindexed_dims_str)

  • summary.append(data_vars_repr(ds.data_vars, col_width=col_width))

  • summary.append(data_vars_repr(ds.data_vars, col_width=col_width, max_rows=max_rows))

    if ds.attrs: - summary.append(attrs_repr(ds.attrs)) + summary.append(attrs_repr(ds.attrs, max_rows=max_rows))

    return "\n".join(summary)

```

{
    "total_count": 1,
    "+1": 1,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  931591247
Powered by Datasette · Queries took 0.743ms · About: xarray-datasette