home / github

Menu
  • Search all tables
  • GraphQL API

issue_comments

Table actions
  • GraphQL API for issue_comments

12 rows where issue = 423742774 sorted by updated_at descending

✎ View and edit SQL

This data as json, CSV (advanced)

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

user 6

  • phockett 4
  • headtr1ck 4
  • dcherian 1
  • keewis 1
  • Ch-Meier 1
  • DerPlankton13 1

author_association 4

  • COLLABORATOR 4
  • CONTRIBUTOR 4
  • MEMBER 2
  • NONE 2

issue 1

  • Dataset.copy(deep=True) does not deepcopy .attrs · 12 ✖
id html_url issue_url node_id user created_at updated_at ▲ author_association body reactions performed_via_github_app issue
1256553736 https://github.com/pydata/xarray/issues/2835#issuecomment-1256553736 https://api.github.com/repos/pydata/xarray/issues/2835 IC_kwDOAMm_X85K5X0I phockett 4447466 2022-09-23T18:47:58Z 2022-09-27T15:00:51Z CONTRIBUTOR

Just for the record, I just ran into this for the specific case of nested dictionary attrs in Dataarray.attrs.

It's definitely an issue in 2022.3.0 and 2022.6.0. Here's a minimal test example in case anyone else runs into this too...

```python

MINIMAL EXAMPLE

import xarray as xr import numpy as np

data = xr.DataArray(np.random.randn(2, 3), dims=("x", "y"), coords={"x": [10, 20]}) data.attrs['flat']='0' data.attrs['nested']={'level1':'1'}

data2 = data.copy(deep=True) data2.attrs['flat']='2' # OK

data2.attrs['nested']={'level1':'2'} # OK

data2.attrs['nested']['level1'] = '2' # Fails - overwrites data

data2.attrs['nested'].update({'level1':'2'}) # Fails - overwrites data

print(data.attrs) print(data2.attrs) ```

Outputs

In XR 2022.3.0 and 2022.6.0 this gives (incorrect): ``` {'flat': '0', 'nested': {'level1': '2'}} {'flat': '2', 'nested': {'level1': '2'}}

```

As a work-around, safe attrs copy with deepcopy works:

```python data2 = data.copy(deep=True) data2.attrs = copy.deepcopy(data.attrs)

```

With correct results after modification: ``` {'flat': '0', 'nested': {'level1': '1'}} {'flat': '2', 'nested': {'level1': '2'}}

```

EDIT 26th Sept: retested in 2022.6.0 and found it was, in fact, failing there too. Updated comment to reflect this.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  Dataset.copy(deep=True) does not deepcopy .attrs 423742774
1258611190 https://github.com/pydata/xarray/issues/2835#issuecomment-1258611190 https://api.github.com/repos/pydata/xarray/issues/2835 IC_kwDOAMm_X85LBOH2 phockett 4447466 2022-09-26T20:43:01Z 2022-09-26T20:43:01Z CONTRIBUTOR

Ok, I thought that copying attrs was fixed. Seems like it did not...

Sorry for the mix-up there - think I initially tested in 2022.6 with the extra data2.attrs = copy.deepcopy(data.attrs) implemented. Caught it with the new test routine 😄

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  Dataset.copy(deep=True) does not deepcopy .attrs 423742774
1258593420 https://github.com/pydata/xarray/issues/2835#issuecomment-1258593420 https://api.github.com/repos/pydata/xarray/issues/2835 IC_kwDOAMm_X85LBJyM headtr1ck 43316012 2022-09-26T20:28:28Z 2022-09-26T20:28:28Z COLLABORATOR

Ok, I thought that copying attrs was fixed. Seems like it did not... I will create a PR to fix this first, then we can use your test :)

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  Dataset.copy(deep=True) does not deepcopy .attrs 423742774
1258538050 https://github.com/pydata/xarray/issues/2835#issuecomment-1258538050 https://api.github.com/repos/pydata/xarray/issues/2835 IC_kwDOAMm_X85LA8RC phockett 4447466 2022-09-26T19:48:39Z 2022-09-26T19:52:14Z CONTRIBUTOR

OK, new test now pushed as #7086. (Hopefully added in the right place and style!)

A couple of additional notes:

  • Revision to my comment above: this actually fails in 2022.3 and 2022.6 for nested attribs.
  • I took a look at the source code in dataarray.py, but couldn't see an obvious way to fix this and/or didn't understand the attrs copying process generally.
  • I tested the equivalent case for DataSet attrs too (see below), and this seems fine as per your previous comments above, so I think https://github.com/pydata/xarray/pull/2839 (which includes a ds level test) still applies to ds.attrs, however the issue does affect the individual arrays within the dataset still (as expected).

```python import xarray as xr

ds = xr.Dataset({"a": (["x"], [1, 2, 3])}, attrs={"t": 1, "nested":{"t2": 1}}) ds.a.attrs = {"t": 'a1', "nested":{"t2": 'a1'}}

ds2 = ds.copy(deep=True) ds.attrs["t"] = 5 ds.attrs["nested"]["t2"] = 10

ds2.a.attrs["t"] = 'a2' ds2.a.attrs["nested"]["t2"] = 'a2'

print(ds.attrs) print(ds.a.attrs) print(ds2.attrs) print(ds2.a.attrs)

```

Results in:

