home / github

Menu
  • Search all tables
  • GraphQL API

issue_comments

Table actions
  • GraphQL API for issue_comments

5 rows where author_association = "NONE" and issue = 341643235 sorted by updated_at descending

✖
✖
✖

✎ View and edit SQL

This data as json, CSV (advanced)

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

user 3

  • joshburkart 3
  • DerWeh 1
  • derhintze 1

issue 1

  • Support non-string dimension/variable names · 5 ✖

author_association 1

  • NONE · 5 ✖
id html_url issue_url node_id user created_at updated_at ▲ author_association body reactions performed_via_github_app issue
979759002 https://github.com/pydata/xarray/issues/2292#issuecomment-979759002 https://api.github.com/repos/pydata/xarray/issues/2292 IC_kwDOAMm_X846Ze-a derhintze 25172489 2021-11-26T07:48:21Z 2021-11-26T07:52:42Z NONE

Would like to chime in that we use a similar approach as in the last comment of @DerWeh . But we extend this by overloading the __str__ method of the enum.Enum base class, and implement a Dimension base class to use for our enum dimensions:

``` class Dimension(str, enum.Enum): """Base class for all dimension enums

It is of type string because this is needed for xarray.
"""

def __str__(self):
    return type(self).__name__ + "." + self.name

```

Using this the xarray output is more consistent:

```

class CoordId(Dimension): ... LAT = 'lat' ... LON = 'lon' ... xr.DataArray( ... data=np.arange(3 * 2).reshape(3, 2), ... coords={CoordId.LAT: [1, 2, 3], CoordId.LON: [7, 8]}, ... dims=[CoordId.LAT, CoordId.LON], ... ) <xarray.DataArray (CoordId.LAT: 3, CoordId.LON: 2)> array([[0, 1], [2, 3], [4, 5]]) Coordinates: * CoordId.LAT (CoordId.LAT) int64 1 2 3 * CoordId.LON (CoordId.LON) int64 7 8 ```

We then have deserialization code, that re-creates enum members when reading NetCDF files with corresponding dimensions (and coordinates). Access to coordinates works with enum members as well as their string value.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  Support non-string dimension/variable names 341643235
722565840 https://github.com/pydata/xarray/issues/2292#issuecomment-722565840 https://api.github.com/repos/pydata/xarray/issues/2292 MDEyOklzc3VlQ29tbWVudDcyMjU2NTg0MA== DerWeh 22542812 2020-11-05T18:41:24Z 2020-11-05T18:41:24Z NONE

I just came along this question as I tried something similar to @joshburkart. Using a string-enum instead, the code works in principle:

```python import enum

import numpy as np import pandas as pd import xarray as xr

class CoordId(str, enum.Enum): LAT = 'lat' LON = 'lon'

pd.DataFrame({CoordId.LAT: [1,2,3]}).to_csv()

Returns: ',CoordId.LAT\n0,1\n1,2\n2,3\n'

xr.DataArray( data=np.arange(3 * 2).reshape(3, 2), coords={CoordId.LAT: [1, 2, 3], CoordId.LON: [7, 8]}, dims=[CoordId.LAT, CoordId.LON], )

output

<xarray.DataArray (lat: 3, lon: 2)>

array([[0, 1],

[2, 3],

[4, 5]])

Coordinates:

* lat (CoordId.LAT) int64 1 2 3

* lon (CoordId.LON) int64 7 8

```

We however got somewhat ambivalent results, that the dimensions are still enum elements dims = (<CoordId.LAT: 'lat'>, <CoordId.LON: 'lon'>), but the coordinate names are the strings. After writing and reading the DataArray, everything is a plain string, we can still access the elements using the enum elements, as they are equal to the strings.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  Support non-string dimension/variable names 341643235
406617353 https://github.com/pydata/xarray/issues/2292#issuecomment-406617353 https://api.github.com/repos/pydata/xarray/issues/2292 MDEyOklzc3VlQ29tbWVudDQwNjYxNzM1Mw== joshburkart 3888181 2018-07-20T14:28:07Z 2018-07-20T14:28:07Z NONE

Just to clarify @shoyer, you said (2) sounds best to you, but your other comments (e.g. duck typing, requiring hashable) seem to describe (1)...? Slightly confused...

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  Support non-string dimension/variable names 341643235
406356945 https://github.com/pydata/xarray/issues/2292#issuecomment-406356945 https://api.github.com/repos/pydata/xarray/issues/2292 MDEyOklzc3VlQ29tbWVudDQwNjM1Njk0NQ== joshburkart 3888181 2018-07-19T17:37:34Z 2018-07-19T17:37:34Z NONE

Some options that come to mind:

  1. Allow any object with a __str__ method to be supplied as a variable/dimension label, but then delegate all internal sorting/printing/etc. logic to str(label).
  2. Just implicitly run str on everything a user tries to input as a label (both when creating an xarray object and when accessing fields from an existing object), so that only strings are used internally.
  3. Put this on the user, and only allow calling xarray objects/methods/etc. with labels already strings, as you suggested @shoyer.

I dunno. Whatever the maintainers think is best? (3) seems least complex on the xarray side, but (1) or (2) might be more convenient for users.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  Support non-string dimension/variable names 341643235
405380136 https://github.com/pydata/xarray/issues/2292#issuecomment-405380136 https://api.github.com/repos/pydata/xarray/issues/2292 MDEyOklzc3VlQ29tbWVudDQwNTM4MDEzNg== joshburkart 3888181 2018-07-16T20:59:13Z 2018-07-16T20:59:13Z NONE

Thanks @shoyer. I'll see if I can take a look in the near future...

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  Support non-string dimension/variable names 341643235

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 478.832ms · About: xarray-datasette
  • Sort ascending
  • Sort descending
  • Facet by this
  • Hide this column
  • Show all columns
  • Show not-blank rows