pint icon indicating copy to clipboard operation
pint copied to clipboard

how to make sure Quantity cannot wrap a user defined object

Open seb5g opened this issue 4 months ago • 4 comments

Hi there, I'm developing a data acquisition framework (PyMoDAQ) and data handling. The main objects (let's say DataBase holds data as a list of numpy arrays and an attribute being units. So I'm using quite a bit of pint functionalities under the hood, simply adding compatibility for list of ndarrays. By implementing array_ufunc and array_function and using their implementation in pint, I could quickly get it working for many functions. However when I execute:

Quantity(1, 's') * DataBase(...)

I'm getting a quantity with a magnitude being my DataBase object.

When I'm doing the other way around:

 DataBase(...) * Quantity(1, 's')

I properly (what I want at least) get the product of the underlying quantities (with units handling).

Here comes the question:

How can I be sure that this is always my DataBase that will have the priority?

I tried the __array_priority__ attribute (I saw you set it to 17 for your numpy wrapping quantities) but it doesn't work.

I also almost understand the idea of upcast_type but i'm actually not sure if this is or not related to my issue...

Thxs

seb5g avatar Oct 19 '24 12:10 seb5g