Skip to content

Commit

Permalink
Standardize behaviour: error if directory doesn't exist, error if no …
Browse files Browse the repository at this point in the history
…objects passed
  • Loading branch information
ivirshup committed Oct 5, 2023
1 parent 1f3150c commit 9bf0b30
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
7 changes: 5 additions & 2 deletions anndata/experimental/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ def concat_on_disk(
Name: count, dtype: int64
"""
if len(in_files) == 0:
return
raise ValueError("No objects to concatenate.")

# Argument normalization
if pairwise:
Expand All @@ -537,8 +537,11 @@ def concat_on_disk(

merge = resolve_merge_strategy(merge)
uns_merge = resolve_merge_strategy(uns_merge)

out_file = Path(out_file)
out_file.parent.mkdir(parents=True, exist_ok=True)
if not out_file.parent.exists():
raise FileNotFoundError(f"Parent directory of {out_file} does not exist.")

if isinstance(in_files, Mapping):
if keys is not None:
raise TypeError(
Expand Down
15 changes: 15 additions & 0 deletions anndata/tests/test_concatenate_disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,18 @@ def gen_index(n):

def test_concatenate_obsm_inner(obsm_adatas, tmp_path, file_format):
assert_eq_concat_on_disk(obsm_adatas, tmp_path, file_format, join="inner")


def test_output_dir_exists(tmp_path):
in_pth = tmp_path / "in.h5ad"
out_pth = tmp_path / "does_not_exist" / "out.h5ad"

AnnData(X=np.ones((5, 1))).write_h5ad(in_pth)

with pytest.raises(FileNotFoundError, match=f"{out_pth}"):
concat_on_disk([in_pth], out_pth)


def test_failure_w_no_args(tmp_path):
with pytest.raises(ValueError, match="No objects to concatenate"):
concat_on_disk([], tmp_path / "out.h5ad")

0 comments on commit 9bf0b30

Please sign in to comment.