Pewarta Proxy

📋 Server Request & Proxy Logs

Loading active proxy settings...
Developed by Khairul Adha (adhexa.id)
Mengambil log server...

⚙️ Pengaturan Proxy Target

Skip to content

Allow numeric bounds when clipping dimensionless quantities - #282

Open
antonsoo wants to merge 1 commit into
python-quantities:masterfrom
antonsoo:fix/dimensionless-clip-bounds
Open

antonsoo wants to merge 1 commit into
python-quantities:masterfrom
antonsoo:fix/dimensionless-clip-bounds

Conversation

@antonsoo

Copy link
Copy Markdown

Clipping a dimensionless Quantity with numeric limits currently raises AttributeError:

import quantities as pq

q = pq.Quantity([-2., 0.5, 3.])
print(q.clip(0, 1))

This should return [0., 0.5, 1.] dimensionless. Convert the bounds to quantities before rescaling them, after the existing check that requires quantity-valued bounds for dimensional inputs.

Fixes #108. The regression covers scalar, array and one-sided bounds, np.clip, output buffers and incompatible units. Both the full suite and README doctests pass on Python 3.10/NumPy 1.24 and Python 3.12/NumPy 2.4 and 2.5. Mypy passes on NumPy 1.24 and 2.4; NumPy 2.5 has the same quantity.pyi error on unchanged master, already addressed by #277. The advisory lint results are unchanged.

I also checked clipping normalized channels from PhysioNet's S001R01 EEG recording against NumPy magnitude calculations: all 24 previously failing configurations now complete, and the eight configurations with explicit Quantity bounds retain identical results.

Fixes python-quantities#108. Normalize dimensionless numeric bounds before rescaling, preserving dimensional-bound validation and output behavior.
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.

clip fails for *dimensionless* Quantities when the limits are not Quantities.

1 participant