home / github / issue_comments

Menu
  • GraphQL API
  • Search all tables

issue_comments: 532325585

This data as json

html_url issue_url id node_id user created_at updated_at author_association body reactions performed_via_github_app issue
https://github.com/pydata/xarray/pull/3238#issuecomment-532325585 https://api.github.com/repos/pydata/xarray/issues/3238 532325585 MDEyOklzc3VlQ29tbWVudDUzMjMyNTU4NQ== 14808389 2019-09-17T17:41:13Z 2019-09-17T17:41:13Z MEMBER

I'm not sure where to put this, so I'll post this here.

While working on the numpy methods part and using any of the pint versions implement __array_function__ (hgrecco/pint#764 and andrewgsavage/pint#6) , I encountered the following: ```python

array = np.array([1.3, 3.1, 7.5]) array.searchsorted(2.4) 1 (array * ureg.m).searchsorted(2.4 * ureg.m) Traceback (most recent call last): File "<stdin>", line 1, in <module> File ".../pint/quantity.py", line 1548, in searchsorted raise DimensionalityError('dimensionless', self._units) pint.errors.DimensionalityError: Cannot convert from 'dimensionless' to 'meter' (array * ureg.m).searchsorted(2.4) <Traceback> pint.errors.DimensionalityError: Cannot convert from 'dimensionless' to 'meter' (array * ureg.m).searchsorted(2.4 * ureg.s) <Traceback> pint.errors.DimensionalityError: Cannot convert from 'dimensionless' to 'meter' I believe that is because in `BaseQuantity.searchsorted`, `self.__class__` is used to check the type, which may be either `QuantitySequence` or `QuantityScalar`. If `self` is a sequence and a scalar is passed to the method, this fails. To fix this, replacing `self.__class__` with `BaseQuantity` seems to work.python np.searchsorted(array * ureg.m, 2.4 * ureg.m) <Quantity(1, 'meter')> np.searchsorted(array * ureg.m, 2.4) <Quantity(1, 'meter')> np.searchsorted(array * ureg.m, 2.4 * ureg.s) <Traceback> pint.errors.DimensionalityError: Cannot convert from 'second' ([time]) to 'meter' ([length]) `` I don't know what to do here (using the code from andrewgsavage/pint#6 I tried movingsearchsortedinto the same category asisclose` -- this seems to work partially, but passing non-quantities is still allowed), but the result should be indices and incompatible units (or no unit at all) should raise an error.

Both the method and the function work fine with current master.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  484015016
Powered by Datasette · Queries took 0.659ms · About: xarray-datasette