yt-project / unyt

Handle, manipulate, and convert data with units in Python
https://unyt.readthedocs.io
BSD 3-Clause "New" or "Revised" License
364 stars 49 forks source link

BUG: fix subtraction for different dimensionally equivalent units #413

Closed neutrinoceros closed 1 year ago

neutrinoceros commented 1 year ago

end goal: fix #220 This is very preliminary, as multiple tests are currently broken, but it's getting late, so I'm opening to get this out of my system for today.

ngoldbaum commented 1 year ago

Let me know if you'd like a hand with this.

neutrinoceros commented 1 year ago

Sure ! I'm actually having a hard time understanding how my changes affect tests unyt/tests/test_unyt_array.py

ngoldbaum commented 1 year ago

I'm actually having a hard time understanding how my changes affect tests unyt/tests/test_unyt_array.py

See d708386

neutrinoceros commented 1 year ago

awesome, well played ! The one remaining failure (in docs) touches a case that I'm not sure how to treat. Should 1*delta_degC - 1*degC remain a valid operation ?

ngoldbaum commented 1 year ago

It looks like Pint returns data in units of degC, so I think we should probably follow that. I guess one way to justify it is:

1*delta_degC - 1*degC = -1 * (1*degC - 1*delta_degC)

So it makes sense for both operations to return results in the same units.

It also means we're not raising a new error without a deprecation, which is nice.

neutrinoceros commented 1 year ago

Ok, let's do this then.

neutrinoceros commented 1 year ago

I think this is now ready. Thanks a lot for your help Nathan !