home / github

Menu
  • GraphQL API
  • Search all tables

issues

Table actions
  • GraphQL API for issues

1 row where state = "closed", type = "issue" and user = 9399446 sorted by updated_at descending

✎ View and edit SQL

This data as json, CSV (advanced)

Suggested facets: created_at (date), updated_at (date), closed_at (date)

type 1

  • issue · 1 ✖

state 1

  • closed · 1 ✖

repo 1

  • xarray 1
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
834273555 MDU6SXNzdWU4MzQyNzM1NTU= 5048 Ability to rename items inside a coordinate, matching pandas rename() functionality Jeitan 9399446 closed 0     6 2021-03-18T00:15:04Z 2022-04-18T15:52:31Z 2022-04-18T15:52:30Z NONE      

I have by necessity been converting a bunch of code that used pandas Panels to xarray, but I seem to have hit the fact that the xarray "renaming" functionality is not, in fact, related at all to the pandas "rename," and there appears to be no functionality for the latter in xarray.

Describe the solution you'd like I want to be able to rename specific items inside of a coordinate, which for 2D DataArrays is analogous to renaming a column in a pandas DataFrame.

For example, let's say I have the following DataArray in variable da: da = xr.DataArray(np.random.randn(3, 5), dims=['one', 'two'], coords={'one': [1, 2, 3], 'two': ['a', 'b', 'c', 'dd', 'e']}) Gives me <xarray.DataArray (one: 3, two: 5)> array([[-0.06079764, -0.54747953, 0.30818265, -1.66491362, 0.73121399], [-1.0309981 , 1.54785819, -1.23288457, 0.30912773, 1.24241736], [-0.5355933 , 0.08441669, 0.70498245, 0.1723775 , -1.06150325]]) Coordinates: * one (one) int32 1 2 3 * two (two) <U2 'a' 'b' 'c' 'dd' 'e'

Let's pretend that the 'dd' should be 'd' and is a typo from something outside of my control. If that were a Pandas DataFrame, I could just do df.rename({'dd':'d'}, axis=1). I want to be able to do something similar in xarray, e.g.

da.rename({'two': {'dd': 'd'}}) or da.rename({'dd': 'd'}, dim='two') or anything similar, whatever it may be called.

I found this issue #4825 on renaming/resetting/setting, etc. but everything listed there deals with the whole coordinate, not the innards of one. The only thing I've found that allows what I want to do is assign_coords, but that requires me to iterate over the coordinate myself (and in the case of strings, call .item() on it while I'm doing it, but that's a separate annoyance) to make the new coordinates. This is what I have done to make this work: rdict = {'dd': 'd'} coordlist = [k.item() for k in da.coords['two']] newlist = [rdict[k] if k in rdict else k for k in coordlist] da = da.assign_coords(dict(two=newlist))

It's exceedingly cumbersome. If there is already a way to do this and I'm just missing it, please just let me know and I will be super happy to go off and eat my crow and use the existing method. If not, I think this is actually a really important functionality. It may even be a deal-breaker for me ... I have to rename columns a LOT.

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

Advanced export

JSON shape: default, array, newline-delimited, object

CSV options:

CREATE TABLE [issues] (
   [id] INTEGER PRIMARY KEY,
   [node_id] TEXT,
   [number] INTEGER,
   [title] TEXT,
   [user] INTEGER REFERENCES [users]([id]),
   [state] TEXT,
   [locked] INTEGER,
   [assignee] INTEGER REFERENCES [users]([id]),
   [milestone] INTEGER REFERENCES [milestones]([id]),
   [comments] INTEGER,
   [created_at] TEXT,
   [updated_at] TEXT,
   [closed_at] TEXT,
   [author_association] TEXT,
   [active_lock_reason] TEXT,
   [draft] INTEGER,
   [pull_request] TEXT,
   [body] TEXT,
   [reactions] TEXT,
   [performed_via_github_app] TEXT,
   [state_reason] TEXT,
   [repo] INTEGER REFERENCES [repos]([id]),
   [type] TEXT
);
CREATE INDEX [idx_issues_repo]
    ON [issues] ([repo]);
CREATE INDEX [idx_issues_milestone]
    ON [issues] ([milestone]);
CREATE INDEX [idx_issues_assignee]
    ON [issues] ([assignee]);
CREATE INDEX [idx_issues_user]
    ON [issues] ([user]);
Powered by Datasette · Queries took 20.293ms · About: xarray-datasette