Skip to content

Commit

Permalink
[asdf] Do not copy array data (#456)
Browse files Browse the repository at this point in the history
* only cast to ndarray, if not a time type. This makes asdf copy_arrays flag effective again.
* explicitly set DataArray.name to None, to prevent it being derived from ndarray.name (which is used for asdf.NDarraytype wrapper).


Co-authored-by: Cagtay Fabry <43667554+CagtayFabry@users.noreply.github.com>
  • Loading branch information
marscher and CagtayFabry authored Aug 3, 2021
1 parent 6472d6e commit 46459b0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 6 additions & 1 deletion weldx/asdf/tags/weldx/core/common_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,12 @@ def from_tree(cls, tree, ctx):
"""
dtype = np.dtype(tree["dtype"])
data = np.array(tree["data"], dtype=dtype)
# TODO: it would be ideal, if asdf would handle time types natively.
if dtype.char in ("M", "m"): # handle np.timedelta64 and np.datetime64
data = np.array(tree["data"], dtype=dtype)
# assert data.base is tree["data"]
else:
data = tree["data"] # let asdf handle np arrays with its own wrapper.
if "unit" in tree: # convert to pint.Quantity
data = Q_(data, tree["unit"])

Expand Down
3 changes: 3 additions & 0 deletions weldx/asdf/tags/weldx/core/data_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,7 @@ def from_tree(cls, tree, ctx):
attrs = tree["attributes"]

da = DataArray(data=data, coords=coords, dims=dims, attrs=attrs)
da.name = None # we currently do not use the name attribute
# (but since it gets automatically derived if not set, we define it now.

return da

0 comments on commit 46459b0

Please sign in to comment.