Skip to content

Commit 446a3b9

Browse files
Fix the data set dimensions for the sdvplot. (#1130)
* Fix the data set dimensions for the sdvplot. This closes #1129. I could not find anything in the release notes <http://matplotlib.org/users/whats_new.html> however I think this is due to the fact that mpl 2.1 got rid of the availability to handle the unflatten sub list (so this fix will still work with previous versions of mpl). * Fix tqdm to be compatible with new release. * Add type annotation needed for latest mypy. * Pinning hypothesis. This version seems to cover all our needs and is still ensuring coverage. As hypothesis seems to be developing/changing this just makes things easier for us. * Clarify iteration variables. * Add an extra space for PEP8.
1 parent 7bd9c95 commit 446a3b9

File tree

5 files changed

+21
-8
lines changed

5 files changed

+21
-8
lines changed

axelrod/plot.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ def _sd_ordering(self):
112112
@property
113113
def _sdv_plot_dataset(self):
114114
ordering = self._sd_ordering
115-
diffs = self.result_set.score_diffs
115+
diffs = [[score_diff for opponent in player for score_diff in opponent]
116+
for player in self.result_set.score_diffs]
116117
# Reorder and grab names
117118
diffs = [diffs[i] for i in ordering]
118119
ranked_names = [str(self.players[i]) for i in ordering]

axelrod/tests/unit/test_plot.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ def setUpClass(cls):
7070
[[2, 2, 2], [0, 0, 0], [0, 0, 0]],
7171
['Defector', 'Tit For Tat', 'Alternator'])
7272

73+
cls.expected_sdvplot_dataset = (
74+
[[3, 3, 3, 1, 1, 1, 0, 0, 0],
75+
[0, 0, 0, 0, 0, 0, -1, -1, -1],
76+
[0, 0, 0, 0, 0, 0, -3, -3, -3]],
77+
['Defector', 'Tit For Tat', 'Alternator'])
78+
7379
def test_default_cmap(self):
7480
cmap = axelrod.plot.default_cmap('0.0')
7581
self.assertEqual(cmap, 'YlGnBu')
@@ -173,6 +179,12 @@ def test_winplot(self):
173179
self.assertIsInstance(fig, matplotlib.pyplot.Figure)
174180
plt.close(fig)
175181

182+
def test_sdvplot_dataset(self):
183+
plot = axelrod.Plot(self.test_result_set)
184+
self.assertSequenceEqual(
185+
plot._sdv_plot_dataset,
186+
self.expected_sdvplot_dataset)
187+
176188
def test_sdvplot(self):
177189
plot = axelrod.Plot(self.test_result_set)
178190
fig = plot.sdvplot()

axelrod/tests/unit/test_tournament.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ def test_get_progress_bar(self):
251251
self.test_tournament.use_progress_bar = True
252252
pbar = self.test_tournament._get_progress_bar()
253253
self.assertIsInstance(pbar, tqdm)
254-
self.assertEqual(pbar.desc, 'Playing matches: ')
254+
self.assertEqual(pbar.desc, 'Playing matches')
255255
self.assertEqual(pbar.n, 0)
256256
self.assertEqual(pbar.total, self.test_tournament.match_generator.size)
257257

@@ -260,7 +260,7 @@ def test_get_progress_bar(self):
260260
edges=new_edges)
261261
new_tournament.use_progress_bar = True
262262
pbar = new_tournament._get_progress_bar()
263-
self.assertEqual(pbar.desc, 'Playing matches: ')
263+
self.assertEqual(pbar.desc, 'Playing matches')
264264
self.assertEqual(pbar.n, 0)
265265
self.assertEqual(pbar.total, len(new_edges))
266266

@@ -327,7 +327,7 @@ def test_no_progress_bar_play(self):
327327
self.assertIsInstance(results, axelrod.ResultSet)
328328

329329
def assert_play_pbar_correct_total_and_finished(self, pbar, total):
330-
self.assertEqual(pbar.desc, 'Playing matches: ')
330+
self.assertEqual(pbar.desc, 'Playing matches')
331331
self.assertEqual(pbar.total, total)
332332
self.assertEqual(pbar.n, total)
333333
self.assertTrue(pbar.disable, True)

axelrod/tournament.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,8 @@ def _run_parallel(self, processes: int=2) -> bool:
255255
"""
256256
# At first sight, it might seem simpler to use the multiprocessing Pool
257257
# Class rather than Processes and Queues. However, this way is faster.
258-
work_queue = Queue()
259-
done_queue = Queue()
258+
work_queue = Queue() # type: Queue
259+
done_queue = Queue() # type: Queue
260260
workers = self._n_workers(processes=processes)
261261

262262
chunks = self.match_generator.build_match_chunks()

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
numpy>=1.9.2
22
matplotlib>=1.4.2
3-
hypothesis>=3.2
43
tqdm>=3.4.0
54
prompt-toolkit>=1.0.7
6-
scipy>=0.19.0
5+
scipy>=0.19.0
6+
hypothesis==3.2

0 commit comments

Comments
 (0)