Skip to content

fix(base): accept a list of rows in getmatrix and a range in getvector - #278

Open
MrNK2107 wants to merge 1 commit into
rai-opensource:masterfrom
MrNK2107:fix/getmatrix-nested-lists-255
Open

MrNK2107 wants to merge 1 commit into
rai-opensource:masterfrom
MrNK2107:fix/getmatrix-nested-lists-255

Conversation

@MrNK2107

Copy link
Copy Markdown

Part of #255.

getmatrix() raised TypeError for a nested list or tuple, such as a 2xN path written as [[0, 1, 2], [0, 1, 0]], and getvector() raised TypeError for a range.

  • getmatrix: a list or tuple that isn't a vector is converted with np.array and then goes through the existing 2D branch, so its shape is checked against shape (a mismatch raises ValueError; it isn't reshaped). A range is treated as a 1D sequence.
  • getvector: a range is converted to a list first, so every out format works.

Not changed: a flat list is still reshaped (getmatrix([0, 1, 2, 3], (2, None)) is still (2, 2)), and Points2/Points3 are untouched. Both change public behaviour, so I've left them for a separate decision.

Behaviour change: inputs that used to raise TypeError are now accepted; nothing that previously worked returns a different result.

Tests: new cases in tests/base/test_argcheck.py for nested lists/tuples (including shape mismatch) and range in getvector. Both fail on master and pass with the fix. Full suite: 475 passed, 3 skipped (master: 473 passed, 3 skipped). black and flake8 are clean on the changed files.

AI disclosure: I used an AI assistant while working on this; I've read the diff and run the tests myself.

getmatrix() raised TypeError for a nested list or tuple, such as a 2xN
path written as [[0, 1, 2], [0, 1, 0]], and getvector() raised TypeError
for a range. Convert a nested sequence to an array and check its shape
like any 2D array, and treat a range like a list.

A flat list is still reshaped as before.

Refs rai-opensource#255
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@petercorke

Copy link
Copy Markdown
Collaborator

Thank you for your interest in SMTB, and for the thoughtful change! Accepting a list of rows in getmatrix and a range in getvector is a sensible extension for #255, and I appreciate that you kept Points2/Points3 out of scope and listed what you left alone. The tests and the shape-check behavior look good to me.

Two requests:

  1. 1.1.19 is now released, and this PR currently has merge conflicts with master. Could you rebase onto the current master and resolve them?
  2. Could you check how getmatrix behaves with ragged input, such as [[1, 2, 3], [4, 5]]? As written it falls through to np.array, so the user would see NumPy's own error rather than one from getmatrix. A clear ValueError for that case, with a test, would be ideal.

Once those are done I'm happy to approve. I can only approve; we rely on RAI to merge and publish.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants