Skip to content

Commit 20e02cf

Browse files
NEW: Documentation on RachisWarning (#161)
Co-authored-by: Colin Wood <woodcolin38@gmail.com>
1 parent c050d80 commit 20e02cf

3 files changed

Lines changed: 35 additions & 1 deletion

File tree

‎book/_toc.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ parts:
4545
- file: plugins/how-to-guides/usage-examples
4646
- file: plugins/how-to-guides/format-validation-levels
4747
- file: plugins/how-to-guides/handle-exceptions-in-parallel-pipelines
48+
- file: plugins/how-to-guides/raise-visible-warning
4849
- file: plugins/explanations/intro
4950
sections:
5051
- file: plugins/explanations/actions

‎book/plugins/how-to-guides/create-register-transformer.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Transformers are often short Python functions that convert one file format or data type to another file format or data type.
55
These functions are never directly called by users or developers, so by convention they don't get informative function names (as the annotations of the input and output provide complete detail on what they do).
66

7-
Here's are two example `transformer` that are [defined and registered in `q2-types`](https://github.com/qiime2/q2-types/blob/e25f9355958755343977e037bbe39110cfb56a63/q2_types/distance_matrix/_transformer.py#L16):
7+
Here are two example `transformer` that are [defined and registered in `q2-types`](https://github.com/qiime2/q2-types/blob/e25f9355958755343977e037bbe39110cfb56a63/q2_types/distance_matrix/_transformer.py#L16):
88

99
```python
1010
import skbio
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
(howto-raise-visible-warning)=
2+
3+
# Use the RachisWarning Class: An Always-Visible Warning
4+
5+
Warnings issued by the Python `warning` library are suppressed by defualt when using the command line interface (CLI).
6+
In order to make sure the warnings issued by your plugin are visible in the CLI you must use the `RachisWarning` class.
7+
This class can be imported from the QIIME2 framework, specifically from `qiime2.core.exceptions`.
8+
Below is an [excerpt](https://github.com/qiime2/q2-feature-table/blob/b6a312e612338db0f69c97641372e7f0005b43f5/q2_feature_table/_merge.py#L90C12-L93C14) from the `q2-feature-table` plugin that may issue such a warning.
9+
10+
```python
11+
from qiime2.core.excpetions import RachisWarnings
12+
13+
def merge_taxa(data: pd.DataFrame) -> pd.DataFrame:
14+
if len(data) > 1:
15+
depths = []
16+
for taxonomy in data:
17+
max = 0
18+
for _, row in taxonomy.iterrows():
19+
depth = row['Taxon'].count(';')
20+
if depth > max:
21+
max = depth
22+
23+
depths.append(max)
24+
25+
if len(set(depths)) != 1:
26+
warnings.warn(
27+
"You are merging taxonomies with different depths.",
28+
RachisWarning
29+
)
30+
```
31+
32+
This action issues a `RachisWarning` when the taxonomies have different depths.
33+
Since the `RachisWarning` class is an empty subclass of `UserWarning` from the Python `warnings` [library](https://docs.python.org/3/library/warnings.html), the only difference in behavior is command line visibility.

0 commit comments

Comments
 (0)