Skip to content

Commit

Permalink
try to catch memoryerror when resizing arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
aryarm authored Dec 27, 2024
1 parent 9e742d8 commit 2365c8f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions haptools/data/genotypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1599,13 +1599,13 @@ def write(self):
# https://stackoverflow.com/a/46575580
allele_cts = self._num_unique_alleles(data[start:end])
subset_data = np.ascontiguousarray(data[start:end], dtype=np.int32)
subset_data.resize((len(self.variants), len(self.samples) * 2))
missing.resize((len(self.variants), len(self.samples) * 2))
except np.core._exceptions._ArrayMemoryError as e:
raise ValueError(
"You don't have enough memory to write these genotypes! Try"
" specifying a value to the chunk_size parameter, instead"
) from e
subset_data.resize((len(self.variants), len(self.samples) * 2))
missing.resize((len(self.variants), len(self.samples) * 2))
# convert any missing genotypes to -9
subset_data[missing] = -9
# finally, append the genotypes to the PGEN file
Expand Down

0 comments on commit 2365c8f

Please sign in to comment.