Skip to content

Commit c426601

Browse files
authored
Merge pull request #42 from YosefLab/read-patch
h5ad without X
2 parents 1114645 + 760a322 commit c426601

4 files changed

Lines changed: 21 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ and this project adheres to [Semantic Versioning][].
1616

1717
### Fixed
1818

19+
## [0.1.2] - 2024-12-02
20+
21+
### Added
22+
23+
### Changed
24+
25+
### Fixed
26+
27+
- Fixed `KeyError: "Unable to synchronously open object (object 'X' doesn't exist)"'` when reading h5ad without X field (#40)
28+
1929
## [0.1.1] - 2024-11-25
2030

2131
### Added

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ requires = ["hatchling"]
44

55
[project]
66
name = "treedata"
7-
version = "0.1.1"
7+
version = "0.1.2"
88
description = "anndata with trees"
99
readme = "README.md"
1010
requires-python = ">=3.10"

src/treedata/_core/read.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ def _read_tdata(f, filename, backed) -> dict:
7676
backed = "r"
7777
# Read X if not backed
7878
if not backed:
79-
d["X"] = _read_elem(f["X"])
79+
if "X" in f:
80+
d["X"] = _read_elem(f["X"])
8081
else:
8182
d.update({"filename": filename, "filemode": backed})
8283
# Read standard elements

tests/test_readwrite.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@ def test_read_anndata(X, tmp_path):
102102
assert tdata.obst_keys() == []
103103

104104

105+
def test_read_no_X(X, tmp_path):
106+
tdata = td.TreeData(obs=pd.DataFrame(index=["0", "1", "2"]))
107+
file_path = tmp_path / "test.h5ad"
108+
tdata.write_h5ad(file_path)
109+
tdata2 = td.read_h5ad(file_path)
110+
assert tdata2.X is None
111+
112+
105113
def test_h5ad_backing(tdata, tree, tmp_path):
106114
tdata_copy = tdata.copy()
107115
assert not tdata.isbacked

0 commit comments

Comments
 (0)