Skip to content
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

FutureWarning for the 1.11 to begin the process of switching leiden backend #2935

Closed
ilan-gold opened this issue Mar 21, 2024 · 1 comment · Fixed by #2951
Closed

FutureWarning for the 1.11 to begin the process of switching leiden backend #2935

ilan-gold opened this issue Mar 21, 2024 · 1 comment · Fixed by #2951
Assignees
Labels
Area – API API design
Milestone

Comments

@ilan-gold
Copy link
Contributor

See: #2865

@ilan-gold ilan-gold self-assigned this Mar 21, 2024
@ilan-gold ilan-gold added the Area – API API design label Mar 21, 2024
@ilan-gold ilan-gold added this to the 1.11.0 milestone Mar 21, 2024
@ivirshup
Copy link
Member

I think we sorta already did this:

sc.tl.leiden(adata)
/mnt/workspace/repos/scanpy/scanpy/tools/_leiden.py:144: FutureWarning: Use of leidenalg is discouraged and will be deprecated in the future.  Please use `flavor="igraph"` `n_iterations=2` to achieve similar results.  `directed` must also be `False` to work with `igraph`'s implementation.
  warnings.warn(msg, FutureWarning)

However, I do think the warning could be reworked

  • Stack level should be set so the right line is shown
  • Message should be more like:

FutureWarning: In the future, the default backend for leiden will be igraph instead of leidenalg. To achieve the future defaults please pass: flavor="igraph" and n_iterations=2. directed must also be False to work with igraph's implementation.

Note that results will be slightly different with the changed backend.

  • We should only warn once, instead of every time leiden is called. Here's a util we defined in anndata for this (I think stolen from pandas?)
def warn_once(msg: str, category: type[Warning], stacklevel: int = 1):
    warnings.warn(msg, category, stacklevel=stacklevel)
    # Prevent from showing up every time an awkward array is used
    # You'd think `'once'` works, but it doesn't at the repl and in notebooks
    warnings.filterwarnings("ignore", category=category, message=re.escape(msg))

@ivirshup ivirshup modified the milestones: 1.11.0, 1.10.0 Mar 25, 2024
@ilan-gold ilan-gold assigned ivirshup and unassigned ilan-gold Mar 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area – API API design
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants