Skip to content

Commit 2ba5c52

Browse files
authored
Merge pull request #183 from PEtab-dev/release_0.1.30
Release 0.1.30
2 parents ff1bdde + 23bc37a commit 2ba5c52

File tree

14 files changed

+260
-112
lines changed

14 files changed

+260
-112
lines changed

.ci_pip_reqs.txt

Lines changed: 0 additions & 11 deletions
This file was deleted.

.github/workflows/ci_tests.yml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,14 @@ jobs:
3939
- name: Install dependencies
4040
run: |
4141
python -m pip install --upgrade pip wheel
42-
pip install -r .ci_pip_reqs.txt
43-
pip install .[reports,combine,tests]
42+
pip install -r requirements-dev.txt
4443
45-
- name: Run flake8
46-
run: |
47-
python -m flake8
44+
- name: Quality tests
45+
run: tox -e quality
4846
if: matrix.platform == 'ubuntu-latest'
4947

50-
- name: Run tests
51-
run: |
52-
pytest --cov --cov-report=xml tests
48+
- name: Unit tests
49+
run: tox -e unit
5350

5451
- name: Coverage
5552
uses: codecov/codecov-action@v1

CHANGELOG.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,32 @@
22

33
## 0.1 series
44

5+
### 0.1.30
6+
7+
Various smaller fixes:
8+
9+
* Vis: Handle missing data more gracefully by @dweindl
10+
in https://github.com/PEtab-dev/libpetab-python/pull/175
11+
* Fix test dependencies: scipy by @dweindl
12+
in https://github.com/PEtab-dev/libpetab-python/pull/177
13+
* Add `petab.Problem.__str__` by @dweindl
14+
in https://github.com/PEtab-dev/libpetab-python/pull/178
15+
* Fix deprecated tight layout matplotlib by @yannikschaelte
16+
in https://github.com/PEtab-dev/libpetab-python/pull/180
17+
* Move tests to tox by @yannikschaelte
18+
in https://github.com/PEtab-dev/libpetab-python/pull/182
19+
* Update deprecated functions in tests by @yannikschaelte
20+
in https://github.com/PEtab-dev/libpetab-python/pull/181
21+
* Use petab identifier for combine archives by @fbergmann
22+
in https://github.com/PEtab-dev/libpetab-python/pull/179
23+
24+
New Contributors
25+
* @fbergmann made their first contribution
26+
in https://github.com/PEtab-dev/libpetab-python/pull/179
27+
28+
**Full Changelog**:
29+
https://github.com/PEtab-dev/libpetab-python/compare/v0.1.29...v0.1.30
30+
531
### 0.1.29
632

733
Features:

