Repository navigation
Conversation
|
Thanks for this. Keeping units through I ran Neo's core tests with this branch, and three fail ( times = np.hstack([self.times, othertimes]) * self.times.unitswhich currently gives
There's also one inconsistency to settle before merging: |
# Conflicts: # doc/user/issues.rst
|
Thanks for running Neo against it, that's a really useful check. The plan sounds good to me. I merged master in, which resolved the conflict, and moved the changelog entry to a new "Unreleased" section, marked as a Behaviour change. It now names the On the mixed case, I'd keep what the PR does now: as soon as any argument isn't a Quantity, it falls back to the old behaviour. My reasons:
If you'd rather have mixed calls be consistent too, I think raising for a non-Quantity argument when |
Fixes #50 and #88.
np.concatenateon Quantity arrays joined the bare magnitudes and returned a dimensionless result.np.hstack,np.vstack,np.stackandnp.appendgo through it, so they lost the units too:This handles
np.concatenateinQuantity.__array_function__, likenp.ptp. The result takes the units of the first array and the others are rescaled to them, sonp.concatenate([[1, 2] * pq.m, [50, 300] * pq.cm])gives[1, 2, 0.5, 3] m, and incompatible units raiseValueError.It only applies when every item is a plain
Quantity. These keep their old behaviour: a mix with non-Quantity items (e.g.np.append(q, np.nan), whichtest_nanargmaxrelies on),UncertainQuantity, and calls without=.Tests cover concatenate (axes,
axis=None, unit conversion, incompatible units,out/dtype, plain arrays) and hstack/vstack/stack/append. Full suite passes on NumPy 2.5 and Ruff is clean. I also removedvstackfrom the "functions which drop units" list and added a changelog line.