``` {'t': 5, 'nested': {'t2': 10}} {'t': 'a1', 'nested': {'t2': 'a2'}} {'t': 1, 'nested': {'t2': 1}} {'t': 'a2', 'nested': {'t2': 'a2'}}

```

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  Dataset.copy(deep=True) does not deepcopy .attrs 423742774
1258235669 https://github.com/pydata/xarray/issues/2835#issuecomment-1258235669 https://api.github.com/repos/pydata/xarray/issues/2835 IC_kwDOAMm_X85K_ycV headtr1ck 43316012 2022-09-26T15:41:22Z 2022-09-26T15:41:22Z COLLABORATOR

Absolutely @headtr1ck, glad that it was useful - I'm a bit green re: tests and PRs to large projects, but will make a stab at it. I'm just consulting the Contributing guide now.

Great! Just ask if you need help :)

Basically: fork repo, make new branch on your forked repo, add test, create PR (when you push GitHub should show a popup asking if you want to create a PR anyway).

{
    "total_count": 1,
    "+1": 1,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  Dataset.copy(deep=True) does not deepcopy .attrs 423742774
1258231700 https://github.com/pydata/xarray/issues/2835#issuecomment-1258231700 https://api.github.com/repos/pydata/xarray/issues/2835 IC_kwDOAMm_X85K_xeU phockett 4447466 2022-09-26T15:38:18Z 2022-09-26T15:38:18Z CONTRIBUTOR

Absolutely @headtr1ck, glad that it was useful - I'm a bit green re: tests and PRs to large projects, but will make a stab at it. I'm just consulting the Contributing guide now.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  Dataset.copy(deep=True) does not deepcopy .attrs 423742774
1256569748 https://github.com/pydata/xarray/issues/2835#issuecomment-1256569748 https://api.github.com/repos/pydata/xarray/issues/2835 IC_kwDOAMm_X85K5buU headtr1ck 43316012 2022-09-23T18:59:33Z 2022-09-23T18:59:33Z COLLABORATOR

I see, so it was a problem of recursively copying the attrs. @phockett would you be open to add your example as a test in a PR such that we can avoid this in the future?

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  Dataset.copy(deep=True) does not deepcopy .attrs 423742774
1236379727 https://github.com/pydata/xarray/issues/2835#issuecomment-1236379727 https://api.github.com/repos/pydata/xarray/issues/2835 IC_kwDOAMm_X85JsahP keewis 14808389 2022-09-04T17:01:05Z 2022-09-04T17:01:05Z MEMBER

even with python In [1]: import xarray as xr ...: ...: ds = xr.Dataset({"a": ("x", [1, 2, 3], {"t": 0})}, attrs={"t": 1}) ...: ds2 = ds.copy(deep=True) ...: ds.attrs["t"] = 5 ...: ds.a.attrs["t"] = 6 ...: ...: display(ds2, ds2.a) <xarray.Dataset> Dimensions: (x: 3) Dimensions without coordinates: x Data variables: a (x) int64 1 2 3 Attributes: t: 1 <xarray.DataArray 'a' (x: 3)> array([1, 2, 3]) Dimensions without coordinates: x Attributes: t: 0 I cannot reproduce. @Ch-Meier, @DerPlankton13, can either of you post a minimal example demonstrating the issue?

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  Dataset.copy(deep=True) does not deepcopy .attrs 423742774
1236356402 https://github.com/pydata/xarray/issues/2835#issuecomment-1236356402 https://api.github.com/repos/pydata/xarray/issues/2835 IC_kwDOAMm_X85JsU0y headtr1ck 43316012 2022-09-04T14:41:39Z 2022-09-04T14:41:39Z COLLABORATOR

Cannot reproduce on current master using ```python import xarray as xr

ds = xr.Dataset({"a": (["x"], [1, 2, 3])}, attrs={"t": 1}) ds2 = ds.copy(deep=True) ds.attrs["t"] = 5 print(ds2.attrs) # returns: {'t': 1} ```

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  Dataset.copy(deep=True) does not deepcopy .attrs 423742774
1194130964 https://github.com/pydata/xarray/issues/2835#issuecomment-1194130964 https://api.github.com/repos/pydata/xarray/issues/2835 IC_kwDOAMm_X85HLP4U Ch-Meier 18261501 2022-07-25T14:33:32Z 2022-07-25T14:33:54Z NONE

Jumping from 2022.3.0 to 2022.6.0 this issue has re-emerged for me.

I am seeing the same issue as well.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  Dataset.copy(deep=True) does not deepcopy .attrs 423742774
1194129373 https://github.com/pydata/xarray/issues/2835#issuecomment-1194129373 https://api.github.com/repos/pydata/xarray/issues/2835 IC_kwDOAMm_X85HLPfd DerPlankton13 69301768 2022-07-25T14:32:18Z 2022-07-25T14:32:18Z NONE

Jumping from 2022.3.0 to 2022.6.0 this issue has re-emerged for me.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  Dataset.copy(deep=True) does not deepcopy .attrs 423742774
475263182 https://github.com/pydata/xarray/issues/2835#issuecomment-475263182 https://api.github.com/repos/pydata/xarray/issues/2835 MDEyOklzc3VlQ29tbWVudDQ3NTI2MzE4Mg== dcherian 2448579 2019-03-21T14:56:03Z 2019-03-21T14:56:03Z MEMBER

Thanks @kefirbandi, can you send in a PR?

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  Dataset.copy(deep=True) does not deepcopy .attrs 423742774

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