From 187885b4a3b9f54dbe27d568639931b8094b488e Mon Sep 17 00:00:00 2001 From: Mike Taves Date: Fri, 19 Apr 2024 14:39:13 +1200 Subject: [PATCH] fix(OptionBlock): deprecate attribute typo 'auxillary' -> 'auxiliary' (#2159) --- .docs/Notebooks/nwt_option_blocks_tutorial.py | 4 ++-- autotest/test_uzf.py | 15 ++++++++++++++ flopy/modflow/mfwel.py | 8 ++++---- flopy/pakbase.py | 10 +++++----- flopy/utils/optionblock.py | 20 ++++++++++++++++++- 5 files changed, 45 insertions(+), 12 deletions(-) diff --git a/.docs/Notebooks/nwt_option_blocks_tutorial.py b/.docs/Notebooks/nwt_option_blocks_tutorial.py index f9acbb18cc..0bd0d45645 100644 --- a/.docs/Notebooks/nwt_option_blocks_tutorial.py +++ b/.docs/Notebooks/nwt_option_blocks_tutorial.py @@ -183,9 +183,9 @@ options.noprint = True -# and the user can also add auxillary variables by using `options.auxillary` +# and the user can also add auxiliary variables by using `options.auxiliary` -options.auxillary = ["aux", "iface"] +options.auxiliary = ["aux", "iface"] # ### Now we can create a new wel file using this `OptionBlock` # diff --git a/autotest/test_uzf.py b/autotest/test_uzf.py index aa3018d703..b95a852bb2 100644 --- a/autotest/test_uzf.py +++ b/autotest/test_uzf.py @@ -658,3 +658,18 @@ def test_uzf_negative_iuzfopt(function_tmpdir): assert ( np.max(extpd) == np.min(extpd) and np.max(extpd) != 0.2 ), "Read error for iuzfopt less than 0" + + +def test_optionsblock_auxillary_typo(): + # Incorrect: auxillary + # Correct: auxiliary + options = OptionBlock("", ModflowWel, block=True) + assert options.auxiliary == [] + with pytest.deprecated_call(): + assert options.auxillary == [] + with pytest.deprecated_call(): + options.auxillary = ["aux", "iface"] + assert options.auxiliary == ["aux", "iface"] + options.auxiliary = [] + with pytest.deprecated_call(): + assert options.auxillary == [] diff --git a/flopy/modflow/mfwel.py b/flopy/modflow/mfwel.py index e1326721c8..b6532331e5 100644 --- a/flopy/modflow/mfwel.py +++ b/flopy/modflow/mfwel.py @@ -222,8 +222,8 @@ def __init__( options.append(f"aux {name} ") if isinstance(self.options, OptionBlock): - if not self.options.auxillary: - self.options.auxillary = options + if not self.options.auxiliary: + self.options.auxiliary = options else: self.options = options @@ -282,9 +282,9 @@ def write_file(self, f=None): if isinstance(self.options, OptionBlock): if self.options.noprint: line += "NOPRINT " - if self.options.auxillary: + if self.options.auxiliary: line += " ".join( - [str(aux).upper() for aux in self.options.auxillary] + [str(aux).upper() for aux in self.options.auxiliary] ) else: diff --git a/flopy/pakbase.py b/flopy/pakbase.py index 0b592888d0..638926a3ec 100644 --- a/flopy/pakbase.py +++ b/flopy/pakbase.py @@ -1002,15 +1002,15 @@ def load( it += 1 it += 1 - # add auxillary information to nwt options + # add auxiliary information to nwt options if nwt_options is not None: if options: if options[0] == "noprint": nwt_options.noprint = True if len(options) > 1: - nwt_options.auxillary = options[1:] + nwt_options.auxiliary = options[1:] else: - nwt_options.auxillary = options + nwt_options.auxiliary = options options = nwt_options @@ -1034,9 +1034,9 @@ def load( if options[0] == "noprint": nwt_options.noprint = True if len(options) > 1: - nwt_options.auxillary = options[1:] + nwt_options.auxiliary = options[1:] else: - nwt_options.auxillary = options + nwt_options.auxiliary = options options = nwt_options else: diff --git a/flopy/utils/optionblock.py b/flopy/utils/optionblock.py index 0826dec8d9..1130400218 100644 --- a/flopy/utils/optionblock.py +++ b/flopy/utils/optionblock.py @@ -1,3 +1,5 @@ +import warnings + import numpy as np from ..utils import flopy_io @@ -49,13 +51,22 @@ def __init__(self, options_line, package, block=True): self._attr_types = {} self.options_line = options_line self.package = package - self.auxillary = [] + self.auxiliary = [] self.noprint = False self.block = block self.__build_attr_types() self._set_attributes() + def __getattr__(self, key): + if key == "auxillary": # catch typo from older version + key = "auxiliary" + warnings.warn( + "the atttribute 'auxillary' is deprecated, use 'auxiliary' instead", + category=DeprecationWarning, + ) + return super().__getattribute__(key) + @property def single_line_options(self): """ @@ -150,6 +161,13 @@ def __setattr__(self, key, value): is consistant with the attribute data type """ + if key == "auxillary": # catch typo from older version + key = "auxiliary" + warnings.warn( + "the atttribute 'auxillary' is deprecated, use 'auxiliary' instead", + category=DeprecationWarning, + ) + err_msg = "Data type must be compatible with {}" if key in ("_context", "_attr_types", "options_line"): self.__dict__[key] = value