Skip to content

Commit 7e28d34

Browse files
committed
Removed API methods that were deprecated in version 1.0.
1 parent 05b3b23 commit 7e28d34

File tree

2 files changed

+13
-161
lines changed

2 files changed

+13
-161
lines changed

mph/model.py

Lines changed: 13 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from numpy import integer
99
from pathlib import Path
1010
from re import match
11-
from warnings import warn
1211
from logging import getLogger
1312

1413
from jpype import JClass
@@ -629,30 +628,27 @@ def rename(self, name: str):
629628

630629
@overload
631630
def parameter(self,
632-
name: str,
633-
value: str | int | float | complex,
634-
unit: str | None,
635-
description: str | None,
636-
evaluate: Literal[False],
631+
name: str,
632+
value: str | int | float | complex,
633+
*,
634+
evaluate: Literal[False],
637635
): ...
638636
@overload
639637
def parameter(self,
640-
name: str,
641-
value: Literal[None],
642-
unit: Literal[None],
643-
description: Literal[None],
644-
evaluate: Literal[False],
638+
name: str,
639+
value: Literal[None],
640+
*,
641+
evaluate: Literal[False],
645642
) -> str: ...
646643
@overload
647644
def parameter(self,
648-
name: str,
649-
value: Literal[None],
650-
unit: Literal[None],
651-
description: Literal[None],
652-
evaluate: Literal[True],
645+
name: str,
646+
value: Literal[None],
647+
*,
648+
evaluate: Literal[True],
653649
) -> int | float | complex: ...
654650
def parameter(
655-
self, name, value=None, unit=None, description=None, evaluate=False
651+
self, name, value=None, *, evaluate=False
656652
):
657653
"""
658654
Returns or sets the parameter of the given name.
@@ -669,21 +665,7 @@ def parameter(
669665
the unit, again inside brackets. If the option `evaluate` is set
670666
to `True`, the numerical value that the expression evaluates to
671667
is returned.
672-
673-
*Warning*: The optional arguments `unit` and `description` are
674-
deprecated and will be removed in a future release. Include the
675-
unit in the value expression and call the `description()` method
676-
to change a parameter description.
677668
"""
678-
if unit is not None:
679-
warn('Argument "unit" to Model.parameter() is deprecated. '
680-
'Include the unit in the value inside square brackets.')
681-
if value:
682-
value = f'{value} [{unit}]'
683-
if description is not None:
684-
warn('Argument "description" to Model.parameter() is deprecated. '
685-
'Call .description() instead.')
686-
self.description(name, description)
687669
if value is None:
688670
if not evaluate:
689671
try:
@@ -725,13 +707,6 @@ def parameters(self, evaluate=False):
725707
the user, unless `evaluate` is set to `True`, in which case
726708
the expressions are evaluated and the corresponding numbers
727709
are returned.
728-
729-
*Warning*: Prior to version 1.0, this method would return
730-
a list of named tuples holding name, value, and description.
731-
It now returns a dictionary, which is a breaking change that
732-
may require application code to be adapted. The descriptions
733-
can be retrieved by additionally calling `.description()` or
734-
`.descriptions()`.
735710
"""
736711
if not evaluate:
737712
return {str(name): str(self.java.param().get(name))
@@ -1010,70 +985,3 @@ def save(self, path: Path | str = None, format: str = None):
1010985
else:
1011986
self.java.save(str(file), type)
1012987
log.info('Finished saving model.')
1013-
1014-
###############
1015-
# Deprecation #
1016-
###############
1017-
1018-
def features(self, physics: str) -> list[str]:
1019-
# Returns the names of all features in a given physics interface.
1020-
#
1021-
# The term feature refers to the nodes defined under a physics
1022-
# interface. They define the differential equations, boundary
1023-
# conditions, initial values, etc.
1024-
warn('Model.features() is deprecated. Use the Node class instead.')
1025-
if physics not in self.physics():
1026-
error = f'No physics interface named "{physics}".'
1027-
log.error(error)
1028-
raise LookupError(error)
1029-
tags = [tag for tag in self.java.physics().tags()]
1030-
ptag = tags[self.physics().index(physics)]
1031-
tags = [tag for tag in self.java.physics(ptag).feature().tags()]
1032-
return [str(self.java.physics(ptag).feature(ftag).label())
1033-
for ftag in tags]
1034-
1035-
def toggle(self, physics: str, feature: str, action: str = 'flip'):
1036-
# Enables or disables features of a physics interface.
1037-
#
1038-
# If `action` is `'flip'` (the default), it enables the feature
1039-
# if it is currently disabled or disables it if enabled. Pass
1040-
# `'enable'` or `'on'` to enable the feature regardless of its
1041-
# current state. Pass `'disable'` or `'off'` to disable it.
1042-
warn('Model.toggle() is deprecated. Use the Node class instead.')
1043-
if physics not in self.physics():
1044-
error = f'No physics interface named "{physics}".'
1045-
log.error(error)
1046-
raise LookupError(error)
1047-
tags = [tag for tag in self.java.physics().tags()]
1048-
ptag = tags[self.physics().index(physics)]
1049-
node = self.java.physics(ptag)
1050-
if feature not in self.features(physics):
1051-
error = f'No feature named "{feature}" in physics "{physics}".'
1052-
log.error(error)
1053-
raise LookupError(error)
1054-
tags = [tag for tag in node.feature().tags()]
1055-
ftag = tags[self.features(physics).index(feature)]
1056-
node = node.feature(ftag)
1057-
if action == 'flip':
1058-
node.active(not node.isActive())
1059-
elif action in ('enable', 'on', 'activate'):
1060-
node.active(True)
1061-
elif action in ('disable', 'off', 'deactivate'):
1062-
node.active(False)
1063-
1064-
def load(self, file: Path | str, interpolation: str):
1065-
# Loads data from a file and assigns it to an interpolation function.
1066-
warn('Model.load() is deprecated. Call .import_() instead.')
1067-
for tag in self.java.func().tags():
1068-
if str(self.java.func(tag).label()) == interpolation:
1069-
break
1070-
else:
1071-
error = f'Interpolation function "{interpolation}" does not exist.'
1072-
log.error(error)
1073-
raise LookupError(error)
1074-
file = Path(file)
1075-
log.info(f'Loading external data from file "{file.name}".')
1076-
self.java.func(tag).discardData()
1077-
self.java.func(tag).set('filename', f'{file}')
1078-
self.java.func(tag).importData()
1079-
log.info('Finished loading external data.')

tests/test_model.py

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import models
77
from fixtures import logging_disabled
8-
from fixtures import warnings_disabled
98
from fixtures import setup_logging
109

1110
from numpy.testing import assert_allclose
@@ -424,10 +423,6 @@ def test_parameter():
424423
model.parameter('non-existing')
425424
with raises(RuntimeError):
426425
model.parameter('non-existing', evaluate=True)
427-
with warnings_disabled():
428-
model.parameter('U', '1', 'V')
429-
assert model.parameter('U') == '1 [V]'
430-
model.parameter('U', description='applied voltage')
431426
model.parameter('U', value)
432427
assert model.parameter('U') == value
433428

@@ -730,53 +725,6 @@ def test_problems():
730725
assert not model.problems()
731726

732727

733-
def test_features():
734-
with warnings_disabled():
735-
assert 'Laplace equation' in model.features('electrostatic')
736-
assert 'zero charge' in model.features('electrostatic')
737-
assert 'initial values' in model.features('electrostatic')
738-
assert 'anode' in model.features('electrostatic')
739-
assert 'cathode' in model.features('electrostatic')
740-
with logging_disabled(), raises(LookupError):
741-
model.features('non-existing')
742-
743-
744-
def test_toggle():
745-
with warnings_disabled():
746-
model.solve('static')
747-
assert abs(model.evaluate('V_es').mean()) < 0.1
748-
model.toggle('electrostatic', 'cathode')
749-
model.solve('static')
750-
assert abs(model.evaluate('V_es').mean() - 0.5) < 0.1
751-
model.toggle('electrostatic', 'cathode', 'on')
752-
model.solve('static')
753-
assert abs(model.evaluate('V_es').mean()) < 0.1
754-
model.toggle('electrostatic', 'cathode', 'off')
755-
model.solve('static')
756-
assert abs(model.evaluate('V_es').mean() - 0.5) < 0.1
757-
with logging_disabled():
758-
with raises(LookupError):
759-
model.toggle('non-existing', 'feature')
760-
with raises(LookupError):
761-
model.toggle('electrostatic', 'non-existing')
762-
763-
764-
def test_load():
765-
with warnings_disabled():
766-
image = model.create('functions/image', 'Image')
767-
image.property('funcname', 'im')
768-
image.property('fununit', '1/m^2')
769-
image.property('xmin', -5)
770-
image.property('xmax', +5)
771-
image.property('ymin', -5)
772-
image.property('ymax', +5)
773-
image.property('extrap', 'value')
774-
model.load('gaussian.tif', 'image')
775-
model.remove('functions/image')
776-
with logging_disabled(), raises(LookupError):
777-
model.load('image.png', 'non-existing')
778-
779-
780728
if __name__ == '__main__':
781729
setup_logging()
782730
setup_module()
@@ -833,9 +781,5 @@ def test_load():
833781

834782
test_problems()
835783

836-
test_features()
837-
test_toggle()
838-
test_load()
839-
840784
finally:
841785
teardown_module()

0 commit comments

Comments
 (0)