From 6e81b5f8637008eb3e5390e61e489a170fc9fb5d Mon Sep 17 00:00:00 2001 From: Nick Harding Date: Thu, 30 May 2019 11:59:04 +0100 Subject: [PATCH 1/4] Fix for dask to_allele_counts chunks was not being passed to the method also needed to specify drop_ and new_ axis --- allel/model/dask.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/allel/model/dask.py b/allel/model/dask.py index 50639818..4783b734 100644 --- a/allel/model/dask.py +++ b/allel/model/dask.py @@ -318,7 +318,7 @@ def __getitem__(self, item): return index_genotype_array(self, item, array_cls=type(self), vector_cls=GenotypeDaskVector) - def _method(self, method_name, chunks=None, drop_axis=None, dtype=None, **kwargs): + def _method(self, method_name, chunks=None, drop_axis=None, new_axis=None, dtype=None, **kwargs): if chunks is None: # no shape change chunks = self.chunks @@ -330,7 +330,7 @@ def f(block): g = array_cls(block) method = getattr(g, method_name) return method(**kwargs) - out = da.map_blocks(f, self.values, drop_axis=drop_axis, dtype=dtype) + out = da.map_blocks(f, self.values, chunks=chunks, drop_axis=drop_axis, new_axis=new_axis, dtype=dtype) else: # map with mask @@ -340,7 +340,7 @@ def f(block, bmask): method = getattr(g, method_name) return method(**kwargs) m = self.mask[:, :, np.newaxis] - out = da.map_blocks(f, self.values, m, drop_axis=drop_axis, dtype=dtype) + out = da.map_blocks(f, self.values, m, chunks=chunks, drop_axis=drop_axis, new_axis=new_axis, dtype=dtype) return out @@ -439,8 +439,9 @@ def to_allele_counts(self, max_allele=None): if max_allele is None: max_allele = self.max().compute()[()] - chunks = (self.chunks[0], self.chunks[1], (max_allele + 1,)) - out = self._method('to_allele_counts', chunks=chunks, max_allele=max_allele) + chunks = (self.chunks[0], self.chunks[1], (max_allele + 1, )) + + out = self._method('to_allele_counts', chunks=chunks, max_allele=max_allele, drop_axis=2, new_axis=2) out = GenotypeAlleleCountsDaskArray(out) return out From 9a33d47710c768d8f045f73a1fc0255e10077375 Mon Sep 17 00:00:00 2001 From: Alistair Miles Date: Fri, 31 May 2019 12:02:33 +0100 Subject: [PATCH 2/4] fix long lines --- allel/model/dask.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/allel/model/dask.py b/allel/model/dask.py index 4783b734..9ae9fa8b 100644 --- a/allel/model/dask.py +++ b/allel/model/dask.py @@ -318,7 +318,8 @@ def __getitem__(self, item): return index_genotype_array(self, item, array_cls=type(self), vector_cls=GenotypeDaskVector) - def _method(self, method_name, chunks=None, drop_axis=None, new_axis=None, dtype=None, **kwargs): + def _method(self, method_name, chunks=None, drop_axis=None, new_axis=None, dtype=None, + **kwargs): if chunks is None: # no shape change chunks = self.chunks @@ -330,7 +331,8 @@ def f(block): g = array_cls(block) method = getattr(g, method_name) return method(**kwargs) - out = da.map_blocks(f, self.values, chunks=chunks, drop_axis=drop_axis, new_axis=new_axis, dtype=dtype) + out = da.map_blocks(f, self.values, chunks=chunks, drop_axis=drop_axis, + new_axis=new_axis, dtype=dtype) else: # map with mask @@ -340,7 +342,8 @@ def f(block, bmask): method = getattr(g, method_name) return method(**kwargs) m = self.mask[:, :, np.newaxis] - out = da.map_blocks(f, self.values, m, chunks=chunks, drop_axis=drop_axis, new_axis=new_axis, dtype=dtype) + out = da.map_blocks(f, self.values, m, chunks=chunks, drop_axis=drop_axis, + new_axis=new_axis, dtype=dtype) return out @@ -441,7 +444,8 @@ def to_allele_counts(self, max_allele=None): chunks = (self.chunks[0], self.chunks[1], (max_allele + 1, )) - out = self._method('to_allele_counts', chunks=chunks, max_allele=max_allele, drop_axis=2, new_axis=2) + out = self._method('to_allele_counts', chunks=chunks, max_allele=max_allele, + drop_axis=2, new_axis=2) out = GenotypeAlleleCountsDaskArray(out) return out From 4744b34188955fab0e2c8a3cee169c9d9fbb0f93 Mon Sep 17 00:00:00 2001 From: Alistair Miles Date: Fri, 31 May 2019 12:05:57 +0100 Subject: [PATCH 3/4] add #266 release note --- docs/release.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docs/release.rst b/docs/release.rst index d5063d98..27248f6e 100644 --- a/docs/release.rst +++ b/docs/release.rst @@ -1,6 +1,16 @@ Release notes ============= +.. _release_1.2.1: + +v1.2.1 +------ + +* Fixed a bug in :func:`allel.GenotypeDaskArray.to_allele_counts` + where the shape of the output array was not being determined correctly. + By :user:`Nick Harding `, :issue:`266`. + + .. _release_1.2.0: v1.2.0 From b7da01584d1707cd02a9af444db4a48c17c3dc23 Mon Sep 17 00:00:00 2001 From: Alistair Miles Date: Fri, 31 May 2019 16:37:01 +0100 Subject: [PATCH 4/4] remove trailing whitespace --- allel/model/dask.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/allel/model/dask.py b/allel/model/dask.py index 9ae9fa8b..11462005 100644 --- a/allel/model/dask.py +++ b/allel/model/dask.py @@ -318,7 +318,7 @@ def __getitem__(self, item): return index_genotype_array(self, item, array_cls=type(self), vector_cls=GenotypeDaskVector) - def _method(self, method_name, chunks=None, drop_axis=None, new_axis=None, dtype=None, + def _method(self, method_name, chunks=None, drop_axis=None, new_axis=None, dtype=None, **kwargs): if chunks is None: # no shape change @@ -331,7 +331,7 @@ def f(block): g = array_cls(block) method = getattr(g, method_name) return method(**kwargs) - out = da.map_blocks(f, self.values, chunks=chunks, drop_axis=drop_axis, + out = da.map_blocks(f, self.values, chunks=chunks, drop_axis=drop_axis, new_axis=new_axis, dtype=dtype) else: @@ -342,7 +342,7 @@ def f(block, bmask): method = getattr(g, method_name) return method(**kwargs) m = self.mask[:, :, np.newaxis] - out = da.map_blocks(f, self.values, m, chunks=chunks, drop_axis=drop_axis, + out = da.map_blocks(f, self.values, m, chunks=chunks, drop_axis=drop_axis, new_axis=new_axis, dtype=dtype) return out @@ -444,7 +444,7 @@ def to_allele_counts(self, max_allele=None): chunks = (self.chunks[0], self.chunks[1], (max_allele + 1, )) - out = self._method('to_allele_counts', chunks=chunks, max_allele=max_allele, + out = self._method('to_allele_counts', chunks=chunks, max_allele=max_allele, drop_axis=2, new_axis=2) out = GenotypeAlleleCountsDaskArray(out) return out