Skip to content

Commit

Permalink
Rewrites if len(..) == 0 into if .. (#48)
Browse files Browse the repository at this point in the history
* Rewrites if len(..) == 0 into if ..

* fix wrong change
  • Loading branch information
xadupre committed Nov 13, 2023
1 parent 572e0de commit 2d2f0a6
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 19 deletions.
2 changes: 1 addition & 1 deletion _unittests/ut_graph/test_graph_distance.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def test_unittest_GraphDistance2(self):
if distance is None:
raise TypeError("expecting something different from None")
allPaths = list(graph.enumerate_all_paths(True))
if len(allPaths) == 0:
if not allPaths:
raise ValueError("the number of paths should not be null")
if distance == 0:
raise ValueError("expecting a distance > 0")
Expand Down
2 changes: 1 addition & 1 deletion mlstatpy/garden/poulet.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def local_proba_poisson_melange(params, coef, i):
à la loi de paramètre ``params[i]``
:return: valeur
"""
if len(proba_poisson_melange_tableau) == 0:
if not proba_poisson_melange_tableau:
proba_poisson_melange_tableau.extend(
histogramme_poisson_melange(params, coef)
)
Expand Down
12 changes: 6 additions & 6 deletions mlstatpy/graph/graph_distance.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def load_from_file(filename, add_loop):
elif ve:
g = ve.groups()
vertex_label[g[0]] = g[1]
if len(vertex_label) == 0 or len(edge_list) == 0:
if not vertex_label or not edge_list:
raise OSError(f"Unable to parse file {filename!r}.") # pragma: no cover
return GraphDistance(edge_list, vertex_label, add_loop)

Expand Down Expand Up @@ -510,7 +510,7 @@ def common_paths(
add = {}
for k, v in g.vertices.items():
v1, v2 = v.pair
if len(v.succE) == 0:
if not v.succE:
for e1 in v1.succE:
for e2 in v2.succE:
oe1 = self.edges[e1]
Expand Down Expand Up @@ -599,17 +599,17 @@ def clean_dead_ends(self):
def enumerate_all_paths(self, edges_and_vertices, begin=None):
if begin is None:
begin = []
if len(self.vertices) > 0 and len(self.edges) > 0:
if self.vertices and self.edges:
if edges_and_vertices:
last = begin[-1] if len(begin) > 0 else self.vertices[self.labelBegin]
last = begin[-1] if begin else self.vertices[self.labelBegin]
else:
last = (
self.vertices[begin[-1].to]
if len(begin) > 0
if begin
else self.vertices[self.labelBegin]
)

if edges_and_vertices and len(begin) == 0:
if edges_and_vertices and not begin:
begin = [last]

for ef in last.succE:
Expand Down
2 changes: 1 addition & 1 deletion mlstatpy/graph/graphviz_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def run_graphviz(filename, image, engine="dot"):
else:
cmd = f'"{engine}" -Tpng "{filename}" -o "{image}"'
out, err = run_cmd(cmd, wait=True)
if len(err) > 0:
if err:
raise RuntimeError(
f"Unable to run Graphviz\nCMD:\n{cmd}\nOUT:\n{out}\nERR:\n{err}"
)
Expand Down
15 changes: 8 additions & 7 deletions mlstatpy/ml/neural_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,11 @@ def copy(self):
def _update_members(self, node=None, attr=None):
"Updates internal members."
if node is None or attr is None:
if len(self.nodes_attr) == 0:
self.size_ = self.dim
else:
self.size_ = max(d["output"] for d in self.nodes_attr) + 1
self.size_ = (
self.dim
if not self.nodes_attr
else (max(d["output"] for d in self.nodes_attr) + 1)
)
self.output_to_node_ = {}
self.input_to_node_ = {}
for node2, attr2 in zip(self.nodes, self.nodes_attr):
Expand Down Expand Up @@ -150,7 +151,7 @@ def append(self, node, inputs):
self.nodes.append(node)
first_coef = (
0
if len(self.nodes_attr) == 0
if not self.nodes_attr
else self.nodes_attr[-1]["first_coef"]
+ self.nodes_attr[-1]["coef_size"]
)
Expand All @@ -173,7 +174,7 @@ def append(self, node, inputs):
self.nodes.append(node)
first_coef = (
0
if len(self.nodes_attr) == 0
if not self.nodes_attr
else self.nodes_attr[-1]["first_coef"]
+ self.nodes_attr[-1]["coef_size"]
)
Expand Down Expand Up @@ -702,7 +703,7 @@ def gradient_backward(self, graddx, X, inputs=False, cache=None):

whole_gradx = numpy.zeros(pred.shape, dtype=numpy.float64)
whole_gradw = numpy.zeros(shape, dtype=numpy.float64)
if len(graddx.shape) == 0:
if not graddx.shape:
whole_gradx[-1] = graddx
else:
whole_gradx[-graddx.shape[0] :] = graddx
Expand Down
2 changes: 1 addition & 1 deletion mlstatpy/nlp/completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def find(self, prefix: str) -> "CompletionTrieNode":
:param prefix: prefix
:return: node or None for no result
"""
if len(prefix) == 0:
if not prefix:
if not self.value:
return self
else:
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
requirements = f.read().strip(" \n\r\t").split("\n")
except FileNotFoundError:
requirements = []
if len(requirements) == 0 or requirements == [""]:
if not requirements or requirements == [""]:
requirements = ["numpy", "mlinsight", "onnxruntime", "skl2onnx"]

try:
Expand All @@ -34,7 +34,7 @@
for _ in [_.strip("\r\n ") for _ in f.readlines()]
if _.startswith("__version__")
]
if len(line) > 0:
if line:
version_str = line[0].split("=")[1].strip('" ')

# see https://pypi.org/classifiers/
Expand Down

0 comments on commit 2d2f0a6

Please sign in to comment.