Skip to content

Commit

Permalink
fix: bug where Phenotypes.subset(inplace=True) would raise an Attri…
Browse files Browse the repository at this point in the history
…buteError (#226)
  • Loading branch information
aryarm authored Oct 3, 2023
1 parent 7856638 commit cff6d9b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
6 changes: 5 additions & 1 deletion .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@

version: 2

build:
os: "ubuntu-22.04"
tools:
python: "3.7"

sphinx:
configuration: docs/conf.py
fail_on_warning: true

python:
version: 3.7
install:
- method: pip
path: .
Expand Down
4 changes: 2 additions & 2 deletions haptools/data/genotypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,8 +599,8 @@ def check_maf(
self.variants = np.delete(self.variants, idx)
maf = np.delete(maf, idx)
self.log.info(
"Ignoring missing genotypes from "
f"{original_num_variants - len(self.variants)} samples"
f"Ignoring {original_num_variants - len(self.variants)} variants "
f"with MAF < {threshold}"
)
self._var_idx = None
else:
Expand Down
2 changes: 1 addition & 1 deletion haptools/data/phenotypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ def subset(
)
name_idx = tuple(self._name_idx[name] for name in pts.names)
if inplace:
self._pts.names = None
self._name_idx = None
pts.data = pts.data[:, name_idx]
if not inplace:
return pts
12 changes: 12 additions & 0 deletions tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,18 @@ def test_subset_phenotypes(self):
np.testing.assert_allclose(pts_sub.data, expected_data)
assert np.array_equal(pts_sub.names, expected_names)

# also try in-place
expected_data = pts.data[[3, 4], [1]]
expected_data = expected_data[:, np.newaxis]
assert len(expected_data.shape) == 2
expected_names = (pts.names[1],)
samples = ("HG00100", "HG00101")
names = ("bmi",)
pts.subset(samples=samples, names=names, inplace=True)
assert pts_sub.samples == samples
np.testing.assert_allclose(pts_sub.data, expected_data)
assert np.array_equal(pts_sub.names, expected_names)


class TestCovariates:
def _get_expected_covariates(self):
Expand Down

0 comments on commit cff6d9b

Please sign in to comment.