Skip to content

Commit

Permalink
fix(OptionBlock): deprecate attribute typo 'auxillary' -> 'auxiliary' (
Browse files Browse the repository at this point in the history
  • Loading branch information
mwtoews authored Apr 19, 2024
1 parent 30e0349 commit 187885b
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 12 deletions.
4 changes: 2 additions & 2 deletions .docs/Notebooks/nwt_option_blocks_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`
#
Expand Down
15 changes: 15 additions & 0 deletions autotest/test_uzf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 == []
8 changes: 4 additions & 4 deletions flopy/modflow/mfwel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions flopy/pakbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand Down
20 changes: 19 additions & 1 deletion flopy/utils/optionblock.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import warnings

import numpy as np

from ..utils import flopy_io
Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 187885b

Please sign in to comment.