Skip to content

Commit

Permalink
Keep hash and shrink attr on save as in v0.2 by default
Browse files Browse the repository at this point in the history
Defaults will change in the next versions
  • Loading branch information
gtca committed Jul 3, 2024
1 parent a5926bf commit 211fc9c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ test = [

[tool.pytest.ini_options]
python_files = "test_*.py"
testspaths = [
testpaths = [
"./tests", # unit tests
]

Expand Down Expand Up @@ -99,4 +99,4 @@ ignore = [
"E731",
# allow I, O, l as variable names -> I is the identity matrix, i, j, k, l is reasonable indexing notation
"E741",
]
]
25 changes: 21 additions & 4 deletions src/mudata/_core/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

from .file_backing import AnnDataFileManager, MuDataFileManager
from .mudata import ModDict, MuData
from .config import OPTIONS

#
# Saving multimodal data objects
Expand All @@ -34,13 +35,21 @@ def _write_h5mu(file: h5py.File, mdata: MuData, write_data=True, **kwargs):
write_elem(
file,
"obs",
mdata.strings_to_categoricals(mdata._shrink_attr("obs", inplace=False).copy()),
mdata.strings_to_categoricals(
mdata._shrink_attr("obs", inplace=False).copy()
if OPTIONS["pull_on_update"] is None
else mdata.obs.copy()
),
dataset_kwargs=kwargs,
)
write_elem(
file,
"var",
mdata.strings_to_categoricals(mdata._shrink_attr("var", inplace=False).copy()),
mdata.strings_to_categoricals(
mdata._shrink_attr("var", inplace=False).copy()
if OPTIONS["pull_on_update"] is None
else mdata.var.copy()
),
dataset_kwargs=kwargs,
)
write_elem(file, "obsm", dict(mdata.obsm), dataset_kwargs=kwargs)
Expand Down Expand Up @@ -128,13 +137,21 @@ def write_zarr(
write_elem(
file,
"obs",
mdata.strings_to_categoricals(mdata._shrink_attr("obs", inplace=False).copy()),
mdata.strings_to_categoricals(
mdata._shrink_attr("obs", inplace=False).copy()
if OPTIONS["pull_on_update"] is None
else mdata.obs.copy()
),
dataset_kwargs=kwargs,
)
write_elem(
file,
"var",
mdata.strings_to_categoricals(mdata._shrink_attr("var", inplace=False).copy()),
mdata.strings_to_categoricals(
mdata._shrink_attr("var", inplace=False).copy()
if OPTIONS["pull_on_update"] is None
else mdata.var.copy()
),
dataset_kwargs=kwargs,
)
write_elem(file, "obsm", dict(mdata.obsm), dataset_kwargs=kwargs)
Expand Down
10 changes: 6 additions & 4 deletions src/mudata/_core/mudata.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,9 +576,7 @@ def _update_attr(

if not any(attr_changed):
# Nothing to update
# return
pass
# FIXME
return

data_global = getattr(self, attr)

Expand Down Expand Up @@ -848,7 +846,7 @@ def _update_attr_legacy(
# No _attrhash when upon read
# No _attrhash in mudata < 0.2.0
_attrhash = f"_{attr}hash"
attr_changed = self._check_changed_attr_names(attr)
attr_changed = self._check_changed_attr_names(attr, columns=True)

attr_duplicated = self._check_duplicated_attr_names(attr)
attr_intersecting = self._check_intersecting_attr_names(attr)
Expand All @@ -862,6 +860,10 @@ def _update_attr_legacy(
f"Behaviour is not defined with axis=-1, {attr}_names need to be made unique first."
)

if not any(attr_changed):
# Nothing to update
return

# Check if the are same obs_names/var_names in different modalities
# If there are, join_common=True request can not be satisfied
if join_common:
Expand Down

0 comments on commit 211fc9c

Please sign in to comment.