home / github

Menu
  • Search all tables
  • GraphQL API

issue_comments

Table actions
  • GraphQL API for issue_comments

6 rows where author_association = "MEMBER" and issue = 367763373 sorted by updated_at descending

✎ View and edit SQL

This data as json, CSV (advanced)

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

user 2

  • TomNicholas 5
  • shoyer 1

issue 1

  • Recommended way to extend xarray Datasets using accessors? · 6 ✖

author_association 1

  • MEMBER · 6 ✖
id html_url issue_url node_id user created_at updated_at ▲ author_association body reactions performed_via_github_app issue
434627405 https://github.com/pydata/xarray/issues/2473#issuecomment-434627405 https://api.github.com/repos/pydata/xarray/issues/2473 MDEyOklzc3VlQ29tbWVudDQzNDYyNzQwNQ== TomNicholas 35968931 2018-10-31T09:58:05Z 2018-10-31T09:58:05Z MEMBER

2482 has now been merged which means that I can get the behaviour I want by using globally-permanent attrs to store arbitrary objects, and using accessors to attach methods to datasets.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  Recommended way to extend xarray Datasets using accessors? 367763373
429429134 https://github.com/pydata/xarray/issues/2473#issuecomment-429429134 https://api.github.com/repos/pydata/xarray/issues/2473 MDEyOklzc3VlQ29tbWVudDQyOTQyOTEzNA== TomNicholas 35968931 2018-10-12T19:05:24Z 2018-10-12T19:05:59Z MEMBER

I realised I'm massively overcomplicating this, I think all I need is the existing accessor functionality, and for attrs to always be preserved in order to get the behaviour I want. Therefore once #2482 is merged then I should be able to close this.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  Recommended way to extend xarray Datasets using accessors? 367763373
428179704 https://github.com/pydata/xarray/issues/2473#issuecomment-428179704 https://api.github.com/repos/pydata/xarray/issues/2473 MDEyOklzc3VlQ29tbWVudDQyODE3OTcwNA== TomNicholas 35968931 2018-10-09T12:52:30Z 2018-10-09T14:53:30Z MEMBER

Sorry for the triple comment, but I could also do this:

If I do this: ```python @xr.register_dataset_accessor('bout') class BoutAccessor(object): def init(self, ds_object): self._data = ds_object

def set_options(self, options):
    self.options = options

@register_dataset_accessor('storm') class StormAccessor(BoutAccessor): def init(self, ds_object): super().init(ds_object)

def special_storm_plot()
    special_storm_plot(self._data, self.options)

``` then I can have BOUT-specific attributes and methods stored via the bout accessor, all of which are inherited by the more-specific storm accessor

```python ds = collect_data(path) options_obj = get_options(path)

ds.storm.set_options(options_obj) # access inherited methods from the bout accessor to store arbitrary extra data

ds.storm.special_storm_plot() # use data from the bout accessor when calling more-specific methods form the storm accessor

```

However then my attached objects don't survive the calling of xarray methods: python ds.storm.extra_info = 'options' new_ds = ds.isel(t=-1) print(new_ds.storm.extra_info) # AttributeError: 'StormAccessor' object has no attribute 'extra_info'

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  Recommended way to extend xarray Datasets using accessors? 367763373
428170843 https://github.com/pydata/xarray/issues/2473#issuecomment-428170843 https://api.github.com/repos/pydata/xarray/issues/2473 MDEyOklzc3VlQ29tbWVudDQyODE3MDg0Mw== TomNicholas 35968931 2018-10-09T12:21:53Z 2018-10-09T12:21:53Z MEMBER

Or alternatively I suppose I could just store my options as an attribute on the accessor: ```python ds = collect_data(path) ds.bout.options = options_obj

Now I have an object which stores all the data I want

print(ds.bout.options) ```

That seems to be what I should have tried first.

