From 759bc446f6939b6915bca990deb941e75ca69c45 Mon Sep 17 00:00:00 2001 From: Gregor Sturm Date: Tue, 9 Jan 2024 20:33:41 +0000 Subject: [PATCH] Fix incompatibility with adjustText 1.0 (#477) * Fix incompatibility with adjustText 1.0 * Update CHANGELOG * Adjusttext compatibility with both new and old versions * get version using importlib metadata --- CHANGELOG.md | 6 +++++- src/scirpy/pl/_clonotype_modularity.py | 12 +++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1cae1f4ab..12ee44099 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,11 @@ and this project adheres to [Semantic Versioning][]. ## Unreleased -## New features +### Fixes + +- Fix incompatibility with `adjustText` 1.0 ([#477](https://github.com/scverse/scirpy/pull/477)) + +### New features - Speed up alignment distances by pre-filtering. There are two filtering strategies: A (lossless) length-based filter and a heuristic based on the expected penalty per mismatch. This is implemented in the `FastAlignmentDistanceCalculator` diff --git a/src/scirpy/pl/_clonotype_modularity.py b/src/scirpy/pl/_clonotype_modularity.py index 023b850bb..0caf60948 100644 --- a/src/scirpy/pl/_clonotype_modularity.py +++ b/src/scirpy/pl/_clonotype_modularity.py @@ -1,9 +1,11 @@ from collections.abc import Sequence +from importlib.metadata import version from typing import Optional, Union import numpy as np from adjustText import adjust_text from matplotlib import patheffects +from packaging.version import Version from scirpy.util import DataHandler @@ -186,13 +188,21 @@ def clonotype_modularity( ) if label_adjusttext: + kwargs = {} + # incompatible API between <1.0 and >=1.0. I'd like to pin 1.0, but it's not available from + # conda-forge and there are some issue (https://github.com/Phlya/adjustText/issues/166) + if Version(version("adjustText")) >= Version("1.0"): + kwargs["force_static"] = (0.4, 0.4) + else: + kwargs["force_points"] = (0.4, 0.4) + adjust_text( label_objs, score_df["xs"].values, score_df["ys"].values, arrowprops={"arrowstyle": "-", "color": "k", "lw": 0.5}, force_text=(0.3, 0.3), - force_points=(0.4, 0.4), + **kwargs, ) return ax