-
Notifications
You must be signed in to change notification settings - Fork 177
Fix/replace asserts with runtime validation #1260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
eaf3122
c2c4f73
93c4acd
df84a65
586f49f
57df6e3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -403,8 +403,17 @@ def _moving_h1x(ha, hb, size, start=0, stop=None, step=None): | |
| H1X values (sum of squares of joint haplotype frequencies). | ||
| """ | ||
|
|
||
| assert ha.ndim == hb.ndim == 2 | ||
| assert ha.shape[0] == hb.shape[0] | ||
| if ha.ndim != 2 or hb.ndim != 2: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an private function, so the user has no idea what ha and hb are in this context. |
||
| raise ValueError( | ||
| "Expected both haplotype arrays to be 2-dimensional " | ||
| "(n_variants, n_haplotypes), " | ||
| f"got ndim=({ha.ndim}, {hb.ndim})" | ||
| ) | ||
| if ha.shape[0] != hb.shape[0]: | ||
| raise ValueError( | ||
| "Expected both haplotype arrays to have the same number of variants " | ||
| f"(axis 0), got ({ha.shape[0]}, {hb.shape[0]})" | ||
| ) | ||
|
|
||
| # Construct moving windows. | ||
| windows = allel.index_windows(ha, size, start, stop, step) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -594,8 +594,16 @@ def _aim_analysis(self): | |
| def _parse_aim_metadata( | ||
| self, sample_set: str, data: Union[bytes, Exception] | ||
| ) -> pd.DataFrame: | ||
| assert self._aim_metadata_columns is not None | ||
| assert self._aim_metadata_dtype is not None | ||
| if self._aim_metadata_columns is None: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would assume that it is another case where the absence of AIMs should be caught earlier so, if the code gets to this, the user probably should raise an issue. |
||
| raise RuntimeError( | ||
| "Internal error: AIM metadata columns are not configured. " | ||
| "This should not happen; please open a GitHub issue." | ||
| ) | ||
| if self._aim_metadata_dtype is None: | ||
| raise RuntimeError( | ||
| "Internal error: AIM metadata dtypes are not configured. " | ||
| "This should not happen; please open a GitHub issue." | ||
| ) | ||
| if isinstance(data, bytes): | ||
| # Parse CSV data but don't apply the dtype yet. | ||
| df = pd.read_csv(io.BytesIO(data), na_values="") | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not really actionable (but it should never happen). Maybe asking the user to raise an issue on GitHub would be sensible.