home / github / issue_comments

Menu
  • Search all tables
  • GraphQL API

issue_comments: 463078403

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/pull/2767#issuecomment-463078403 https://api.github.com/repos/pydata/xarray/issues/2767 463078403 MDEyOklzc3VlQ29tbWVudDQ2MzA3ODQwMw== 223250 2019-02-13T06:38:43Z 2019-02-13T06:38:43Z CONTRIBUTOR

I was looking for this functionality and ran across #1949.

There was one bit of behavior that was unclear to me. Say I have

```python In [6]: data = xr.Dataset({'A': (['x', 'y'], np.random.randn(2, 3)), ...: 'B': ('x', np.random.randn(2)), ...: 'x': ['a', 'b'], 'z': np.pi})

In [7]: data Out[7]: <xarray.Dataset> Dimensions: (x: 2, y: 3) Coordinates: * x (x) <U1 'a' 'b' Dimensions without coordinates: y Data variables: A (x, y) float64 -0.662 -0.705 -0.1866 -0.8655 0.5816 -0.2308 B (x) float64 -0.1002 2.402 z float64 3.142

In [8]: data.drop_dims('x') Out[8]: <xarray.Dataset> Dimensions: () Data variables: z float64 3.142 ```

In this case, I dropped x, but because that eliminated variable A, I also dropped my y dimension, since A was the only variable using y.

At one point, I implemented this slightly differently, which instead gave

python In [8]: data.drop_dims('x') Out[8]: <xarray.Dataset> Dimensions: (y: 3) Dimensions without coordinates: y Data variables: z float64 3.142

In some ways, this seems preferable, especially if y has coordinates. The only downside I can see is that this version called Dataset._replace_vars_and_dims(), the docstring for which says it's deprecated (although it's still widely used).

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