-
Notifications
You must be signed in to change notification settings - Fork 415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MetPy needs a general solution for returning scalars when provided scalars #1209
Comments
It would be good to have something to do this--of course it would be better if we didn't have to care and things just worked with scalars transparently, but alas. I wonder if a decorator would be enough--and if we could get away with only applying to functions that need the help? MetPy should NOT be modifying any arguments in-place. If you see places where we're doing something like that, please open an issue (or even better another PR 😉). Your issue with pint I think is related to an issue I opened ages ago in Pint: hgrecco/pint#481. |
Same as numpy/numpy#12636? I'm guessing numpy doesn't change anything anytime soon, but it would be nice if there was a recommended solution available for package maintainers. |
Today I wanted to return a scalar from from metpy.units import units
from metpy.calc import heat_index
hi = heat_index(30 * units.degC, 0.65)
print("hi.m type is: %s" % (type(hi.m),))
# hi.m type is: <class 'numpy.ndarray'> Additionally I tried Line 379 in eb3fa00
but fails too: from metpy.calc import apparent_temperature
from metpy.units import units
at = apparent_temperature(90 * units.degF, .6, 5 * units.mph)
print("at.m type is: %s" % (type(at.m),))
# at.m type is: <class 'numpy.ndarray'> Does these behaviors also relate to this issue? |
Certainly the hasattr(5 * units.m, '__len__') returns It looks like doing |
This issue continues to be a bit of trouble with Numpy now warning about using single element arrays as if they were floats.
|
@akrherz Is this with pint 0.23? |
yes , I was efforting some code in this space earlier this morning while it worked on python 3.11, it failed on python 3.9. I haven't taken a chance to dig further, sorry. |
Depending on the function, some MetPy calculations will return scalars when provided scalars or return numpy scalar array when provided a scalar. For example:
Functions like
apparent_temperature
got ais_not_scalar
hack in #838 that attempts to keep track of the inbound Quantity magnitude dimensionality and then return the result with that same dimensionality.I started down the path of writing a helper for this:
But this approach quickly broke down as some functions modify their arguments and thus can no longer be checked at function return time. I also found some surprising/scary
pint.Quantity
in-place modification when usingnp.asarray
.Any thoughts here on what a general solution to this could be?
The text was updated successfully, but these errors were encountered: