1
1
from _typeshed import Incomplete
2
2
from collections .abc import Hashable , Iterable , Mapping , Sequence
3
- from typing import Literal
3
+ from typing import Literal , TypedDict , type_check_only
4
4
from typing_extensions import Self , TypeAlias
5
5
6
6
import numpy as np
7
+ import pandas as pd
7
8
from matplotlib .axes import Axes
8
- from matplotlib .colors import Colormap , ListedColormap
9
+ from matplotlib .colors import Colormap , ListedColormap , Normalize
9
10
from matplotlib .gridspec import GridSpec
10
11
from matplotlib .typing import ColorType
11
- from numpy ._typing import _ArrayLike , _ArrayLikeInt_co
12
+ from numpy ._typing import _ArrayLikeInt_co
12
13
from numpy .typing import ArrayLike , NDArray
13
- from pandas import DataFrame , Index , Series
14
14
15
15
from .axisgrid import Grid
16
16
17
17
# pandas._typing.ListLikeU is partially Unknown
18
- _ListLikeU : TypeAlias = Sequence [Incomplete ] | np .ndarray [Incomplete , Incomplete ] | Series [Incomplete ] | Index [Incomplete ]
18
+ _ListLikeU : TypeAlias = Sequence [Incomplete ] | NDArray [Incomplete ] | pd .Series [Incomplete ] | pd .Index [Incomplete ]
19
+ _ConvertibleToDataFrame : TypeAlias = (
20
+ _ListLikeU
21
+ | pd .DataFrame
22
+ | dict [Incomplete , Incomplete ]
23
+ | Iterable [_ListLikeU | tuple [Hashable , _ListLikeU ] | dict [Incomplete , Incomplete ]]
24
+ | None
25
+ )
26
+ _FlatOrNestedSequenceOfColors : TypeAlias = (
27
+ Sequence [ColorType ]
28
+ | Sequence [Iterable [ColorType ]]
29
+ | NDArray [Incomplete ]
30
+ | pd .Index [Incomplete ]
31
+ | pd .Series [Incomplete ]
32
+ | pd .DataFrame
33
+ )
19
34
20
35
__all__ = ["heatmap" , "clustermap" ]
21
36
22
37
def heatmap (
23
- data : DataFrame | _ArrayLike [ Incomplete ] ,
38
+ data : pd . DataFrame | ArrayLike ,
24
39
* ,
25
40
vmin : float | None = None ,
26
41
vmax : float | None = None ,
@@ -38,44 +53,64 @@ def heatmap(
38
53
square : bool = False ,
39
54
xticklabels : Literal ["auto" ] | bool | int | Sequence [str ] = "auto" ,
40
55
yticklabels : Literal ["auto" ] | bool | int | Sequence [str ] = "auto" ,
41
- mask : NDArray [np .bool_ ] | DataFrame | None = None ,
56
+ mask : NDArray [np .bool_ ] | pd . DataFrame | None = None ,
42
57
ax : Axes | None = None ,
58
+ # Kwargs below passed to matplotlib.axes.Axes.pcolormesh
59
+ alpha : float | None = None ,
60
+ norm : str | Normalize | None = None ,
61
+ shading : Literal ["flat" , "nearest" , "gouraud" , "auto" ] | None = None ,
62
+ antialiased : bool = False ,
43
63
** kwargs ,
44
64
) -> Axes : ...
65
+ @type_check_only
66
+ class _Dendogram (TypedDict ):
67
+ icoord : list [list [float ]]
68
+ dcoord : list [list [float ]]
69
+ ivl : list [str ]
70
+ leaves : list [int ]
71
+ color_list : list [str ]
72
+ leaves_color_list : list [str ]
45
73
46
74
class _DendrogramPlotter :
47
75
axis : int
48
- array : NDArray [Incomplete ]
49
- data : DataFrame
76
+ array : NDArray [np . floating ]
77
+ data : pd . DataFrame
50
78
shape : tuple [int , int ]
51
79
metric : str
52
80
method : str
53
81
label : bool
54
82
rotate : bool
55
- linkage : NDArray [Incomplete ]
56
- dendrogram : dict [ str , list [ Incomplete ]]
57
- xticks : list [float ] | NDArray [Incomplete ]
58
- yticks : list [float ] | NDArray [Incomplete ]
83
+ linkage : NDArray [np . floating ]
84
+ dendrogram : _Dendogram
85
+ xticks : list [float ] | NDArray [np . floating ]
86
+ yticks : list [float ] | NDArray [np . floating ]
59
87
xticklabels : list [str ]
60
88
yticklabels : list [str ]
61
89
ylabel : str
62
90
xlabel : str
63
91
dependent_coord : list [list [float ]]
64
92
independent_coord : list [list [float ]]
65
93
def __init__ (
66
- self , data : DataFrame , linkage : NDArray [Incomplete ] | None , metric : str , method : str , axis : int , label : bool , rotate : bool
94
+ self ,
95
+ data : pd .DataFrame ,
96
+ linkage : NDArray [np .floating ] | None ,
97
+ metric : str ,
98
+ method : str ,
99
+ axis : int ,
100
+ label : bool ,
101
+ rotate : bool ,
67
102
) -> None : ...
68
103
@property
69
- def calculated_linkage (self ) -> NDArray [Incomplete ]: ...
70
- def calculate_dendrogram (self ) -> dict [ str , list [ Incomplete ]] : ...
104
+ def calculated_linkage (self ) -> NDArray [np . float64 ]: ...
105
+ def calculate_dendrogram (self ) -> _Dendogram : ...
71
106
@property
72
107
def reordered_ind (self ) -> list [int ]: ...
73
108
def plot (self , ax : Axes , tree_kws : dict [str , Incomplete ]) -> Self : ...
74
109
75
110
def dendrogram (
76
- data : DataFrame ,
111
+ data : pd . DataFrame ,
77
112
* ,
78
- linkage : NDArray [Incomplete ] | None = None ,
113
+ linkage : NDArray [np . floating ] | None = None ,
79
114
axis : int = 1 ,
80
115
label : bool = True ,
81
116
metric : str = "euclidean" ,
@@ -86,13 +121,13 @@ def dendrogram(
86
121
) -> _DendrogramPlotter : ...
87
122
88
123
class ClusterGrid (Grid ):
89
- data : DataFrame
90
- data2d : DataFrame
91
- mask : DataFrame
92
- row_colors : Incomplete
93
- row_color_labels : Incomplete
94
- col_colors : Incomplete
95
- col_color_labels : Incomplete
124
+ data : pd . DataFrame
125
+ data2d : pd . DataFrame
126
+ mask : pd . DataFrame
127
+ row_colors : list [ list [ tuple [ float , float , float ]]] | None
128
+ row_color_labels : list [ str ] | None
129
+ col_colors : list [ list [ tuple [ float , float , float ]]] | None
130
+ col_color_labels : list [ str ] | None
96
131
gs : GridSpec
97
132
ax_row_dendrogram : Axes
98
133
ax_col_dendrogram : Axes
@@ -101,53 +136,47 @@ class ClusterGrid(Grid):
101
136
ax_heatmap : Axes
102
137
ax_cbar : Axes | None
103
138
cax : Axes | None
104
- cbar_pos : Incomplete
139
+ cbar_pos : tuple [ float , float , float , float ] | None
105
140
dendrogram_row : _DendrogramPlotter | None
106
141
dendrogram_col : _DendrogramPlotter | None
107
142
def __init__ (
108
143
self ,
109
- data : (
110
- _ListLikeU
111
- | DataFrame
112
- | dict [Incomplete , Incomplete ]
113
- | Iterable [_ListLikeU | tuple [Hashable , _ListLikeU ] | dict [Incomplete , Incomplete ]]
114
- | None
115
- ),
144
+ data : _ConvertibleToDataFrame ,
116
145
pivot_kws : Mapping [str , Incomplete ] | None = None ,
117
146
z_score : int | None = None ,
118
147
standard_scale : int | None = None ,
119
148
figsize : tuple [float , float ] | None = None ,
120
- row_colors = None ,
121
- col_colors = None ,
122
- mask : NDArray [np .bool_ ] | DataFrame | None = None ,
149
+ row_colors : _FlatOrNestedSequenceOfColors | None = None ,
150
+ col_colors : _FlatOrNestedSequenceOfColors | None = None ,
151
+ mask : NDArray [np .bool_ ] | pd . DataFrame | None = None ,
123
152
dendrogram_ratio : float | tuple [float , float ] | None = None ,
124
153
colors_ratio : float | tuple [float , float ] | None = None ,
125
154
cbar_pos : tuple [float , float , float , float ] | None = None ,
126
155
) -> None : ...
127
156
def format_data (
128
157
self ,
129
- data : DataFrame ,
158
+ data : pd . DataFrame ,
130
159
pivot_kws : Mapping [str , Incomplete ] | None ,
131
160
z_score : int | None = None ,
132
161
standard_scale : int | None = None ,
133
- ) -> DataFrame : ...
162
+ ) -> pd . DataFrame : ...
134
163
@staticmethod
135
- def z_score (data2d : DataFrame , axis : int = 1 ) -> DataFrame : ...
164
+ def z_score (data2d : pd . DataFrame , axis : int = 1 ) -> pd . DataFrame : ...
136
165
@staticmethod
137
- def standard_scale (data2d : DataFrame , axis : int = 1 ) -> DataFrame : ...
138
- def dim_ratios (self , colors : Incomplete | None , dendrogram_ratio : float , colors_ratio : float ) -> list [float ]: ...
166
+ def standard_scale (data2d : pd . DataFrame , axis : int = 1 ) -> pd . DataFrame : ...
167
+ def dim_ratios (self , colors : ArrayLike | None , dendrogram_ratio : float , colors_ratio : float ) -> list [float ]: ...
139
168
@staticmethod
140
169
def color_list_to_matrix_and_cmap (
141
- colors : Sequence [ ColorType ] , ind : _ArrayLikeInt_co , axis : int = 0
170
+ colors : _FlatOrNestedSequenceOfColors , ind : _ArrayLikeInt_co , axis : int = 0
142
171
) -> tuple [NDArray [np .int_ ], ListedColormap ]: ...
143
172
def plot_dendrograms (
144
173
self ,
145
174
row_cluster : bool ,
146
175
col_cluster : bool ,
147
176
metric : str ,
148
177
method : str ,
149
- row_linkage : NDArray [Incomplete ] | None ,
150
- col_linkage : NDArray [Incomplete ] | None ,
178
+ row_linkage : NDArray [np . floating ] | None ,
179
+ col_linkage : NDArray [np . floating ] | None ,
151
180
tree_kws : dict [str , Incomplete ] | None ,
152
181
) -> None : ...
153
182
def plot_colors (self , xind : _ArrayLikeInt_co , yind : _ArrayLikeInt_co , ** kws ) -> None : ...
@@ -159,20 +188,14 @@ class ClusterGrid(Grid):
159
188
colorbar_kws : dict [str , Incomplete ] | None ,
160
189
row_cluster : bool ,
161
190
col_cluster : bool ,
162
- row_linkage : NDArray [Incomplete ] | None ,
163
- col_linkage : NDArray [Incomplete ] | None ,
191
+ row_linkage : NDArray [np . floating ] | None ,
192
+ col_linkage : NDArray [np . floating ] | None ,
164
193
tree_kws : dict [str , Incomplete ] | None ,
165
194
** kws ,
166
195
) -> Self : ...
167
196
168
197
def clustermap (
169
- data : (
170
- _ListLikeU
171
- | DataFrame
172
- | dict [Incomplete , Incomplete ]
173
- | Iterable [_ListLikeU | tuple [Hashable , _ListLikeU ] | dict [Incomplete , Incomplete ]]
174
- | None
175
- ),
198
+ data : _ConvertibleToDataFrame ,
176
199
* ,
177
200
pivot_kws : dict [str , Incomplete ] | None = None ,
178
201
method : str = "average" ,
@@ -183,11 +206,11 @@ def clustermap(
183
206
cbar_kws : dict [str , Incomplete ] | None = None ,
184
207
row_cluster : bool = True ,
185
208
col_cluster : bool = True ,
186
- row_linkage : NDArray [Incomplete ] | None = None ,
187
- col_linkage : NDArray [Incomplete ] | None = None ,
188
- row_colors = None ,
189
- col_colors = None ,
190
- mask : NDArray [np .bool_ ] | DataFrame | None = None ,
209
+ row_linkage : NDArray [np . floating ] | None = None ,
210
+ col_linkage : NDArray [np . floating ] | None = None ,
211
+ row_colors : _FlatOrNestedSequenceOfColors | None = None ,
212
+ col_colors : _FlatOrNestedSequenceOfColors | None = None ,
213
+ mask : NDArray [np .bool_ ] | pd . DataFrame | None = None ,
191
214
dendrogram_ratio : float | tuple [float , float ] = 0.2 ,
192
215
colors_ratio : float | tuple [float , float ] = 0.03 ,
193
216
cbar_pos : tuple [float , float , float , float ] | None = (0.02 , 0.8 , 0.05 , 0.18 ),
0 commit comments