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

🎨 Introduce ordered collections and simplify .mapped() #1390

Merged
merged 4 commits into from
Jan 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lamindb/_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ def from_artifacts(artifacts: Iterable[Artifact]) -> Tuple[str, Dict[str, str]]:
def mapped(
self,
label_keys: Optional[Union[str, List[str]]] = None,
join_vars: Optional[Literal["auto", "inner", "outer"]] = "auto",
join: Optional[Literal["inner", "outer"]] = "outer",
encode_labels: bool = True,
cache_categories: bool = True,
parallel: bool = False,
Expand All @@ -333,7 +333,7 @@ def mapped(
return MappedCollection(
path_list,
label_keys,
join_vars,
join,
encode_labels,
cache_categories,
parallel,
Expand Down
7 changes: 3 additions & 4 deletions lamindb/dev/_mapped_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ def __init__(
self,
path_list: List[Union[str, PathLike]],
label_keys: Optional[Union[str, List[str]]] = None,
join_vars: Optional[Literal["auto", "inner", "outer"]] = "auto",
join: Optional[Literal["inner", "outer"]] = "outer",
encode_labels: bool = True,
cache_categories: bool = True,
parallel: bool = False,
dtype: Optional[str] = None,
):
assert join_vars in {None, "auto", "inner", "outer"}
assert join in {None, "inner", "outer"}

self.storages = [] # type: ignore
self.conns = [] # type: ignore
Expand All @@ -84,7 +84,7 @@ def __init__(
self.indices = np.hstack([np.arange(n_obs) for n_obs in self.n_obs_list])
self.storage_idx = np.repeat(np.arange(len(self.storages)), self.n_obs_list)

self.join_vars = join_vars if len(path_list) > 1 else None
self.join_vars = join if len(path_list) > 1 else None
self.var_indices = None
if self.join_vars is not None:
self._make_join_vars()
Expand All @@ -100,7 +100,6 @@ def __init__(
self._make_encoders(self.label_keys)

self._dtype = dtype

self._closed = False

def _make_connections(self, path_list: list, parallel: bool):
Expand Down
2 changes: 1 addition & 1 deletion sub/lamindb-setup
2 changes: 1 addition & 1 deletion sub/lnschema-core
8 changes: 3 additions & 5 deletions tests/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,7 @@ def test_collection_mapped():
assert ls_ds.closed
del ls_ds

with collection.mapped(
label_keys="feat1", join_vars="inner", dtype="float32"
) as ls_ds:
with collection.mapped(label_keys="feat1", join="inner", dtype="float32") as ls_ds:
assert not ls_ds.closed
assert len(ls_ds) == 4
assert len(ls_ds[0]) == 2 and len(ls_ds[2]) == 2
Expand All @@ -314,8 +312,8 @@ def test_collection_mapped():
assert len(ls_ds[0]) == 2 and len(ls_ds[2]) == 2

# adata3 goes first here
with collection_outer.mapped(label_keys="feat1", join_vars="auto") as ls_ds:
assert ls_ds.join_vars == "outer"
with collection_outer.mapped(label_keys="feat1", join="inner") as ls_ds:
assert ls_ds.join_vars == "inner"
falexwolf marked this conversation as resolved.
Show resolved Hide resolved
assert len(ls_ds.var_joint) == 6
assert len(ls_ds[0]) == 2
assert len(ls_ds[0][0]) == 6
Expand Down
Loading