Skip to content

Commit b2cc7c8

Browse files
committed
ty: un-ignore parameter-already-assigned (1 file, 1 spot)
plt.axes(projection="3d") is typed to return the base 2D Axes, so ax.scatter's 3rd positional arg (meant as zs) was resolving against 2D Axes.scatter's `s` parameter and colliding with the explicit s=100 kwarg. Cast ax to Axes3D so ty resolves the correct (xs, ys, zs, ...) overload instead. Part of #15187
1 parent 0a72d14 commit b2cc7c8

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

‎machine_learning/k_means_clust.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,12 @@
4848
"""
4949

5050
import warnings
51+
from typing import cast
5152

5253
import numpy as np
5354
import pandas as pd
5455
from matplotlib import pyplot as plt
56+
from mpl_toolkits.mplot3d import Axes3D
5557
from sklearn.metrics import pairwise_distances
5658

5759
warnings.filterwarnings("ignore")
@@ -157,7 +159,10 @@ def plot_heterogeneity(heterogeneity, k) -> None:
157159

158160

159161
def plot_kmeans(data, centroids, cluster_assignment) -> None:
160-
ax = plt.axes(projection="3d")
162+
# plt.axes() is typed to return the base 2D Axes, but projection="3d" makes
163+
# it an Axes3D at runtime; cast so ty resolves Axes3D.scatter's (xs, ys, zs)
164+
# signature instead of colliding its 3rd positional arg with the `s` kwarg.
165+
ax = cast(Axes3D, plt.axes(projection="3d"))
161166
ax.scatter(data[:, 0], data[:, 1], data[:, 2], c=cluster_assignment, cmap="viridis")
162167
ax.scatter(
163168
centroids[:, 0], centroids[:, 1], centroids[:, 2], c="red", s=100, marker="x"

‎pyproject.toml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,6 @@ rules.invalid-return-type = "ignore"
323323
rules.no-matching-overload = "ignore"
324324
rules.not-iterable = "ignore"
325325
rules.not-subscriptable = "ignore"
326-
rules.parameter-already-assigned = "ignore"
327326
rules.unresolved-attribute = "ignore"
328327
rules.unresolved-import = "ignore"
329328
rules.unsupported-operator = "ignore"

0 commit comments

Comments
 (0)