home / github

Menu
  • Search all tables
  • GraphQL API

issue_comments

Table actions
  • GraphQL API for issue_comments

8 rows where issue = 365438396 and user = 6628425 sorted by updated_at descending

✎ View and edit SQL

This data as json, CSV (advanced)

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

user 1

  • spencerkclark · 8 ✖

issue 1

  • da.loc[date[0]] brings up two instead of one · 8 ✖

author_association 1

  • MEMBER 8
id html_url issue_url node_id user created_at updated_at ▲ author_association body reactions performed_via_github_app issue
426398519 https://github.com/pydata/xarray/issues/2450#issuecomment-426398519 https://api.github.com/repos/pydata/xarray/issues/2450 MDEyOklzc3VlQ29tbWVudDQyNjM5ODUxOQ== spencerkclark 6628425 2018-10-02T19:21:45Z 2018-10-02T19:21:45Z MEMBER

This seems like an xarray version issue; the other argument was not added to where until version 0.10.0. Are you running this script on a different platform than before? I'm surprised your original code, https://github.com/pydata/xarray/issues/2450#issuecomment-426346137, didn't raise the same error.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  da.loc[date[0]] brings up two instead of one 365438396
426392397 https://github.com/pydata/xarray/issues/2450#issuecomment-426392397 https://api.github.com/repos/pydata/xarray/issues/2450 MDEyOklzc3VlQ29tbWVudDQyNjM5MjM5Nw== spencerkclark 6628425 2018-10-02T19:01:16Z 2018-10-02T19:01:16Z MEMBER

Gonna try with just the first of the four

👍 let me know how it goes.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  da.loc[date[0]] brings up two instead of one 365438396
426381265 https://github.com/pydata/xarray/issues/2450#issuecomment-426381265 https://api.github.com/repos/pydata/xarray/issues/2450 MDEyOklzc3VlQ29tbWVudDQyNjM4MTI2NQ== spencerkclark 6628425 2018-10-02T18:27:17Z 2018-10-02T18:27:17Z MEMBER

Does complete_shear happen to return more than one DataArray?

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  da.loc[date[0]] brings up two instead of one 365438396
426374411 https://github.com/pydata/xarray/issues/2450#issuecomment-426374411 https://api.github.com/repos/pydata/xarray/issues/2450 MDEyOklzc3VlQ29tbWVudDQyNjM3NDQxMQ== spencerkclark 6628425 2018-10-02T18:07:16Z 2018-10-02T18:07:16Z MEMBER

