Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unwanted name attribute from asdf NDArrayType #110

Closed
CagtayFabry opened this issue Aug 21, 2020 · 9 comments
Closed

unwanted name attribute from asdf NDArrayType #110

CagtayFabry opened this issue Aug 21, 2020 · 9 comments
Labels
ASDF everything ASDF related (python + schemas) bug Something isn't working close Mark an issue when you think it can be closed but want confimation before closing it

Comments

@CagtayFabry
Copy link
Member

There appears to happen some unlucky attribute propagation when reading from asdf ndarray -> pint.Quantity -> xarray.DataArray which makes the following fail:

ts = TimeSeries(data=Q_([40.0,20.0], "V"),time=Q_([0.0,10.0],"s"))
data = weldx.asdf.utils._write_read_buffer({"root":ts})
data["root"] == ts
>>> False

Both TimeSeries have identical values but == fails because xarray.DataArray.identical checks every attribute including DataArray.name

When reading from the ASDF file in this case the name attribute gets erroneously applied:

print(ts.data_array.name)
>>> None
print(data["root"].data_array.name)
>>> core/ndarray

The problem occurs because when creating a pint.Quantity directly from an ndarray it actually gets constructed from the asdf NDArrayType which apparently carries .name='core/ndarray'
This propagates over to the pint.Quantity and finally xarray.DataArray.

Here is a quick fix for the TimeSeries class 1dd1f23 but we should be aware of the issue and discuss how to handle this in general.

@CagtayFabry CagtayFabry added bug Something isn't working ASDF everything ASDF related (python + schemas) labels Aug 21, 2020
@marscher
Copy link
Contributor

Ain't an issue any more.

@CagtayFabry
Copy link
Member Author

CagtayFabry commented Jul 5, 2021

I think we fixed this in the TimeSeries asdf implementation?
but the general problem should still persist?

One possible idea could be to adapt asdf implementation of our quantity to remove the attribute.

@CagtayFabry
Copy link
Member Author

CagtayFabry commented Jul 5, 2021

cref #364 (comment)

relevant code:

def from_tree_mod(tree):
if "coordinates" in tree:
tree["coordinates"] = np.asarray(tree["coordinates"])
return tree

@vhirtham
Copy link
Collaborator

vhirtham commented Jul 5, 2021

So reopen?

@CagtayFabry
Copy link
Member Author

yes I think I'd like to run some more tests until finally closing this one

@CagtayFabry CagtayFabry reopened this Jul 5, 2021
@marscher
Copy link
Contributor

marscher commented Jul 5, 2021

Sorry, if this caused extra work now. I just ran the attached snippet and it didn't showed the described behavior any more.

@CagtayFabry
Copy link
Member Author

it's good to keep in mind, I'll have to think of a proper snipped for debugging

@marscher
Copy link
Contributor

marscher commented Aug 3, 2021

most likely fixed in #456

@marscher marscher added the close Mark an issue when you think it can be closed but want confimation before closing it label Aug 3, 2021
@marscher
Copy link
Contributor

marscher commented Aug 9, 2021

the linked pr fixed this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ASDF everything ASDF related (python + schemas) bug Something isn't working close Mark an issue when you think it can be closed but want confimation before closing it
Projects
None yet
Development

No branches or pull requests

3 participants