petab/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ def _add_file_metadata(location: str, description: str = ""):
396396
archive.addFile(
397397
str(yaml_file),
398398
os.path.basename(yaml_file),
399-
libcombine.KnownFormats.lookupFormat("yaml"),
399+
"http://identifiers.org/combine.specifications/petab.version-1",
400400
True
401401
)
402402
_add_file_metadata(location=os.path.basename(yaml_file),

petab/problem.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,31 @@ def __setattr__(self, name, value):
104104
else:
105105
super().__setattr__(name, value)
106106

107+
def __str__(self):
108+
model = f"with model ({self.model})" if self.model else "without model"
109+
conditions = f"{self.condition_df.shape[0]} conditions" \
110+
if self.condition_df is not None else "without conditions table"
111+
112+
observables = f"{self.observable_df.shape[0]} observables" \
113+
if self.observable_df is not None else "without observables table"
114+
115+
measurements = f"{self.measurement_df.shape[0]} measurements" \
116+
if self.measurement_df is not None \
117+
else "without measurements table"
118+
119+
if self.parameter_df is not None:
120+
num_estimated_parameters = sum(self.parameter_df[ESTIMATE] == 1) \
121+
if ESTIMATE in self.parameter_df \
122+
else self.parameter_df.shape[0]
123+
parameters = f"{num_estimated_parameters} estimated parameters"
124+
else:
125+
parameters = "without parameter_df table"
126+
127+
return (
128+
f"PEtab Problem {model}, {conditions}, {observables}, "
129+
f"{measurements}, {parameters}"
130+
)
131+
107132
@staticmethod
108133
def from_files(
109134
sbml_file: Union[str, Path] = None,
@@ -386,7 +411,7 @@ def to_files(
386411
visualization tables, they will be merged and written to a single file.
387412
388413
Arguments:
389-
sbml_file: SBML model destination
414+
sbml_file: SBML model destination (deprecated)
390415
model_file: Model destination
391416
condition_file: Condition table destination
392417
measurement_file: Measurement table destination

petab/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
"""PEtab library version"""
2-
__version__ = '0.1.29'
2+
__version__ = '0.1.30'

petab/visualize/plotter.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ def generate_lineplot(
9595

9696
label_base = dataplot.legendEntry
9797

98-
if measurements_to_plot is not None:
98+
if measurements_to_plot is not None \
99+
and not measurements_to_plot.data_to_plot.empty:
99100
# plotting all measurement data
100101

101102
if plotTypeData == REPLICATE:
@@ -361,7 +362,7 @@ def generate_figure(
361362

362363
fig, axes = plt.subplots(num_row, num_col, squeeze=False,
363364
figsize=self.figure.size)
364-
fig.set_tight_layout(True)
365+
fig.set_layout_engine("tight")
365366

366367
for ax in axes.flat[self.figure.num_subplots:]:
367368
ax.remove()
@@ -372,11 +373,15 @@ def generate_figure(
372373
for subplot in self.figure.subplots:
373374
if subplot_dir is not None:
374375
fig, ax = plt.subplots(figsize=self.figure.size)
375-
fig.set_tight_layout(True)
376+
fig.set_layout_engine("tight")
376377
else:
377378
ax = axes[subplot.plotId]
378379

379-
self.generate_subplot(ax, subplot)
380+
try:
381+
self.generate_subplot(ax, subplot)
382+
except Exception as e:
383+
raise RuntimeError(
384+
f"Error plotting {getattr(subplot, PLOT_ID)}.") from e
380385

381386
if subplot_dir is not None:
382387
# TODO: why this doesn't work?

requirements-dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tox >= 3.26.0

setup.py

Lines changed: 64 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ def read(fname):
1212
def absolute_links(txt):
1313
"""Replace relative petab github links by absolute links."""
1414

15-
raw_base = "(https://raw.githubusercontent.com/"\
16-
"petab-dev/libpetab-python/master/"
17-
embedded_base = "(https://github.com/petab-dev/libpetab-python/"\
18-
"tree/master/"
15+
raw_base = \
16+
"(https://raw.githubusercontent.com/petab-dev/libpetab-python/master/"
17+
embedded_base = \
18+
"(https://github.com/petab-dev/libpetab-python/tree/master/"
1919
# iterate over links
20-
for var in re.findall(r'\[.*?\]\((?!http).*?\)', txt):
21-
if re.match(r'.*?.(png|svg)\)', var):
20+
for var in re.findall(r"\[.*?\]\((?!http).*?\)", txt):
21+
if re.match(r".*?.(png|svg)\)", var):
2222
# link to raw file
2323
rep = var.replace("(", raw_base)
2424
else:
@@ -30,62 +30,72 @@ def absolute_links(txt):
3030

3131
# Python version check. We need >= 3.6 due to e.g. f-strings
3232
if sys.version_info < (3, 8, 0):
33-
sys.exit('PEtab requires at least Python version 3.8')
33+
sys.exit("PEtab requires at least Python version 3.8")
3434

3535
# read version from file
36-
__version__ = ''
37-
version_file = os.path.join('petab', 'version.py')
36+
__version__ = ""
37+
version_file = os.path.join("petab", "version.py")
3838
# sets __version__
3939
exec(read(version_file)) # pylint: disable=W0122 # nosec
4040

4141
ENTRY_POINTS = {
42-
'console_scripts': [
43-
'petablint = petab.petablint:main',
44-
'petab_visualize = petab.visualize.cli:_petab_visualize_main',
42+
"console_scripts": [
43+
"petablint = petab.petablint:main",
44+
"petab_visualize = petab.visualize.cli:_petab_visualize_main",
4545
]
4646
}
4747

4848
# project metadata
4949
# noinspection PyUnresolvedReferences
50-
setup(name='petab',
51-
version=__version__,
52-
description='Parameter estimation tabular data',
53-
long_description=absolute_links(read('README.md')),
54-
long_description_content_type="text/markdown",
55-
author='The PEtab developers',
56-
author_email='[email protected]',
57-
url='https://github.com/PEtab-dev/libpetab-python',
58-
packages=find_packages(exclude=['doc*', 'test*']),
59-
install_requires=['numpy>=1.15.1',
60-
'pandas>=1.2.0',
61-
'matplotlib>=3.5.0',
62-
'python-libsbml>=5.17.0',
63-
'sympy',
64-
'colorama',
65-
'seaborn',
66-
'pyyaml',
67-
'jsonschema',
68-
],
69-
include_package_data=True,
70-
python_requires='>=3.8.0',
71-
entry_points=ENTRY_POINTS,
72-
extras_require={
73-
'tests': [
74-
'flake8',
75-
'pytest',
76-
'python-libcombine',
77-
'simplesbml'
78-
],
79-
'reports': ['Jinja2'],
80-
'combine': ['python-libcombine>=0.2.6'],
81-
'doc': [
82-
'sphinx>=3.5.3, !=5.1.0',
83-
'sphinxcontrib-napoleon>=0.7',
84-
'sphinx-markdown-tables>=0.0.15',
85-
'sphinx-rtd-theme>=0.5.1',
86-
'm2r2',
87-
'myst-nb>=0.14.0',
88-
'ipython>=7.21.0',
89-
]
90-
}
91-
)
50+
setup(
51+
name="petab",
52+
version=__version__,
53+
description="Parameter estimation tabular data",
54+
long_description=absolute_links(read("README.md")),
55+
long_description_content_type="text/markdown",
56+
author="The PEtab developers",
57+
author_email="[email protected]",
58+
url="https://github.com/PEtab-dev/libpetab-python",
59+
packages=find_packages(exclude=["doc*", "test*"]),
60+
install_requires=[
61+
"numpy>=1.15.1",
62+
"pandas>=1.2.0",
63+
"matplotlib>=3.6.0",
64+
"python-libsbml>=5.17.0",
65+
"sympy",
66+
"colorama",
67+
"seaborn",
68+
"pyyaml",
69+
"jsonschema",
70+
],
71+
include_package_data=True,
72+
python_requires=">=3.8.0",
73+
entry_points=ENTRY_POINTS,
74+
extras_require={
75+
"tests": [
76+
"pytest",
77+
"pytest-cov",
78+
"simplesbml",
79+
"scipy",
80+
],
81+
"quality": [
82+
"flake8>=3.8.3",
83+
],
84+
"reports": [
85+
# https://github.com/spatialaudio/nbsphinx/issues/641
86+
"Jinja2==3.0.3",
87+
],
88+
"combine": [
89+
"python-libcombine>=0.2.6",
90+
],
91+
"doc": [
92+
"sphinx>=3.5.3, !=5.1.0",
93+
"sphinxcontrib-napoleon>=0.7",
94+
"sphinx-markdown-tables>=0.0.15",
95+
"sphinx-rtd-theme>=0.5.1",
96+
"m2r2",
97+
"myst-nb>=0.14.0",
98+
"ipython>=7.21.0",
99+
],
100+
},
101+
)

tests/test_deprecated.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
"""Check that deprecated functionality raises but still works."""
2+
import pytest
3+
import tempfile
4+
from pathlib import Path
5+
6+
import petab
7+
8+
from .test_sbml import create_test_data, check_model
9+
from .test_petab import petab_problem # noqa: F401
10+
11+
12+
def test_problem_with_sbml_model():
13+
"""Test that a problem can be correctly created from sbml model."""
14+
# retrieve test data
15+
ss_model, condition_df, observable_df, measurement_df, parameter_df = \
16+
create_test_data()
17+
18+
with pytest.deprecated_call():
19+
petab_problem = petab.Problem( # noqa: F811
20+
sbml_model=ss_model.model,
21+
condition_df=condition_df,
22+
measurement_df=measurement_df,
23+
parameter_df=parameter_df,
24+
)
25+
26+
_, condition_model = petab.get_model_for_condition(
27+
petab_problem, "condition_1")
28+
29+
check_model(condition_model)
30+
31+
32+
def test_to_files_with_sbml_model(petab_problem): # noqa: F811
33+
"""Test problem.to_files."""
34+
with tempfile.TemporaryDirectory() as outdir:
35+
# create target files
36+
sbml_file = Path(outdir, "model.xml")
37+
condition_file = Path(outdir, "conditions.tsv")
38+
measurement_file = Path(outdir, "measurements.tsv")
39+
parameter_file = Path(outdir, "parameters.tsv")
40+
observable_file = Path(outdir, "observables.tsv")
41+
42+
# write contents to files
43+
with pytest.deprecated_call():
44+
petab_problem.to_files(
45+
sbml_file=sbml_file,
46+
condition_file=condition_file,
47+
measurement_file=measurement_file,
48+
parameter_file=parameter_file,
49+
visualization_file=None,
50+
observable_file=observable_file,
51+
yaml_file=None,
52+
)
53+
54+
# exemplarily load some
55+
parameter_df = petab.get_parameter_df(parameter_file)
56+
same_nans = parameter_df.isna() == petab_problem.parameter_df.isna()
57+
assert ((parameter_df == petab_problem.parameter_df) | same_nans) \
58+
.all().all()

0 commit comments

Comments
 (0)