Skip to content

Commit 818fb75

Browse files
committed
Improved deprecation warnings
1 parent 15174b4 commit 818fb75

File tree

8 files changed

+41
-67
lines changed

8 files changed

+41
-67
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ from sklearn.datasets import make_circles
7676
from sklearn.decomposition import PCA
7777
from sklearn.cluster import DBSCAN
7878

79-
from tdamapper.core import MapperAlgorithm
79+
from tdamapper.learn import MapperAlgorithm
8080
from tdamapper.cover import CubicalCover
8181
from tdamapper.plot import MapperPlot
8282

docs/source/notebooks/circles_online.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"from sklearn.decomposition import PCA\n",
4343
"from sklearn.cluster import DBSCAN\n",
4444
"\n",
45-
"from tdamapper.core import MapperAlgorithm\n",
45+
"from tdamapper.learn import MapperAlgorithm\n",
4646
"from tdamapper.cover import CubicalCover\n",
4747
"from tdamapper.plot import MapperPlot\n",
4848
"\n",

docs/source/notebooks/digits_online.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
},
1111
{
1212
"cell_type": "code",
13-
"execution_count": 1,
13+
"execution_count": 5,
1414
"id": "8cf55ffb",
1515
"metadata": {},
1616
"outputs": [],
@@ -21,7 +21,7 @@
2121
"from sklearn.cluster import AgglomerativeClustering\n",
2222
"from sklearn.decomposition import PCA\n",
2323
"\n",
24-
"from tdamapper.core import MapperAlgorithm\n",
24+
"from tdamapper.learn import MapperAlgorithm\n",
2525
"from tdamapper.cover import CubicalCover\n",
2626
"from tdamapper.clustering import FailSafeClustering\n",
2727
"from tdamapper.plot import MapperPlot\n",
@@ -41,7 +41,7 @@
4141
},
4242
{
4343
"cell_type": "code",
44-
"execution_count": 2,
44+
"execution_count": 6,
4545
"id": "02d341cc",
4646
"metadata": {},
4747
"outputs": [],
@@ -68,7 +68,7 @@
6868
},
6969
{
7070
"cell_type": "code",
71-
"execution_count": 3,
71+
"execution_count": 7,
7272
"id": "a20d99cf",
7373
"metadata": {},
7474
"outputs": [
@@ -163,7 +163,7 @@
163163
},
164164
{
165165
"cell_type": "code",
166-
"execution_count": 4,
166+
"execution_count": 8,
167167
"id": "ee374256",
168168
"metadata": {},
169169
"outputs": [

src/tdamapper/_common.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,20 @@
66
import numpy as np
77

88

9-
def warn_deprecated(deprecated, substitute):
10-
msg = f'{deprecated} is deprecated and will be removed in a future version. Use {substitute} instead.'
11-
warnings.warn(
12-
msg,
13-
DeprecationWarning,
14-
stacklevel=2
15-
)
9+
warnings.filterwarnings(
10+
'default',
11+
category=DeprecationWarning,
12+
module=r'^tdamapper\.'
13+
)
14+
15+
16+
def deprecated(msg):
17+
def deprecated_func(func):
18+
def wrapper(*args, **kwargs):
19+
warnings.warn(msg, DeprecationWarning, stacklevel=2)
20+
return func(*args, **kwargs)
21+
return wrapper
22+
return deprecated_func
1623

1724

1825
def warn_user(msg):

src/tdamapper/clustering.py

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
ParamsMixin,
99
EstimatorMixin,
1010
clone,
11-
warn_deprecated,
11+
deprecated,
1212
)
1313

1414

@@ -17,25 +17,21 @@ class TrivialClustering(tdamapper.core.TrivialClustering):
1717
**DEPRECATED**: This class is deprecated and will be removed in a future
1818
release. Use :class:`tdamapper.core.TrivialClustering`.
1919
"""
20-
def __init__(self):
21-
warn_deprecated(
22-
TrivialClustering.__qualname__,
23-
tdamapper.core.TrivialClustering.__qualname__,
24-
)
25-
super().__init__()
20+
21+
@deprecated('This class is deprecated and will be removed in a future release. Use tdamapper.core.TrivialClustering.')
22+
def __init__(self, *args, **kwargs):
23+
super().__init__(*args, **kwargs)
2624

2725

2826
class FailSafeClustering(tdamapper.core.FailSafeClustering):
2927
"""
3028
**DEPRECATED**: This class is deprecated and will be removed in a future
3129
release. Use :class:`tdamapper.core.FailSafeClustering`.
3230
"""
33-
def __init__(self, clustering=None, verbose=True):
34-
warn_deprecated(
35-
FailSafeClustering.__qualname__,
36-
tdamapper.core.FailSafeClustering.__qualname__,
37-
)
38-
super().__init__(clustering, verbose)
31+
32+
@deprecated('This class is deprecated and will be removed in a future release. Use tdamapper.core.FailSafeClustering.')
33+
def __init__(self, *args, **kwargs):
34+
super().__init__(*args, **kwargs)
3935

4036

4137
class _MapperClustering(EstimatorMixin, ParamsMixin):
@@ -73,13 +69,6 @@ class MapperClustering(_MapperClustering):
7369
release. Use :class:`tdamapper.learn.MapperClustering`.
7470
"""
7571

76-
def __init__(self, cover=None, clustering=None, n_jobs=1):
77-
warn_deprecated(
78-
MapperClustering.__qualname__,
79-
'tdamapper.learn.MapperClustering',
80-
)
81-
super().__init__(
82-
cover=cover,
83-
clustering=clustering,
84-
n_jobs=n_jobs,
85-
)
72+
@deprecated('This class is deprecated and will be removed in a future release. Use tdamapper.learn.MapperClustering.')
73+
def __init__(self, *args, **kwargs):
74+
super().__init__(*args, **kwargs)

src/tdamapper/core.py

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
from tdamapper.utils.unionfind import UnionFind
3636
from tdamapper._common import (
3737
clone,
38-
warn_deprecated,
38+
deprecated,
3939
ParamsMixin,
4040
EstimatorMixin,
4141
)
@@ -424,25 +424,9 @@ class MapperAlgorithm(_MapperAlgorithm):
424424
release. Use :class:`tdamapper.learn.MapperAlgorithm`.
425425
"""
426426

427-
def __init__(
428-
self,
429-
cover=None,
430-
clustering=None,
431-
failsafe=True,
432-
verbose=True,
433-
n_jobs=1,
434-
):
435-
warn_deprecated(
436-
MapperAlgorithm.__qualname__,
437-
'tdamapper.learn.MapperAlgorithm',
438-
)
439-
super().__init__(
440-
cover=cover,
441-
clustering=clustering,
442-
failsafe=failsafe,
443-
verbose=verbose,
444-
n_jobs=n_jobs,
445-
)
427+
@deprecated('This class is deprecated and will be removed in a future release. Use tdamapper.learn.MapperAlgorithm.')
428+
def __init__(self, *args, **kwargs):
429+
super().__init__(*args, **kwargs)
446430

447431

448432
class FailSafeClustering(ParamsMixin):

src/tdamapper/plot.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from tdamapper._plot_plotly import plot_plotly, plot_plotly_update
1010
from tdamapper._plot_pyvis import plot_pyvis
1111

12-
from tdamapper._common import warn_deprecated
12+
from tdamapper._common import deprecated
1313

1414

1515
class MapperPlot:
@@ -289,6 +289,7 @@ class MapperLayoutInteractive:
289289
:type cmap: str, optional
290290
"""
291291

292+
@deprecated('This class is deprecated and will be removed in a future release. Use tdamapper.plot.MapperPlot.')
292293
def __init__(
293294
self,
294295
graph,
@@ -302,10 +303,6 @@ def __init__(
302303
height=512,
303304
cmap='jet',
304305
):
305-
warn_deprecated(
306-
MapperLayoutInteractive.__qualname__,
307-
MapperPlot.__qualname__,
308-
)
309306
self.__graph = graph
310307
self.__dim = dim
311308
self.__iterations = iterations
@@ -450,6 +447,7 @@ class MapperLayoutStatic:
450447
:type cmap: str, optional
451448
"""
452449

450+
@deprecated('This class is deprecated and will be removed in a future release. Use tdamapper.plot.MapperPlot.')
453451
def __init__(
454452
self,
455453
graph,
@@ -463,10 +461,6 @@ def __init__(
463461
height=512,
464462
cmap='jet',
465463
):
466-
warn_deprecated(
467-
MapperLayoutStatic.__qualname__,
468-
MapperPlot.__qualname__,
469-
)
470464
self.__colors = colors
471465
self.__agg = agg
472466
self.__title = title

tests/example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from sklearn.decomposition import PCA
55
from sklearn.cluster import DBSCAN
66

7-
from tdamapper.core import MapperAlgorithm
7+
from tdamapper.learn import MapperAlgorithm
88
from tdamapper.cover import CubicalCover
99
from tdamapper.plot import MapperPlot
1010

0 commit comments

Comments
 (0)