Skip to content

Commit

Permalink
few fixes for find_mat_version:
Browse files Browse the repository at this point in the history
1. Use default `dataset`
2. Deal with cases where none of the IDs are materialized
3. Use custom MaterializationMatchError error
  • Loading branch information
schlegelp committed Mar 18, 2024
1 parent 65826aa commit 432802b
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions fafbseg/flywire/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,11 +607,12 @@ def get_lr_position(x, coordinates='nm'):
return (m[:, 0] - x[:, 0]) / 2


@inject_dataset()
def find_mat_version(ids,
verbose=True,
allow_multiple=False,
raise_missing=True,
dataset='production'):
dataset=None):
"""Find a materialization version (or live) for given IDs.
Parameters
Expand Down Expand Up @@ -682,13 +683,13 @@ def find_mat_version(ids,
print('Using live materialization')
return 'live'

if allow_multiple:
if allow_multiple and any(latest_valid != 0):
if all(latest_valid != 0):
if verbose and not SILENCE_FIND_MAT_VERSION:
print(f"Found root IDs spread across {len(np.unique(latest_valid))} "
"materialization versions.")
return latest_valid

msg = (f"Found root IDs spread across {len(np.unique(latest_valid)) - 1} "
f"materialization versions but {(latest_valid == 0).sum()} IDs "
"do not exist in any of the materialized tables.")
Expand All @@ -698,16 +699,18 @@ def find_mat_version(ids,
print(msg)
return latest_valid
else:
raise ValueError(msg)
raise MaterializationMatchError(msg)

if dataset not in ('public, '):
raise ValueError('Given root IDs do not (co-)exist in any of the available '
'materialization versions (including live). Try updating '
'root IDs and rerun your query.')
raise MaterializationMatchError(
'Given root IDs do not (co-)exist in any of the available '
'materialization versions (including live). Try updating '
'root IDs and rerun your query.')
else:
raise ValueError('Given root IDs do not (co-)exist in any of the available '
'public materialization versions. Please make sure that '
'the root IDs do exist and rerun your query.')
raise MaterializationMatchError(
'Given root IDs do not (co-)exist in any of the available '
'public materialization versions. Please make sure that '
'the root IDs do exist and rerun your query.')


def _is_valid_version(ids, version, dataset):
Expand Down Expand Up @@ -751,3 +754,7 @@ def __enter__(self):
def __exit__(self, exc_type, exc_value, exc_tb):
global SILENCE_FIND_MAT_VERSION
SILENCE_FIND_MAT_VERSION = False


class MaterializationMatchError(Exception):
pass

0 comments on commit 432802b

Please sign in to comment.