Skip to content

Commit 2d2f0a6

Browse files
authored
Rewrites if len(..) == 0 into if .. (#48)
* Rewrites if len(..) == 0 into if .. * fix wrong change
1 parent 572e0de commit 2d2f0a6

File tree

7 files changed

+20
-19
lines changed

7 files changed

+20
-19
lines changed

_unittests/ut_graph/test_graph_distance.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def test_unittest_GraphDistance2(self):
129129
if distance is None:
130130
raise TypeError("expecting something different from None")
131131
allPaths = list(graph.enumerate_all_paths(True))
132-
if len(allPaths) == 0:
132+
if not allPaths:
133133
raise ValueError("the number of paths should not be null")
134134
if distance == 0:
135135
raise ValueError("expecting a distance > 0")

mlstatpy/garden/poulet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def local_proba_poisson_melange(params, coef, i):
166166
à la loi de paramètre ``params[i]``
167167
:return: valeur
168168
"""
169-
if len(proba_poisson_melange_tableau) == 0:
169+
if not proba_poisson_melange_tableau:
170170
proba_poisson_melange_tableau.extend(
171171
histogramme_poisson_melange(params, coef)
172172
)

mlstatpy/graph/graph_distance.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ def load_from_file(filename, add_loop):
246246
elif ve:
247247
g = ve.groups()
248248
vertex_label[g[0]] = g[1]
249-
if len(vertex_label) == 0 or len(edge_list) == 0:
249+
if not vertex_label or not edge_list:
250250
raise OSError(f"Unable to parse file {filename!r}.") # pragma: no cover
251251
return GraphDistance(edge_list, vertex_label, add_loop)
252252

@@ -510,7 +510,7 @@ def common_paths(
510510
add = {}
511511
for k, v in g.vertices.items():
512512
v1, v2 = v.pair
513-
if len(v.succE) == 0:
513+
if not v.succE:
514514
for e1 in v1.succE:
515515
for e2 in v2.succE:
516516
oe1 = self.edges[e1]
@@ -599,17 +599,17 @@ def clean_dead_ends(self):
599599
def enumerate_all_paths(self, edges_and_vertices, begin=None):
600600
if begin is None:
601601
begin = []
602-
if len(self.vertices) > 0 and len(self.edges) > 0:
602+
if self.vertices and self.edges:
603603
if edges_and_vertices:
604-
last = begin[-1] if len(begin) > 0 else self.vertices[self.labelBegin]
604+
last = begin[-1] if begin else self.vertices[self.labelBegin]
605605
else:
606606
last = (
607607
self.vertices[begin[-1].to]
608-
if len(begin) > 0
608+
if begin
609609
else self.vertices[self.labelBegin]
610610
)
611611

612-
if edges_and_vertices and len(begin) == 0:
612+
if edges_and_vertices and not begin:
613613
begin = [last]
614614

615615
for ef in last.succE:

mlstatpy/graph/graphviz_helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def run_graphviz(filename, image, engine="dot"):
2424
else:
2525
cmd = f'"{engine}" -Tpng "{filename}" -o "{image}"'
2626
out, err = run_cmd(cmd, wait=True)
27-
if len(err) > 0:
27+
if err:
2828
raise RuntimeError(
2929
f"Unable to run Graphviz\nCMD:\n{cmd}\nOUT:\n{out}\nERR:\n{err}"
3030
)

mlstatpy/ml/neural_tree.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,11 @@ def copy(self):
9595
def _update_members(self, node=None, attr=None):
9696
"Updates internal members."
9797
if node is None or attr is None:
98-
if len(self.nodes_attr) == 0:
99-
self.size_ = self.dim
100-
else:
101-
self.size_ = max(d["output"] for d in self.nodes_attr) + 1
98+
self.size_ = (
99+
self.dim
100+
if not self.nodes_attr
101+
else (max(d["output"] for d in self.nodes_attr) + 1)
102+
)
102103
self.output_to_node_ = {}
103104
self.input_to_node_ = {}
104105
for node2, attr2 in zip(self.nodes, self.nodes_attr):
@@ -150,7 +151,7 @@ def append(self, node, inputs):
150151
self.nodes.append(node)
151152
first_coef = (
152153
0
153-
if len(self.nodes_attr) == 0
154+
if not self.nodes_attr
154155
else self.nodes_attr[-1]["first_coef"]
155156
+ self.nodes_attr[-1]["coef_size"]
156157
)
@@ -173,7 +174,7 @@ def append(self, node, inputs):
173174
self.nodes.append(node)
174175
first_coef = (
175176
0
176-
if len(self.nodes_attr) == 0
177+
if not self.nodes_attr
177178
else self.nodes_attr[-1]["first_coef"]
178179
+ self.nodes_attr[-1]["coef_size"]
179180
)
@@ -702,7 +703,7 @@ def gradient_backward(self, graddx, X, inputs=False, cache=None):
702703

703704
whole_gradx = numpy.zeros(pred.shape, dtype=numpy.float64)
704705
whole_gradw = numpy.zeros(shape, dtype=numpy.float64)
705-
if len(graddx.shape) == 0:
706+
if not graddx.shape:
706707
whole_gradx[-1] = graddx
707708
else:
708709
whole_gradx[-graddx.shape[0] :] = graddx

mlstatpy/nlp/completion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ def find(self, prefix: str) -> "CompletionTrieNode":
267267
:param prefix: prefix
268268
:return: node or None for no result
269269
"""
270-
if len(prefix) == 0:
270+
if not prefix:
271271
if not self.value:
272272
return self
273273
else:

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
requirements = f.read().strip(" \n\r\t").split("\n")
1919
except FileNotFoundError:
2020
requirements = []
21-
if len(requirements) == 0 or requirements == [""]:
21+
if not requirements or requirements == [""]:
2222
requirements = ["numpy", "mlinsight", "onnxruntime", "skl2onnx"]
2323

2424
try:
@@ -34,7 +34,7 @@
3434
for _ in [_.strip("\r\n ") for _ in f.readlines()]
3535
if _.startswith("__version__")
3636
]
37-
if len(line) > 0:
37+
if line:
3838
version_str = line[0].split("=")[1].strip('" ')
3939

4040
# see https://pypi.org/classifiers/

0 commit comments

Comments
 (0)