Skip to content

Commit 0fb793f

Browse files
author
Release Manager
committed
sagemathgh-37410: minor fixes in sandpiles
Just fixing a few `ruff` warnings in the two modified files, plus some `pep8` code formatting. Also a few code simplifications on the way. I also changed some errors from `UserWarning` to better ones. and changed one function, used nowhere inside sage, into an iterator ### 📝 Checklist - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. URL: sagemath#37410 Reported by: Frédéric Chapoton Reviewer(s): Matthias Köppe
2 parents 57d4e09 + 73b17c3 commit 0fb793f

File tree

4 files changed

+98
-119
lines changed

4 files changed

+98
-119
lines changed

build/pkgs/configure/checksums.ini

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
tarball=configure-VERSION.tar.gz
2-
sha1=0c93ffbc40ee55c429b82c6070817c0133a05013
3-
md5=96e8d0c3aa48cab18b60499c4d303a73
4-
cksum=2523075193
2+
sha1=cebcfe9542c5aa28fd27329786ec7ceb53c4b18b
3+
md5=83b5e5a5ad023e6266626dfde92f5969
4+
cksum=383438152
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
81a374dc4dacba71cf071f981d496ff63b2b2acb
1+
f531179bcd7b18e31291000415f0d076538a0802

src/sage/sandpiles/examples.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
from sage.sandpiles.sandpile import Sandpile
2626
from sage.graphs.graph_generators import graphs
2727

28-
class SandpileExamples():
28+
29+
class SandpileExamples:
2930
"""
3031
Some examples of sandpiles.
3132
@@ -92,7 +93,7 @@ def Complete(self, n):
9293
sage: sandpiles.Complete(3) == sandpiles.Cycle(3)
9394
True
9495
"""
95-
return Sandpile(graphs.CompleteGraph(n),0)
96+
return Sandpile(graphs.CompleteGraph(n), 0)
9697

9798
def Cycle(self, n):
9899
"""
@@ -119,7 +120,7 @@ def Cycle(self, n):
119120
(3, 0, 1),
120121
(3, 2, 1)]
121122
"""
122-
return Sandpile(graphs.CycleGraph(n),0)
123+
return Sandpile(graphs.CycleGraph(n), 0)
123124

124125
def Diamond(self):
125126
"""
@@ -164,18 +165,18 @@ def Fan(self, n, deg_three_verts=False):
164165
"""
165166
f = graphs.WheelGraph(n)
166167
if n > 2:
167-
f.delete_edge(1,n-1)
168+
f.delete_edge(1, n-1)
168169
if deg_three_verts:
169170
f.allow_multiple_edges(True)
170-
f.add_edges([(0,1),(0,n-1)])
171-
return Sandpile(f,0)
171+
f.add_edges([(0, 1), (0, n-1)])
172+
return Sandpile(f, 0)
172173
elif n == 1:
173-
return Sandpile(f,0)
174+
return Sandpile(f, 0)
174175
elif n == 2:
175176
if deg_three_verts:
176-
return Sandpile({0:{1:3}, 1:{0:3}})
177+
return Sandpile({0: {1: 3}, 1: {0: 3}})
177178
else:
178-
return Sandpile(f,0)
179+
return Sandpile(f, 0)
179180

180181
def Grid(self, m, n):
181182
"""
@@ -200,11 +201,12 @@ def Grid(self, m, n):
200201
sage: s.dict()
201202
{(0, 0): {(1, 1): 4}, (1, 1): {(0, 0): 4}}
202203
"""
203-
G = graphs.Grid2dGraph(m+2,n+2)
204+
G = graphs.Grid2dGraph(m+2, n+2)
204205
G.allow_multiple_edges(True) # to ensure each vertex ends up with degree 4
205-
V = [(i,j) for i in [0,m+1] for j in range(n+2)] + [(i,j) for j in [0,n+1] for i in range(m+2)]
206+
V = [(i, j) for i in [0, m+1] for j in range(n+2)]
207+
V += [(i, j) for j in [0, n+1] for i in range(m+2)]
206208
G.merge_vertices(V)
207-
return Sandpile(G, (0,0))
209+
return Sandpile(G, (0, 0))
208210

209211
def House(self):
210212
"""
@@ -224,7 +226,7 @@ def House(self):
224226
sage: s.invariant_factors()
225227
[1, 1, 1, 11]
226228
"""
227-
return Sandpile(graphs.HouseGraph(),0)
229+
return Sandpile(graphs.HouseGraph(), 0)
228230

229231
def Wheel(self, n):
230232
"""
@@ -244,7 +246,7 @@ def Wheel(self, n):
244246
sage: w.invariant_factors()
245247
[1, 1, 1, 11, 11]
246248
"""
247-
return Sandpile(graphs.WheelGraph(n),0)
249+
return Sandpile(graphs.WheelGraph(n), 0)
248250

249251

250252
sandpiles = SandpileExamples()

0 commit comments

Comments
 (0)