Skip to content

Convert ediff1d boundary differences to the input units - #283

Open
antonsoo wants to merge 1 commit into
python-quantities:masterfrom
antonsoo:fix/ediff1d-boundary-units
Open

antonsoo wants to merge 1 commit into
python-quantities:masterfrom
antonsoo:fix/ediff1d-boundary-units

Conversation

@antonsoo

Copy link
Copy Markdown

pq.ediff1d currently strips the units of to_begin and to_end without converting their magnitudes:

import quantities as pq

voltage = [1., 3., 6.] * pq.mV
print(pq.ediff1d(voltage, to_begin=1000 * pq.uV))

This returns [1000., 2., 3.] mV; the first value should be 1 mV. Rescale quantity-valued boundary differences to the input units before passing their magnitudes to NumPy. Incompatible dimensions now raise ValueError. Numeric boundaries retain their existing interpretation, and NumPy's casting checks apply after conversion.

Tests cover both boundaries, scalar and array values, flattened inputs, incompatible dimensions and integer casting. 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; the existing NumPy 2.5 typing error is unchanged and covered by #277. Advisory lint results are unchanged.

In a chunk-differencing check on four channels of PhysioNet's S001R01 EEG recording, converting boundary differences from microvolts to millivolts removes 96 wrong values across 72 cases. All 144 same-unit or numeric-boundary controls remain identical.

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.

1 participant