Skip to content

Commit

Permalink
add python 3.9 numpy 2 workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlKCarlK committed Jul 2, 2024
1 parent b973b7c commit 3a0c8e2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
version = "1.0.5-beta.1"
version = "1.0.5-beta.2"
name = "bed-reader"
description = "Read and write the PLINK BED format, simply and efficiently."
repository = "https://github.com/fastlmm/bed-reader"
Expand Down
14 changes: 14 additions & 0 deletions bed_reader/_open_bed.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import logging
import multiprocessing
import os
import re
import sys
from dataclasses import dataclass
from io import BytesIO
from itertools import repeat, takewhile
Expand Down Expand Up @@ -1792,6 +1794,8 @@ def sparsify(self, val, order, minor_index, batch_slice, data, indices, indptr):


def _read_csv(filepath, delimiter=None, dtype=None, usecols=None):
pattern = re.compile(r"^np\.\w+\((.+?)\)$")

# Prepare the usecols by ensuring it is a list of indices
usecols_indices = list(usecols)
transposed = np.loadtxt(
Expand All @@ -1809,6 +1813,16 @@ def _read_csv(filepath, delimiter=None, dtype=None, usecols=None):
columns = []
for output_index, input_index in enumerate(usecols_indices):
col = transposed[output_index]

# work around numpy/python bug
if (
(sys.version_info.major, sys.version_info.minor) <= (3, 9)
and int(np.__version__.split(".")[0]) >= 2
and len(col) > 0
and pattern.fullmatch(col[0])
):
col = np.array([pattern.fullmatch(x).group(1) for x in col])

# Find the dtype for this column
col_dtype = dtype.get(input_index, np.str_)
# Convert the column list to a numpy array with the specified dtype
Expand Down

0 comments on commit 3a0c8e2

Please sign in to comment.