Skip to content

Commit

Permalink
refactor: mark deprecated with PEP702
Browse files Browse the repository at this point in the history
  • Loading branch information
yzx9 committed Apr 7, 2024
1 parent 30c8302 commit 9d5347d
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 88 deletions.
30 changes: 6 additions & 24 deletions swcgeom/analysis/sholl.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import seaborn as sns
from matplotlib.axes import Axes
from matplotlib.figure import Figure
from typing_extensions import deprecated

from swcgeom.analysis.visualization import draw
from swcgeom.core import Tree
Expand Down Expand Up @@ -160,61 +161,42 @@ def _get_rs(self, steps: int | npt.ArrayLike) -> npt.NDArray[np.float32]:

return self.get_rs(self.rmax, steps)

@deprecated("Use `Sholl.get(x)` instead")
def get_count(self) -> npt.NDArray[np.int32]:
"""Get the count of intersection.
.. deprecated:: 0.5.0
Use :meth:`Sholl.get` instead.
Use :meth:`Sholl(x).get()` instead.
"""

warnings.warn(
"`Sholl.get_count` has been renamed to `get` since v0.5.0, "
"and will be removed in next version",
DeprecationWarning,
)
return self.get().astype(np.int32)

@deprecated("Use `Shool(x).get().mean()` instead")
def avg(self) -> float:
"""Get the average of the count of intersection.
.. deprecated:: 0.6.0
Use :meth:`Shool(x).get().mean()` instead.
"""

warnings.warn(
"`Sholl.avg` has been deprecated since v0.6.0 and will be "
"removed in next version, use `Shool(x).get().mean()` "
"instead",
DeprecationWarning,
)
return self.get().mean()

@deprecated("Use `Shool(x).get().std()` instead")
def std(self) -> float:
"""Get the std of the count of intersection.
.. deprecated:: 0.6.0
Use :meth:`Shool(x).get().std()` instead.
"""

warnings.warn(
"`Sholl.std` has been deprecate since v0.6.0 and will be "
"removed in next version, use `Shool(x).get().std()` "
"instead",
DeprecationWarning,
)
return self.get().std()

@deprecated("Use `Shool(x).get().sum()` instead")
def sum(self) -> int:
"""Get the sum of the count of intersection.
.. deprecated:: 0.6.0
Use :meth:`Shool(x).get().sum()` instead.
"""

warnings.warn(
"`Sholl.sum` has been deprecate since v0.6.0 and will be "
"removed in next version, use `Shool(x).get().sum()` "
"instead",
DeprecationWarning,
)
return self.get().sum()
8 changes: 2 additions & 6 deletions swcgeom/core/path.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""Nueron path."""

import warnings
from collections.abc import Iterable, Iterator
from typing import Generic, overload

import numpy as np
import numpy.typing as npt
from typing_extensions import deprecated

from swcgeom.core.node import Node
from swcgeom.core.swc import DictSWC, SWCLike, SWCTypeVar
Expand Down Expand Up @@ -75,18 +75,14 @@ def keys(self) -> Iterable[str]:
def get_ndata(self, key: str) -> npt.NDArray:
return self.attach.get_ndata(key)[self.idx]

@deprecated("Use `path.node` instead.")
def get_node(self, idx: int | np.integer) -> Node:
"""Get the count of intersection.
.. deprecated:: 0.16.0
Use :meth:`path.node` instead.
"""

warnings.warn(
"`Path.get_node` has been deprecated since v0.16.0 and "
"will be removed in future version",
DeprecationWarning,
)
return self.node(idx)

def node(self, idx: int | np.integer) -> Node:
Expand Down
14 changes: 3 additions & 11 deletions swcgeom/core/swc_utils/checker.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""Check common """

import warnings
from collections import defaultdict
from typing import Optional

import numpy as np
import pandas as pd
from typing_extensions import deprecated

