home / github / issue_comments

Menu
  • Search all tables
  • GraphQL API

issue_comments: 1033814820

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/6069#issuecomment-1033814820 https://api.github.com/repos/pydata/xarray/issues/6069 1033814820 IC_kwDOAMm_X849nsMk 43613877 2022-02-09T14:23:54Z 2022-02-09T14:36:48Z CONTRIBUTOR

You are right, the coordinates should not be dropped.

I think the function _validate_region has a bug. Currently it checks for all ds.variables if at least one of their dimensions agrees with the ones given in the region argument. However, ds.variables also returns the coordinates. However, we actually only want to check if the ds.data_vars have a dimension intersecting with the given region.

Changing the function to `python def _validate_region(ds, region): if not isinstance(region, dict): raise TypeError(f"region`` must be a dict, got {type(region)}")

for k, v in region.items():
    if k not in ds.dims:
        raise ValueError(
            f"all keys in ``region`` are not in Dataset dimensions, got "
            f"{list(region)} and {list(ds.dims)}"
        )
    if not isinstance(v, slice):
        raise TypeError(
            "all values in ``region`` must be slice objects, got "
            f"region={region}"
        )
    if v.step not in {1, None}:
        raise ValueError(
            "step on all slices in ``region`` must be 1 or None, got "
            f"region={region}"
        )

non_matching_vars = [
    k for k, v in ds.data_vars.items() if not set(region).intersection(v.dims)
]
if non_matching_vars:
    raise ValueError(
        f"when setting `region` explicitly in to_zarr(), all "
        f"variables in the dataset to write must have at least "
        f"one dimension in common with the region's dimensions "
        f"{list(region.keys())}, but that is not "
        f"the case for some variables here. To drop these variables "
        f"from this dataset before exporting to zarr, write: "
        f".drop({non_matching_vars!r})"
    )

``` seems to work.

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