In that case would it be possible to have multiple accessors, one for the core bout functionality and others for extensions for even-more-specific users? i.e an accessor for a code called Storm which is based on BOUT++: ```python print(ds) # xarray dataset

print(ds.bout.options) # BOUT-specific extra information

print(ds.storm.special_storm_plot()) # storm-user-group-specific method ``` Can an accessor inherit from another accessor class?

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  Recommended way to extend xarray Datasets using accessors? 367763373
428152588 https://github.com/pydata/xarray/issues/2473#issuecomment-428152588 https://api.github.com/repos/pydata/xarray/issues/2473 MDEyOklzc3VlQ29tbWVudDQyODE1MjU4OA== TomNicholas 35968931 2018-10-09T11:10:46Z 2018-10-09T11:10:46Z MEMBER

Accessors should only accept one argument, which is an xarray.Dataset.

Ah - I misunderstood how they work, if I do this:

```python @xr.register_dataset_accessor('bout') class BoutDataset(object): def init(self, ds_object): self.data = ds_object

def plot_tokamak():
    plot_in_bout_specific_way(self.data, self.extra_data)

then I can successfully use it like this:python ds = collect_data(path)

ds.bout.plot_tokamak() print(ds.bout.data) ``` Thanks!

What does your extra_data look like? Would it be possible to put it into xarray in the form of coordinates or attributes?

My extra_data is a nested-dictionary-like object containing everything in the simulation input file. This I can store in the attributes dictionary (that's what I'm doing at the moment), but I'm still interested in the problem of attaching arbitrary objects because because losing the attributes on operations is annoying and I envisage either myself or other users of the code wanting to store more complicated structures in the future. (For example an xgcm grid object)

Also the philosophy of the BOUT framework encourages each group of users to add their own functionality depending on what exactly they are solving. Some kind of base BoutDataset class which could then be further subclassed to add more specific functionality would fit best with this system. Would it be a terrible idea to subclass xr.Dataset into a BoutDataset, then decorate every inherited method by looping over them so that my extra attached objects are dealt with appropriately (maybe like this)? Would that not in theory give me the whole API of xarray while allowing me to attach arbitrary objects and methods to my class, and allowing further subclassing if desired?

(Sorry if this is too far off the topic of xarray, feel free to close it if you think this is not going to be relevant to any of the rest of the community.)

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  Recommended way to extend xarray Datasets using accessors? 367763373
427927907 https://github.com/pydata/xarray/issues/2473#issuecomment-427927907 https://api.github.com/repos/pydata/xarray/issues/2473 MDEyOklzc3VlQ29tbWVudDQyNzkyNzkwNw== shoyer 1217238 2018-10-08T18:06:23Z 2018-10-08T18:06:23Z MEMBER

Your use of an xarray accessor class looks a little funny to me. Accessors should only accept one argument, which is an xarray.Dataset. If you want to make your own objects, that's fine, but I don't think there's any point in making them an accessor.

What does your extra_data look like? Would it be possible to put it into xarray in the form of coordinates or attributes? If so, that would probably be the preferred path.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  Recommended way to extend xarray Datasets using accessors? 367763373

Advanced export

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

CSV options:

CREATE TABLE [issue_comments] (
   [html_url] TEXT,
   [issue_url] TEXT,
   [id] INTEGER PRIMARY KEY,
   [node_id] TEXT,
   [user] INTEGER REFERENCES [users]([id]),
   [created_at] TEXT,
   [updated_at] TEXT,
   [author_association] TEXT,
   [body] TEXT,
   [reactions] TEXT,
   [performed_via_github_app] TEXT,
   [issue] INTEGER REFERENCES [issues]([id])
);
CREATE INDEX [idx_issue_comments_issue]
    ON [issue_comments] ([issue]);
CREATE INDEX [idx_issue_comments_user]
    ON [issue_comments] ([user]);
Powered by Datasette · Queries took 13.903ms · About: xarray-datasette