from swcgeom.core.swc_utils.base import SWCNames, Topology, get_dsu, get_names, traverse
from swcgeom.utils import DisjointSetUnion
Expand Down Expand Up @@ -81,21 +81,18 @@ def has_cyclic(topology: Topology) -> bool:
return False


@deprecated("Use `is_single_root` instead")
def check_single_root(*args, **kwargs) -> bool:
"""Check if the tree is single root.
.. deprecated:: 0.5.0
Use :meth:`is_single_root` instead.
"""

warnings.warn(
"`check_single_root` has been renamed to `is_single_root` since"
"v0.5.0, and will be removed in next version",
DeprecationWarning,
)
return is_single_root(*args, **kwargs)


@deprecated("Use `is_bifurcate` instead")
def is_binary_tree(
df: pd.DataFrame, exclude_root: bool = True, *, names: Optional[SWCNames] = None
) -> bool:
Expand All @@ -105,11 +102,6 @@ def is_binary_tree(
Use :meth:`is_bifurcate` instead.
"""

warnings.warn(
"`is_binary_tree` has been replaced by to `is_bifurcate` since"
"v0.8.0, and will be removed in next version",
DeprecationWarning,
)
names = get_names(names)
topo = (df[names.id].to_numpy(), df[names.pid].to_numpy())
return is_bifurcate(topo, exclude_root=exclude_root)
9 changes: 2 additions & 7 deletions swcgeom/core/tree_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import Optional, TypeVar, overload

import numpy as np
from typing_extensions import deprecated

from swcgeom.core.swc import SWCLike
from swcgeom.core.swc_utils import (
Expand Down Expand Up @@ -95,6 +96,7 @@ def _leave(n: Tree.Node, children: list[K]) -> K:
return to_subtree(tree, removals)


@deprecated("Use `to_subtree` instead")
def to_sub_tree(swc_like: SWCLike, sub: Topology) -> tuple[Tree, dict[int, int]]:
"""Create subtree from origin tree.
Expand All @@ -111,13 +113,6 @@ def to_sub_tree(swc_like: SWCLike, sub: Topology) -> tuple[Tree, dict[int, int]]
id_map : dict[int, int]
"""

warnings.warn(
"`to_sub_tree` will be removed in v0.6.0, it is replaced by "
"`to_subtree` beacuse it is easy to use, and this will be "
"removed in next version",
DeprecationWarning,
)

sub = propagate_removal(sub)
(new_id, new_pid), id_map_arr = to_sub_topology(sub)

Expand Down
12 changes: 2 additions & 10 deletions swcgeom/images/folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
import math
import os
import re
import warnings
from collections.abc import Callable, Iterable
from dataclasses import dataclass
from typing import Generic, Literal, Optional, TypeVar, overload

import numpy as np
import numpy.typing as npt
from tqdm import tqdm
from typing_extensions import Self
from typing_extensions import Self, deprecated

from swcgeom.images.io import ScalarType, read_imgs
from swcgeom.transforms import Identity, Transform
Expand Down Expand Up @@ -65,21 +64,14 @@ def scan(root: str, *, pattern: Optional[str] = None) -> list[str]:
return fs

@staticmethod
@deprecated("Use `~swcgeom.images.io.read_imgs(fname).get_full()` instead")
def read_imgs(fname: str) -> npt.NDArray[np.float32]:
"""Read images.
.. deprecated:: 0.16.0
Use :meth:`~swcgeom.images.io.read_imgs(fname).get_full()` instead.
"""

warnings.warn(
"`ImageStackFolderBase.read_imgs` serves as a "
"straightforward wrapper for `~swcgeom.images.io.read_imgs(fname).get_full()`. "
"However, as it is not utilized within our internal "
"processes, it is scheduled for removal in the "
"forthcoming version.",
DeprecationWarning,
)
return read_imgs(fname).get_full()


Expand Down
7 changes: 2 additions & 5 deletions swcgeom/images/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import numpy as np
import numpy.typing as npt
import tifffile
from typing_extensions import deprecated
from v3dpy.loaders import PBD, Raw

__all__ = ["read_imgs", "save_tiff", "read_images"]
Expand Down Expand Up @@ -601,16 +602,12 @@ def shape(self) -> tuple[int, int, int]:
return self.imgs.shape[:-1]


@deprecated("Use `read_imgs` instead")
def read_images(*args, **kwargs) -> GrayImageStack:
"""Read images.
.. deprecated:: 0.16.0
Use :meth:`read_imgs` instead.
"""

warnings.warn(
"`read_images` has been replaced by `read_imgs` because it"
"provide rgb support, and this will be removed in next version",
DeprecationWarning,
)
return GrayImageStack(read_imgs(*args, **kwargs))
12 changes: 2 additions & 10 deletions swcgeom/transforms/images.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
"""Image stack related transform."""

import warnings

import numpy as np
import numpy.typing as npt
from typing_extensions import deprecated

from swcgeom.transforms.base import Identity, Transform

Expand Down Expand Up @@ -45,21 +44,14 @@ def extra_repr(self) -> str:
return f"shape_out=({','.join(str(a) for a in self.shape_out)})"


@deprecated("use `ImagesCenterCrop` instead", stacklevel=2)
class Center(ImagesCenterCrop):
"""Get image stack center.
.. deprecated:: 0.16.0
Use :class:`ImagesCenterCrop` instead.
"""

def __init__(self, shape_out: int | tuple[int, int, int]):
warnings.warn(
"`Center` is deprecated, use `ImagesCenterCrop` instead",
DeprecationWarning,
stacklevel=2,
)
super().__init__(shape_out)


class ImagesScale(Transform[NDArrayf32, NDArrayf32]):
def __init__(self, scaler: float) -> None:
Expand Down
12 changes: 2 additions & 10 deletions swcgeom/transforms/tree.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""Transformation in tree."""

import warnings
from collections.abc import Callable
from typing import Optional

import numpy as np
from typing_extensions import deprecated

from swcgeom.core import BranchTree, DictSWC, Path, Tree, cut_tree, to_subtree
from swcgeom.core.swc_utils import SWCTypes, get_types
Expand Down Expand Up @@ -69,22 +69,14 @@ def extra_repr(self):
return f"n_nodes={self.n_nodes}"


@deprecated("Use `Normalizer` instead")
class TreeNormalizer(Normalizer[Tree]):
"""Noramlize coordinates and radius to 0-1.
.. deprecated:: 0.6.0
Use :cls:`Normalizer` instead.
"""

def __init__(self, *args, **kwargs) -> None:
warnings.warn(
"`TreeNormalizer` has been replaced by `Normalizer` since "
"v0.6.0 beacuse it applies more widely, and this will be "
"removed in next version",
DeprecationWarning,
)
super().__init__(*args, **kwargs)


class CutByType(Transform[Tree, Tree]):
"""Cut tree by type.
Expand Down
7 changes: 2 additions & 5 deletions swcgeom/utils/sdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import numpy as np
import numpy.typing as npt
from typing_extensions import deprecated

from swcgeom.utils.solid_geometry import project_vector_on_plane

Expand Down Expand Up @@ -173,6 +174,7 @@ def is_in(self, p: npt.NDArray[np.float32]) -> npt.NDArray[np.bool_]:
return flags


@deprecated("Use `SDFUnion` instead")
class SDFCompose(SDFUnion):
"""Compose multiple SDFs.
Expand All @@ -181,11 +183,6 @@ class SDFCompose(SDFUnion):
"""

def __init__(self, sdfs: Iterable[SDF]) -> None:
warnings.warn(
"`SDFCompose` has been replace by `SDFUnion` since v0.14.0, "
"and will be removed in next version",
DeprecationWarning,
)
sdfs = list(sdfs)
if len(sdfs) == 1:
warnings.warn("compose only one SDF, use SDFCompose.compose instead")
Expand Down

0 comments on commit 9d5347d

Please sign in to comment.