diff --git a/anndata/_core/views.py b/anndata/_core/views.py index c81eb6824..46add57b7 100644 --- a/anndata/_core/views.py +++ b/anndata/_core/views.py @@ -4,7 +4,7 @@ from copy import deepcopy from collections.abc import Sequence, KeysView, Callable, Iterable, Mapping from functools import reduce, singledispatch, wraps -from typing import Any, Literal +from typing import Any, Literal, Dict, cast import warnings import numpy as np @@ -295,8 +295,8 @@ def __copy__(self) -> AwkArray: """ array = self # makes a shallow copy and removes the reference to the original AnnData object - array = ak.with_parameter(self, _PARAM_NAME, None) - array = ak.with_parameter(array, "__list__", None) + array = ak.with_parameter(array, _PARAM_NAME, None) + array = ak.with_parameter(array, "__record__", None) return array @as_view.register(AwkArray) @@ -308,15 +308,16 @@ def as_view_awkarray(array, view_args): # possible strategies to stack behaviors. # A better solution might be based on xarray-style "attrs", once this is implemented # https://github.com/scikit-hep/awkward/issues/1391#issuecomment-1412297114 - if type(array).__name__ != "Array": + if "__record__" in cast(Dict, ak.parameters(array)): raise NotImplementedError( - "Cannot create a view of an awkward array with __array__ parameter. " + "Cannot create a view of an awkward array with __record__ parameter. " "Please open an issue in the AnnData repo and describe your use-case." ) array = ak.with_parameter(array, _PARAM_NAME, (parent_key, attrname, keys)) - array = ak.with_parameter(array, "__list__", "AwkwardArrayView") + array = ak.with_parameter(array, "__record__", "AwkwardArrayView") return array + ak.behavior["*", "AwkwardArrayView"] = AwkwardArrayView ak.behavior["AwkwardArrayView"] = AwkwardArrayView except ImportError: diff --git a/anndata/tests/test_awkward.py b/anndata/tests/test_awkward.py index 87280d5a2..89142eccb 100644 --- a/anndata/tests/test_awkward.py +++ b/anndata/tests/test_awkward.py @@ -159,7 +159,7 @@ def reversed(self): ak.behavior[BEHAVIOUR_ID] = ReversibleArray adata = gen_adata((3, 3), varm_types=(), obsm_types=(), layers_types=()) adata.obsm["awk_string"] = ak.with_parameter( - ak.Array(["AAA", "BBB", "CCC"]), "__list__", BEHAVIOUR_ID + ak.Array(["AAA", "BBB", "CCC"]), "__record__", BEHAVIOUR_ID ) adata_view = adata[:2]