Skip to content

Commit

Permalink
add temporary fix allowing use of 'delta' in
Browse files Browse the repository at this point in the history
  • Loading branch information
peterstangl committed Dec 15, 2023
1 parent 8025ccb commit 15e3436
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
17 changes: 15 additions & 2 deletions wilson/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ def set_default_option(cls, key, value):
Note that this does not affect existing instances or the instance
called from."""
####################################################################
### temporary fix to keep backwards compatibility after renaming ###
### of 'delta' to 'gamma' in the parameters dictionary ###
####################################################################
if key == 'parameters' and 'delta' in value:
warnings.warn("Using the parameter 'delta' is deprecated. "
"Please use 'gamma' instead. Support for using "
"'delta' will be removed in the future.",
FutureWarning)
value['gamma'] = value['delta']
del value['delta']
####################################################################
cls._default_options.update(cls._option_schema({key: value}))

def set_option(self, key, value):
Expand All @@ -60,8 +72,9 @@ def set_option(self, key, value):
####################################################################
if key == 'parameters' and 'delta' in value:
warnings.warn("Using the parameter 'delta' is deprecated. "
"Please use 'gamma' instead. Support for 'delta' "
"will be removed in the future.", FutureWarning)
"Please use 'gamma' instead. Support for using "
"'delta' will be removed in the future.",
FutureWarning)
value['gamma'] = value['delta']
del value['delta']
####################################################################
Expand Down
5 changes: 5 additions & 0 deletions wilson/test_wilson.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ def test_config_parameters(self):
w.set_option('parameters', {'delta': 1.})
self.assertEqual(len(warns), 1)
self.assertTrue(issubclass(warns[-1].category, FutureWarning))
with warnings.catch_warnings(record=True) as warns:
warnings.simplefilter("always")
w.set_default_option('parameters', {'delta': 1.})
self.assertEqual(len(warns), 1)
self.assertTrue(issubclass(warns[-1].category, FutureWarning))
# int should be OK but corced to float
w.set_option('parameters', {'bla': 1})
self.assertTrue(type(w.get_option('parameters')['bla']), float)
Expand Down

0 comments on commit 15e3436

Please sign in to comment.