Skip to content

Commit e3ae58b

Browse files
committed
typ: Remove pin on pandas-stubs
1 parent d575084 commit e3ae58b

File tree

8 files changed

+50
-26
lines changed

8 files changed

+50
-26
lines changed

plotnine/geoms/geom_rug.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
import typing
3+
from typing import TYPE_CHECKING, cast
44

55
import numpy as np
66

@@ -10,7 +10,7 @@
1010
from .geom import geom
1111
from .geom_path import geom_path
1212

13-
if typing.TYPE_CHECKING:
13+
if TYPE_CHECKING:
1414
from typing import Any
1515

1616
import pandas as pd
@@ -90,29 +90,29 @@ def draw_group(
9090
yheight = (ymax - ymin) * params["length"]
9191

9292
# Please the type checker
93-
x: FloatArray
94-
y: FloatArray
93+
x = cast("FloatArray", data["x"].to_numpy())
94+
y = cast("FloatArray", data["y"].to_numpy())
9595

9696
if has_x:
9797
if "b" in sides:
98-
x = np.repeat(data["x"].to_numpy(), 2)
98+
x = np.repeat(x, 2)
9999
y = np.tile([ymin, ymin + yheight], n)
100100
rugs.extend(make_line_segments(x, y, ispath=False))
101101

102102
if "t" in sides:
103-
x = np.repeat(data["x"].to_numpy(), 2)
103+
x = np.repeat(x, 2)
104104
y = np.tile([ymax - yheight, ymax], n)
105105
rugs.extend(make_line_segments(x, y, ispath=False))
106106

107107
if has_y:
108108
if "l" in sides:
109109
x = np.tile([xmin, xmin + xheight], n)
110-
y = np.repeat(data["y"].to_numpy(), 2)
110+
y = np.repeat(y, 2)
111111
rugs.extend(make_line_segments(x, y, ispath=False))
112112

113113
if "r" in sides:
114114
x = np.tile([xmax - xheight, xmax], n)
115-
y = np.repeat(data["y"].to_numpy(), 2)
115+
y = np.repeat(y, 2)
116116
rugs.extend(make_line_segments(x, y, ispath=False))
117117

118118
color = to_rgba(data["color"], data["alpha"])

plotnine/stats/stat_density_2d.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from typing import TYPE_CHECKING
3+
from typing import TYPE_CHECKING, cast
44

55
import numpy as np
66
import pandas as pd
@@ -92,17 +92,19 @@ def compute_group(self, data, scales):
9292
group = data["group"].iloc[0]
9393
range_x = scales.x.dimension()
9494
range_y = scales.y.dimension()
95-
x = np.linspace(range_x[0], range_x[1], params["n"])
96-
y = np.linspace(range_y[0], range_y[1], params["n"])
95+
_x = np.linspace(range_x[0], range_x[1], params["n"])
96+
_y = np.linspace(range_y[0], range_y[1], params["n"])
9797

9898
# The grid must have a "similar" shape (n, p) to the var_data
99-
X, Y = np.meshgrid(x, y)
100-
var_data = np.array([data["x"].to_numpy(), data["y"].to_numpy()]).T
99+
X, Y = np.meshgrid(_x, _y)
100+
x = cast("FloatArrayLike", data["x"].to_numpy())
101+
y = cast("FloatArrayLike", data["y"].to_numpy())
102+
var_data = np.array([x, y]).T
101103
grid = np.array([X.flatten(), Y.flatten()]).T
102104
density = kde(var_data, grid, package, **kde_params)
103105

104106
if params["contour"]:
105-
Z = density.reshape(len(x), len(y))
107+
Z = density.reshape(len(_x), len(_y))
106108
data = contour_lines(X, Y, Z, params["levels"])
107109
# Each piece should have a distinct group
108110
groups = str(group) + "-00" + data["piece"].astype(str)

plotnine/stats/stat_pointdensity.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import TYPE_CHECKING, cast
2+
13
import numpy as np
24
import pandas as pd
35

@@ -6,6 +8,9 @@
68
from .density import get_var_type, kde
79
from .stat import stat
810

11+
if TYPE_CHECKING:
12+
from plotnine.typing import FloatArray
13+
914

1015
@document
1116
class stat_pointdensity(stat):
@@ -67,8 +72,10 @@ def setup_params(self, data):
6772
def compute_group(self, data, scales):
6873
package = self.params["package"]
6974
kde_params = self.params["kde_params"]
75+
x = cast("FloatArray", data["x"].to_numpy())
76+
y = cast("FloatArray", data["y"].to_numpy())
7077

71-
var_data = np.array([data["x"].to_numpy(), data["y"].to_numpy()]).T
78+
var_data = np.array([x, y]).T
7279
density = kde(var_data, var_data, package, **kde_params)
7380

7481
data = pd.DataFrame(

plotnine/stats/stat_qq.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from typing import TYPE_CHECKING
3+
from typing import TYPE_CHECKING, cast
44

55
import numpy as np
66
import pandas as pd
@@ -76,7 +76,7 @@ class stat_qq(stat):
7676
}
7777

7878
def compute_group(self, data, scales):
79-
sample = data["sample"].sort_values().to_numpy()
79+
sample = cast("FloatArray", data["sample"].sort_values().to_numpy())
8080
theoretical = theoretical_qq(
8181
sample,
8282
self.params["distribution"],

plotnine/stats/stat_qq_line.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import TYPE_CHECKING, cast
2+
13
import numpy as np
24
import pandas as pd
35

@@ -6,6 +8,9 @@
68
from .stat import stat
79
from .stat_qq import theoretical_qq
810

11+
if TYPE_CHECKING:
12+
from plotnine.typing import FloatArray
13+
914

1015
@document
1116
class stat_qq_line(stat):
@@ -75,7 +80,7 @@ def compute_group(self, data, scales):
7580
dparams = self.params["dparams"]
7681

7782
# Compute theoretical values
78-
sample = data["sample"].sort_values().to_numpy()
83+
sample = cast("FloatArray", data["sample"].sort_values().to_numpy())
7984
theoretical = theoretical_qq(
8085
sample,
8186
self.params["distribution"],

plotnine/stats/stat_sina.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import TYPE_CHECKING, cast
2+
13
import numpy as np
24
import pandas as pd
35

@@ -9,6 +11,9 @@
911
from .stat import stat
1012
from .stat_density import compute_density
1113

14+
if TYPE_CHECKING:
15+
from plotnine.typing import FloatArray, IntArray
16+
1217

1318
@document
1419
class stat_sina(stat):
@@ -254,19 +259,18 @@ def compute_group(self, data, scales):
254259
def finish_layer(self, data):
255260
# Rescale x in case positions have been adjusted
256261
style = self.params["style"]
257-
x_mean = data["x"].to_numpy()
262+
x_mean = cast("FloatArray", data["x"].to_numpy())
258263
x_mod = (data["xmax"] - data["xmin"]) / data["width"]
259264
data["x"] = data["x"] + data["x_diff"] * x_mod
260-
x = data["x"].to_numpy()
261-
even = data["group"].to_numpy() % 2 == 0
265+
group = cast("IntArray", data["group"].to_numpy())
266+
x = cast("FloatArray", data["x"].to_numpy())
267+
even = group % 2 == 0
262268

263269
def mirror_x(bool_idx):
264270
"""
265271
Mirror x locations along the mean value
266272
"""
267-
data.loc[bool_idx, "x"] = (
268-
2 * x_mean[bool_idx] - data.loc[bool_idx, "x"]
269-
)
273+
data.loc[bool_idx, "x"] = 2 * x_mean[bool_idx] - x[bool_idx]
270274

271275
match style:
272276
case "left":

plotnine/stats/stat_summary_bin.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import TYPE_CHECKING, cast
2+
13
import numpy as np
24
import pandas as pd
35

@@ -9,6 +11,9 @@
911
from .stat import stat
1012
from .stat_summary import make_summary_fun
1113

14+
if TYPE_CHECKING:
15+
from plotnine.typing import IntArray
16+
1217

1318
@document
1419
class stat_summary_bin(stat):
@@ -157,7 +162,8 @@ def func_wrapper(data: pd.DataFrame) -> pd.DataFrame:
157162
# This is a plyr::ddply
158163
out = groupby_apply(data, "bin", func_wrapper)
159164
centers = (breaks[:-1] + breaks[1:]) * 0.5
160-
bin_centers = centers[out["bin"].to_numpy()]
165+
bin = cast("IntArray", out["bin"].to_numpy())
166+
bin_centers = centers[bin]
161167
out["x"] = bin_centers
162168
out["bin"] += 1
163169
if isinstance(scales.x, scale_discrete):

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ dev = [
8383
typing = [
8484
"pyright==1.1.404",
8585
"ipython",
86-
"pandas-stubs==v2.3.2.250827",
86+
"pandas-stubs",
8787
]
8888

8989
[project.urls]

0 commit comments

Comments
 (0)