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

Backport PR #2750 on branch 1.9.x (Skip _wraps_plot_scatter on 3.9) #2751

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 8 additions & 25 deletions scanpy/plotting/_tools/scatterplots.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations
from collections import defaultdict

import sys
import inspect
import collections.abc as cabc
from copy import copy
Expand Down Expand Up @@ -578,31 +578,14 @@ def my_vmax(color_vector): np.percentile(color_vector, p=80)
return tuple(out)


def _get_signature(obj: Any, *, eval_str: bool) -> inspect.Signature:
"""inspect.signature wrapper with eval_str support on Python < 3.10"""
try:
from inspect import get_annotations
except ImportError:
from get_annotations import get_annotations

sig_uneval = inspect.signature(obj)
annotations = defaultdict(
lambda: inspect.Signature.empty, get_annotations(obj, eval_str=eval_str)
)

parameters = [
inspect.Parameter(
name, param.kind, default=param.default, annotation=annotations[name]
)
for name, param in sig_uneval.parameters.items()
]

return inspect.Signature(parameters, return_annotation=annotations["return"])


def _wraps_plot_scatter(wrapper):
params = _get_signature(embedding, eval_str=True).parameters.copy()
wrapper_sig = _get_signature(wrapper, eval_str=True)
"""Update the wrapper function to use the correct signature."""
if sys.version_info < (3, 10):
# Python 3.9 does not support `eval_str`, so we only support this in 3.10+
return wrapper

params = inspect.signature(embedding, eval_str=True).parameters.copy()
wrapper_sig = inspect.signature(wrapper, eval_str=True)
wrapper_params = wrapper_sig.parameters.copy()

params.pop("basis")
Expand Down
Loading