Skip to content

Commit

Permalink
-> Proper condensation of values
Browse files Browse the repository at this point in the history
  • Loading branch information
s-paquette committed Dec 12, 2024
1 parent 6b7556d commit f8af15d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
25 changes: 14 additions & 11 deletions cohorts/metadata_counting.py
Original file line number Diff line number Diff line change
Expand Up @@ -947,18 +947,21 @@ def get_full_case_metadata(ids, source_type, source):
elif idx in sample_idx:
col_name = sample_idx
data_store = case['samples']
val = val.split("|") if isinstance(val, str) and re.search(r'\|', val) else val
val = val.split("|") if isinstance(val, str) and re.search(r'\|', val) else [val]
if col_name[idx] not in data_store:
data_store[col_name[idx]] = val
else:
if isinstance(data_store[col_name[idx]], list):
if isinstance(val, list):
data_store[col_name[idx]].extend(val)
else:
data_store[col_name[idx]].append(val)
data_store[col_name[idx]] = list(set(data_store[col_name[idx]]))
elif data_store[col_name[idx]] != val:
data_store[col_name[idx]] = [data_store[col_name[idx]], val]
data_store[col_name[idx]] = []
data_store[col_name[idx]].extend(val)
for case, case_data in cases.items():
for data_type, data in case_data.items():
if data_type != id_type:
for col_name, vals in data.items():
data[col_name] = list(set(vals))
if None in data[col_name]:
data[col_name].remove(None)
if len(data[col_name]) == 1:
data[col_name] = vals[0]
elif not len(data[col_name]):
data[col_name] = "N/A"

not_found = [x for x in ids if x not in cases]

Expand Down
1 change: 1 addition & 0 deletions google_helpers/bigquery/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ def build_bq_filter_and_params(filters, comb_with='AND', param_suffix=None, with
# If the values are arrays we assume the first value in the first array is indicative of all
# other values (since we don't support multi-typed fields)
type_check = values[0] if type(values[0]) is not list else values[0][0]
type_check = values[0] if type(values[0]) is not list else values[0][0]
parameter_type = (
'STRING' if (
type(type_check) not in [int, float, complex] and re.compile(r'[^0-9\.,]', re.UNICODE).search(
Expand Down

0 comments on commit f8af15d

Please sign in to comment.