home / github / issues

Menu
  • GraphQL API
  • Search all tables

issues: 291485366

This data as json

id node_id number title user state locked assignee milestone comments created_at updated_at closed_at author_association active_lock_reason draft pull_request body reactions performed_via_github_app state_reason repo type
291485366 MDU6SXNzdWUyOTE0ODUzNjY= 1856 Option to make DataArray.transpose also transpose coords 4687996 closed 0     3 2018-01-25T08:20:11Z 2019-05-21T17:37:55Z 2019-05-21T17:37:55Z CONTRIBUTOR      

I've noticed that Dataset.transpose transposes the coordinates while DataArray.transpose does not.

Example:

import xarray as xr
import numpy as np

X_da = xr.DataArray(
    np.random.random((100, 10)),
    coords={'coord_1': (['sample', 'feature'], np.ones((100, 10)))},
    dims=('sample', 'feature')
)

In []: X_da.transpose().coord_1.dims
Out[]: ('sample', 'feature')

X_ds = xr.Dataset(
    {'var_1': (['sample', 'feature'], np.random.random((100, 10)))},
    coords={'coord_1': (['sample', 'feature'], np.ones((100, 10)))},
)

In []: X_ds.transpose().coord_1.dims
Out[]: ('feature', 'sample')

This behaviour is probably intentional, but there are cases where I'd like DataArray.transpose to also transpose the coordinates. As a workaround, I have to convert to a Dataset, transpose and convert back.

I was thinking that DataArray.transpose could accept a keyword argument transpose_coords which would be False by default. I could work on a PR implementing this behavior if it's desired.

{
    "url": "https://api.github.com/repos/pydata/xarray/issues/1856/reactions",
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  completed 13221727 issue

Links from other tables

  • 2 rows from issues_id in issues_labels
  • 3 rows from issue in issue_comments
Powered by Datasette · Queries took 0.72ms · About: xarray-datasette