Skip to content
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

Handle changed functions in check_units decorator #1612

Merged
merged 4 commits into from Dec 21, 2020

Conversation

dopplershift
Copy link
Member

Description Of Changes

Augment the check_units decorator to detect errors from functions that have changed and add that information to the error message.

Checklist

  • Closes #xxxx
  • Tests added

@dopplershift dopplershift marked this pull request as draft December 17, 2020 22:15
@dopplershift dopplershift added Area: Units Pertains to unit information Type: Enhancement Enhancement to existing functionality labels Dec 17, 2020
@dopplershift dopplershift added this to the 1.0 milestone Dec 17, 2020
@dopplershift
Copy link
Member Author

So for this code:

import metpy.calc as mpcalc
from metpy.units import units

p = 1000 * units.hPa
q = 0.8
t = 27 * units.degC

mpcalc.dewpoint_from_specific_humidity(q, t, p)

gives (in Jupyter):

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-6-eb9bf1fd3039> in <module>
      6 t = 27 * units.degC
      7 
----> 8 mpcalc.dewpoint_from_specific_humidity(q, t, p)

~/repos/metpy/src/metpy/xarray.py in wrapper(*args, **kwargs)
   1218 
   1219             # Evaluate inner calculation
-> 1220             result = func(*bound_args.args, **bound_args.kwargs)
   1221 
   1222             # Wrap output based on match and match_unit

~/repos/metpy/src/metpy/units.py in wrapper(*args, **kwargs)
    243                         msg = (f'This function changed in {changed_version}--double check '
    244                                'that the function is being called properly.') + msg
--> 245                 raise ValueError(msg)
    246             return func(*args, **kwargs)
    247 

ValueError: This function changed in 1.0--double check that the function is being called properly.`dewpoint_from_specific_humidity` given arguments with incorrect units: `pressure` requires "[pressure]" but given "none", `specific_humidity` requires "[dimensionless]" but given "hectopascal"
Any variable `x` can be assigned a unit as follows:
    from metpy.units import units
    x = x * units.meter / units.second

What do we think?

@dopplershift dopplershift force-pushed the decorator branch 2 times, most recently from 060cbc6 to 85a898b Compare December 19, 2020 04:49
@ghost
Copy link

ghost commented Dec 19, 2020

Congratulations 🎉. DeepCode analyzed your code in 3.83 seconds and we found no issues. Enjoy a moment of no bugs ☀️.

👉 View analysis in DeepCode’s Dashboard | Configure the bot

@dopplershift
Copy link
Member Author

This should be ready for a review.

This augments the message that comes out from `check_units` based on
whether the `versionchanged` sphinx directive is found in the docstring.
Also add a test to make sure the message is working
@dopplershift dopplershift merged commit d9983dd into Unidata:master Dec 21, 2020
@dopplershift dopplershift deleted the decorator branch December 21, 2020 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Units Pertains to unit information Type: Enhancement Enhancement to existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants