You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think I found a bug in the viz.boxplots function, and also applied a solution that worked. Explaining it here in case other people ever ran into this problem.
I have a cell counts AnnData object where each row is a subject and each column are the cell counts for that subject.
For each subjects I have several categorical features such as Smoke that can assume three values and Disease that assumes two values.
I first plot
viz.boxplots(data_coda, feature_name="Disease")
This works. Then, I plot
viz.boxplots(data_coda, feature_name="Smoke")
which also works. However, if I plot the feature "Disease" again, it crashes with the following error:
Note that this behavior is not easy to reproduce since I think it depends on how many categories each feature has. Moreover, when plotting other features, I found that the legend contained the levels of the previous feature "Smoke". This means that some global variables are persisting between function calls and are leaking in subsequent calls. I think I reconstructed why this happens. In the data_visualization.py script, the function signature of the boxplots function is defined as
This function signature defines the default arguments of args_boxplot and args_swamplot as empty dicts ({}). Using mutable default values is generally not recommended in python because it causes unexpected behaviors between function calls (see here).
To avoid this behavior, I just replaced the default values with None and filled them within the function:
Thanks for spotting this!
I'll keep this fix in mind if we ever release a new version of this package. The actively maintained implementation of scCODA in the pertpy package already contains a very similar fix.
Hello,
I think I found a bug in the
viz.boxplots
function, and also applied a solution that worked. Explaining it here in case other people ever ran into this problem.I have a cell counts AnnData object where each row is a subject and each column are the cell counts for that subject.
For each subjects I have several categorical features such as
Smoke
that can assume three values andDisease
that assumes two values.I first plot
This works. Then, I plot
which also works. However, if I plot the feature "Disease" again, it crashes with the following error:
Note that this behavior is not easy to reproduce since I think it depends on how many categories each feature has. Moreover, when plotting other features, I found that the legend contained the levels of the previous feature "Smoke". This means that some global variables are persisting between function calls and are leaking in subsequent calls. I think I reconstructed why this happens. In the
data_visualization.py
script, the function signature of theboxplots
function is defined asThis function signature defines the default arguments of
args_boxplot
andargs_swamplot
as empty dicts ({}
). Using mutable default values is generally not recommended in python because it causes unexpected behaviors between function calls (see here).To avoid this behavior, I just replaced the default values with
None
and filled them within the function:and inside the function we add
Not sure if other functions use mutable default values. Thought it could be useful if other people ever ran into this problem.
The text was updated successfully, but these errors were encountered: