From 3ac6230249b73e09c9a92a23c7e729ab11aa88d2 Mon Sep 17 00:00:00 2001 From: Chris Sewell Date: Tue, 18 Jun 2019 02:44:18 +0100 Subject: [PATCH] `get_in_units` fix --- .vscode/settings.json | 6 +++--- jsonextended/__init__.py | 2 +- jsonextended/units/core.py | 6 ++++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 729d154..8dd0ae8 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,8 +1,8 @@ { "editor.rulers": [80], - "python.unitTest.pyTestEnabled": true, - "python.unitTest.unittestEnabled": false, - "python.unitTest.nosetestsEnabled": false, + "python.testing.pyTestEnabled": true, + "python.testing.unittestEnabled": false, + "python.testing.nosetestsEnabled": false, "python.pythonPath": "/anaconda/envs/lsr/bin/python", "python.linting.pylintEnabled": false, "python.linting.flake8Enabled": true, diff --git a/jsonextended/__init__.py b/jsonextended/__init__.py index 3b57ff5..498924c 100755 --- a/jsonextended/__init__.py +++ b/jsonextended/__init__.py @@ -93,6 +93,6 @@ """ -__version__ = '0.7.10' +__version__ = '0.7.11' from jsonextended import ejson, units, utils, edict, plugins # noqa: F401 diff --git a/jsonextended/units/core.py b/jsonextended/units/core.py index 646dc9c..2bfba2d 100755 --- a/jsonextended/units/core.py +++ b/jsonextended/units/core.py @@ -15,9 +15,11 @@ def get_in_units(value, units): """get a value in the required units """ try: - return ureg.Quantity(value, units) - except NameError: + from pint import UnitRegistry + ureg = UnitRegistry() + except ImportError: raise ImportError('please install pint to use this module') + return ureg.Quantity(value, units) def apply_unitschema(data, uschema, as_quantity=True,