Skip to content

fix: type k-means 3D plotting and enable parameter-already-assigned - #15511

Open
gcomneno wants to merge 1 commit into
TheAlgorithms:masterfrom
gcomneno:fix/kmeans-axes3d-typing
Open

gcomneno wants to merge 1 commit into
TheAlgorithms:masterfrom
gcomneno:fix/kmeans-axes3d-typing

Conversation

@gcomneno

@gcomneno gcomneno commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Describe your change

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Add or change doctests? -- Note: Please avoid changing both code and tests in a single pull request.
  • Documentation change?

plt.axes(projection="3d") creates an Axes3D, but its static return type
is the base 2D Axes. Consequently, ty interprets the third centroid
coordinate as s and reports a collision with the explicit s=100.

Cast the created axis to Axes3D and annotate all three parameters of
plot_kmeans as NumPy arrays. With no remaining
parameter-already-assigned diagnostics repository-wide, remove that
rule's ignore entry from pyproject.toml.

Part of #15187.

This follows the approach discussed in the closed PR #15463 and includes
the parameter annotations requested in its review:
#15463 (comment)

Validation

  • All 22 module doctests passed on standard CPython 3.15.0rc2.
  • The targeted ty check passed with parameter-already-assigned enabled.
  • The repository-wide ty check reported zero diagnostics for that rule;
    59 other diagnostics remain. The full ty baseline is not clean.
  • An Agg-backend comparison against the original implementation confirmed
    identical coordinates, marker sizes, face colors, marker paths, labels,
    and rendered pixels for the tested input.
  • Applicable pre-commit hooks and git diff --check passed.
  • The full repository test suite was not run.

AI assistance

ChatGPT helped investigate the diagnostic and prepare the patch and
verification commands. I reviewed the diff and ran the reported checks locally.

Checklist

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms include at least one URL that points to Wikipedia or another similar explanation.
  • If this pull request resolves one or more open issues, then the description above includes the issue number(s) with a closing keyword.

No new files or algorithms are added. Existing unannotated functions and
functions without doctests remain outside this change; the modified
plot_kmeans signature is fully annotated. The tracking issue remains open.

@algorithms-keeper algorithms-keeper Bot added awaiting reviews This PR is ready to be reviewed enhancement This PR modified some existing files labels Oct 6, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting reviews This PR is ready to be reviewed enhancement This PR modified some existing files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant