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

fix: bug where Phenotypes.subset(inplace=True) would raise an AttributeError #226

Merged
merged 7 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
Loading