Hacktoberfest 2026: die Issues, die Maintainer für den Oktober markiert haben – offen und einsteigerfreundlich. Hacktoberfest-Issues durchsuchen

getmatrix() rejects a list of lists; revisit the base.X matrix/vector converters

Offen
#255 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
35/100
Issue-Typ
Feature
Klarheit
Größtenteils klar
Aktivitätsstatus
Aktiv
Tech-Stack
numpy, python
Bereich
tooling

Rechercherichtung

Start with getmatrix and getvector in the spatialmath base package, plus isvector and ismatrix, and run the three examples in the issue to reproduce the TypeError and the flat-list reshape. Check spatialmath/base/types.py for Points2 and Points3. The issue leaves open whether the flat-list reshape is intended and whether the type aliases should widen, so settle those with a maintainer before changing code. Done means nested lists and tuples are converted and shape-checked, with tests for the existing converters.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

getmatrix() (and getvector()) reject the most natural way to write a set of points: a list of lists. Found while adding type hints to RTB, where a 2xN path of waypoints is passed to a function.

from spatialmath.base import getmatrix
getmatrix([[0, 1, 2], [0, 1, 0]], (2, None))   # TypeError: argument must be scalar or ndarray
getmatrix([[0, 0], [1, 1], [2, 0]], (2, None))  # TypeError
getmatrix(np.zeros((2, 5)), (2, None))          # OK, (2, 5)

Two related problems:

  1. Nested lists and tuples are rejected. The function accepts a scalar, a 1D array-like or an ndarray, but not a list of rows. I would expect it to convert these with np.asarray and then check the shape against shape, raising ValueError on mismatch.
  2. A flat list is silently reshaped. getmatrix([0, 1, 2, 3], (2, None)) returns a (2, 2) array. That is convenient for (2,2) but can hide a mistake when the caller meant a path of 2 points or a different layout.

Also, Points2 and Points3 in spatialmath.base.types are plain NDArray, so the type hint says "ndarray only" while the docstrings in callers say "array_like".

Suggested direction:

  • Make getmatrix (and the other base.X... converters) accept array-likes of any nesting and validate the shape, so callers can replace hand-written np.asarray(...) plus ndim/shape checks with one call.
  • Decide whether the flat-list reshape is intended, and document it if so.
  • Consider whether Points2/Points3 should widen to accept sequences.

I'll revisit the base.getvector/getmatrix/isvector/ismatrix family together, since the same question applies to all of them.

Vorherrschende Sprache
Python
Sterne
648
Forks
108
Ø Merge
10 T. 20 Std.
Gemergte PRs (30 T.)
21

Entwicklungsumgebung

Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus rai-opensource/spatialmath-python

Alle Issues in rai-opensource/spatialmath-python

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.