Repository navigation
Documentation on RachisWarning #161
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f4da123
Adding documentation on RachisWarning and typo in creating and regist…
Macabe222 eed8bf0
Small changes
Macabe222 8e4ee0d
Small change
Macabe222 81b4ebf
Finalizing
Macabe222 a80345f
Small change
Macabe222 80f8aaa
reformatting
colinvwood fda8c54
small
colinvwood File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| (howto-raise-visible-warning)= | ||
| # Raising a Visible Warning | ||
|
|
||
| Warnings raised by the Python `warning` library are suppressed by the QIIME2 framework by defualt. In order to make sure the warnings raised by your plugin are visible on the command line you must use the `RachisWarning` subclass. This class can be imported from the QIIME2 framework, specifically from `qiime2.core.exceptions`. Below is an excerpt from a [QIIME2 plugin registered in `q2-feature-table` importing and raising a `RachisWarning`.](https://github.com/qiime2/q2-feature-table/blob/b6a312e612338db0f69c97641372e7f0005b43f5/q2_feature_table/_merge.py#L90C12-L93C14) | ||
|
|
||
| ```python | ||
| from qiime2.core.excpetions import RachisWarnings | ||
|
|
||
| def merge_taxa(data: pd.DataFrame) -> pd.DataFrame: | ||
| if len(data) > 1: | ||
| depths = [] | ||
| for taxonomy in data: | ||
| max = 0 | ||
| for _, row in taxonomy.iterrows(): | ||
| depth = row['Taxon'].count(';') | ||
| if depth > max: | ||
| max = depth | ||
|
|
||
| depths.append(max) | ||
| if len(set(depths)) != 1: | ||
| warnings.warn( | ||
| "You are merging taxonomies with different depths.", | ||
| RachisWarning | ||
| ) | ||
| ``` | ||
| This plugin has a `RachisWarning` raised when the taxonomies have different depths. Since the `RachisWarning` is a subclass of `UserWarning` from the | ||
| built in Python `warnings` library, on which you can find more in depth documentation [here,](https://docs.python.org/3/library/warnings.html) they behave | ||
| completely the same outside of command line visibility. | ||
|
Macabe222 marked this conversation as resolved.
Outdated
Macabe222 marked this conversation as resolved.
Outdated
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.