Skip to content

Commit 73160a0

Browse files
committed
Fix failing tests and matplotlib issue
1 parent 43180f0 commit 73160a0

4 files changed

Lines changed: 30 additions & 19 deletions

File tree

‎.github/workflows/tests.yml‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,12 @@ jobs:
6262
- name: Install GADMA and its dependencies.
6363
run: |
6464
pip install .
65-
66-
- name: Use old matplotlib for tests to enable moments pictures.
67-
run: |
68-
conda install "matplotlib<3.5"
6965
7066
- name: Check installations of packages.
7167
run: |
7268
python -c "import numpy"
7369
python -c "import scipy"
70+
python -c "import matplotlib.pyplot"
7471
python -c "import dadi"
7572
python -c "import moments"
7673
python -c "import gadma"

‎gadma/cli/settings_storage.py‎

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import ruamel.yaml
3+
from ruamel.yaml import YAML
34
import numpy as np
45
from . import settings
56
from . import citations
@@ -1041,12 +1042,10 @@ def update_from_file(self, param_file, extra_param_file=None):
10411042
loaded_dict = {}
10421043
if param_file is not None:
10431044
with open(param_file, encoding="utf-8") as fl:
1044-
loaded_dict = ruamel.yaml.load(fl,
1045-
ruamel.yaml.RoundTripLoader)
1045+
loaded_dict = YAML(typ="rt").load(fl)
10461046
if extra_param_file is not None:
10471047
with open(extra_param_file, encoding="utf-8") as fl:
1048-
extra_dict = ruamel.yaml.load(fl,
1049-
ruamel.yaml.RoundTripLoader)
1048+
extra_dict = YAML(typ="rt").load(fl)
10501049
loaded_dict = {**loaded_dict, **extra_dict}
10511050

10521051
for key in loaded_dict:
@@ -1108,8 +1107,7 @@ def to_files(self, params_file, extra_params_file):
11081107
[PARAM_TEMPLATE, EXTRA_PARAM_TEMPLATE]):
11091108
with open(template, encoding="utf-8") as fl:
11101109
readed_template = fl.read()
1111-
loaded_template = ruamel.yaml.load(readed_template,
1112-
ruamel.yaml.RoundTripLoader)
1110+
loaded_template = YAML(typ="rt").load(readed_template)
11131111
for key_name in loaded_template:
11141112
attr_name = key_name.lower()
11151113
attr_name = attr_name.replace("' ", '_')
@@ -1146,14 +1144,14 @@ def my_represent_bool(self, data):
11461144
else:
11471145
value = u'False'
11481146
return self.represent_scalar(u'tag:yaml.org,2002:bool', value)
1149-
ruamel.yaml.RoundTripRepresenter.add_representer(type(None),
1150-
my_represent_none)
1151-
ruamel.yaml.RoundTripRepresenter.add_representer(bool,
1152-
my_represent_bool)
1147+
yaml_rt = YAML(typ="rt")
1148+
yaml_rt.default_flow_style = True
1149+
yaml_rt.width = 4096 # do not wrap long values (e.g. paths)
1150+
yaml_rt.representer.add_representer(type(None),
1151+
my_represent_none)
1152+
yaml_rt.representer.add_representer(bool, my_represent_bool)
11531153
with open(filename, 'w', encoding="utf-8") as fl:
1154-
ruamel.yaml.dump(loaded_template, fl,
1155-
default_flow_style=True,
1156-
Dumper=ruamel.yaml.RoundTripDumper)
1154+
yaml_rt.dump(loaded_template, fl)
11571155
# save missed attributes at the end of extra file
11581156
final_dict = dict()
11591157
with open(extra_params_file, 'a', encoding="utf-8") as fl:
@@ -1171,7 +1169,13 @@ def my_represent_bool(self, data):
11711169
if isinstance(value, np.ndarray):
11721170
value = value.tolist()
11731171
final_dict[attr_name] = value
1174-
fl.write(ruamel.yaml.dump(final_dict, default_flow_style=False))
1172+
try:
1173+
# ruamel.yaml >= 0.18
1174+
yaml_py = YAML(typ="full", pure=True)
1175+
except NotImplementedError:
1176+
yaml_py = YAML(typ="unsafe", pure=True)
1177+
yaml_py.default_flow_style = False
1178+
yaml_py.dump(final_dict, fl)
11751179

11761180
def get_global_optimizer(self):
11771181
"""

‎gadma/core/draw_and_generate_code.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def draw_plots_to_file(x, engine, settings, filename, fig_title):
9797
settings=settings,
9898
)
9999
warnings.filterwarnings(
100-
'ignore', category=matplotlib.cbook.MatplotlibDeprecationWarning)
100+
'ignore', category=matplotlib.MatplotlibDeprecationWarning)
101101

102102
# 0. Get place of dot in filename - where file extention starts
103103
pos = filename.rfind('.')

‎gadma/engines/moments_engine.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,16 @@ def draw_schematic_model_plot(self, values, save_file=None,
200200

201201
# We will create figure to have more control and to return it
202202
fig, ax = plt.subplots(figsize=(6.72, 3.36))
203+
# moments.ModelPlot calls ax.grid(b=...); newer matplotlib has
204+
# renamed that argument to `visible` and no longer accepts `b`
205+
_ax_grid = ax.grid
206+
207+
def _grid_compat(*args, b=None, **kwargs):
208+
if b is not None and not args:
209+
# first positional argument in every matplotlib version
210+
args = (b,)
211+
return _ax_grid(*args, **kwargs)
212+
ax.grid = _grid_compat
203213

204214
if self.data_holder is not None:
205215
if (self.data_holder.projections is not None

0 commit comments

Comments
 (0)