@am-thyst could you show all the code that you used to try it out? If I run all the lines (from 1-8 in https://github.com/pydata/xarray/issues/2450#issuecomment-426340226 and https://github.com/pydata/xarray/issues/2450#issuecomment-426353764) in my IPython console things work for me.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  da.loc[date[0]] brings up two instead of one 365438396
426353764 https://github.com/pydata/xarray/issues/2450#issuecomment-426353764 https://api.github.com/repos/pydata/xarray/issues/2450 MDEyOklzc3VlQ29tbWVudDQyNjM1Mzc2NA== spencerkclark 6628425 2018-10-02T17:07:37Z 2018-10-02T17:07:37Z MEMBER

@am-thyst thanks for the extra details -- try out my method -- I think it does the same thing. Well perhaps you'll just need to multiply the result by 100 at the end and use >= instead of > for the threshold condition :)

Your approach can also be vectorized in such a way that you don't need to manually iterate over the individual times: ``` In [6]: b = da.where(da >= threshold, other=0)

In [7]: c = b.where(b == 0, other=1)

In [8]: (c.sum('time') / c.sizes['time']) * 100 Out[8]: <xarray.DataArray (x: 2, y: 3)> array([[ 25., 50., 25.], [ 25., 50., 50.]]) Dimensions without coordinates: x, y `` Effectivelyda >= threshold` in my earlier example is shorthand for lines 6 and 7 from the example above (and taking the mean is the same as summing over the dimension and dividing by the number of elements along that dimension).

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  da.loc[date[0]] brings up two instead of one 365438396
426340226 https://github.com/pydata/xarray/issues/2450#issuecomment-426340226 https://api.github.com/repos/pydata/xarray/issues/2450 MDEyOklzc3VlQ29tbWVudDQyNjM0MDIyNg== spencerkclark 6628425 2018-10-02T16:28:42Z 2018-10-02T16:28:42Z MEMBER

I'm not sure if I'm understanding the calculation correctly; is something like the following what you are looking for? ``` In [1]: import numpy as np; import pandas as pd; import xarray as xr

In [2]: times = pd.date_range('1979', periods=4, freq='12H')

In [3]: da = xr.DataArray(np.random.rand(4, 2, 3), coords={'time': times}, dims=['time', 'x', 'y'])

In [4]: threshold = 0.5

In [5]: (da > threshold).mean('time') Out[5]: <xarray.DataArray (x: 2, y: 3)> array([[ 0.25, 0.5 , 0.25], [ 0.25, 0.5 , 0.5 ]]) Dimensions without coordinates: x, y ```

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  da.loc[date[0]] brings up two instead of one 365438396
426317958 https://github.com/pydata/xarray/issues/2450#issuecomment-426317958 https://api.github.com/repos/pydata/xarray/issues/2450 MDEyOklzc3VlQ29tbWVudDQyNjMxNzk1OA== spencerkclark 6628425 2018-10-02T15:27:59Z 2018-10-02T15:36:28Z MEMBER

@am-thyst could you provide more details on what sort of operation you are trying to do with each time slice? Typically this kind of process can be better handled in a vectorized way (i.e. without manually iterating over the times).

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  da.loc[date[0]] brings up two instead of one 365438396
426250976 https://github.com/pydata/xarray/issues/2450#issuecomment-426250976 https://api.github.com/repos/pydata/xarray/issues/2450 MDEyOklzc3VlQ29tbWVudDQyNjI1MDk3Ng== spencerkclark 6628425 2018-10-02T12:16:03Z 2018-10-02T12:16:03Z MEMBER

Thanks @am-thyst, this happens to be expected behavior. For a dimension indexed by a DatetimeIndex (e.g. your 'time' dimension), label-based indexing with strings uses so-called "partial string indexing". This behavior in xarray is inherited from pandas. Essentially what it means is that if you provide a string to a label-based indexer (like .loc), then it will return values from all times that would begin with the string you provided if expressed in string form. So, in your example, if you provide only the year, month, and day (e.g. '1979-01-01') it will return values from '1979-01-01' and 1979-01-01T12:00:00, because both string representations start with '1979-01-01'.

As you inferred, if you add detail to the string you provide, you can refine the selection. That said, you need to be careful of the format you use (I think the reason you get a KeyError in your second example is that pandas does not know how to interpret the string you provided). While pandas has some flexibility in how it parses datetime-strings I might recommend sticking to the ISO 8601 format, which should work in all cases. For example to select just the values associated with the first date in your array you could do something like this: ``` In [1]: import numpy as np; import pandas as pd; import xarray as xr

In [2]: times = pd.date_range('1979', periods=8, freq='12H')

In [3]: da = xr.DataArray(np.arange(8), coords=[times], dims=['time'])

In [4]: da Out[4]: <xarray.DataArray (time: 8)> array([0, 1, 2, 3, 4, 5, 6, 7]) Coordinates: * time (time) datetime64[ns] 1979-01-01 ... 1979-01-04T12:00:00

In [5]: da.loc['1979-01-01T00'] Out[5]: <xarray.DataArray ()> array(0) Coordinates: time datetime64[ns] 1979-01-01 One other thing to note, in general, is that you can pass datetimes themselves to label-based indexers if you want to select specific dates; this way you don't need to go through the intermediate step of converting a date to a string: In [6]: da.loc[datetime(1979, 1, 1)] Out[6]: <xarray.DataArray ()> array(0) Coordinates: time datetime64[ns] 1979-01-01 ```

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  da.loc[date[0]] brings up two instead of one 365438396

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 38.314ms · About: xarray-datasette