Skip to content

Commit

Permalink
Merge pull request #103 from lilab-bcb/boli
Browse files Browse the repository at this point in the history
Added function to remove quotes for read_csv function
  • Loading branch information
yihming committed Mar 2, 2023
2 parents 391c685 + a4d329c commit 8ba993a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 6 additions & 2 deletions ext_modules/io_funcs.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -147,28 +147,32 @@ cpdef tuple read_csv(char* csv_file, char* delimiters):

if strchr(delimiters, line[0]) != NULL:
row_key = ""
N = 1
colnames.append(pch)
colnames[N] = colnames[N].strip("\"'")
N = 1
else:
row_key = pch
row_key = row_key.strip("\"'")

pch = strtok(NULL, delimiters)
while pch != NULL:
colnames.append(pch)
colnames[N] = colnames[N].strip("\"'")
N += 1
pch = strtok(NULL, delimiters)

if N == 0:
raise ValueError(f"File {csv_file} contains no columns!")

colnames[N - 1] = colnames[N - 1].rstrip("\n\r")
colnames[N - 1] = colnames[N - 1].rstrip("\n\r").strip("\"'")

while getline(&line, &size, fi) >=0:
if line[0] < 32 or line[0] == 127:
continue
pch = strtok(line, delimiters)
assert pch != NULL
rownames.append(pch)
rownames[M] = rownames[M].strip("\"'")
for i in range(N):
pch = strtok(NULL, delimiters)
assert pch != NULL
Expand Down
2 changes: 2 additions & 0 deletions pegasusio/text_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,8 @@ def write_mtx_file(data: MultimodalData, output_directory: str, precision: int =
logger.info("Mtx files are written.")


def _strip_quotes(rowkey: str, rownames: List[str], colnames: List[str]) -> Tuple[str, List[str], List[str]]:
return rowkey.strip("\"'"), list(map(lambda x: x.strip("\"'"), rownames)), list(map(lambda x: x.strip("\"'"), colnames))

def load_csv_file(
input_csv: str,
Expand Down

0 comments on commit 8ba993a

Please sign in to comment.