Skip to content

Commit

Permalink
Merge pull request #17 from pirovc/dev
Browse files Browse the repository at this point in the history
v1.3.1 fix filter root
  • Loading branch information
pirovc authored Apr 26, 2023
2 parents 3d22282 + a390fd0 commit 396e19c
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 39 deletions.
2 changes: 1 addition & 1 deletion docs/multitax.html
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ <h1 class="modulename">

<details>
<summary>View Source</summary>
<div class="pdoc-code codehilite"><pre><span></span><span class="n">__version__</span> <span class="o">=</span> <span class="s2">&quot;1.3.0&quot;</span>
<div class="pdoc-code codehilite"><pre><span></span><span class="n">__version__</span> <span class="o">=</span> <span class="s2">&quot;1.3.1&quot;</span>

<span class="n">__all__</span> <span class="o">=</span> <span class="p">(</span>
<span class="s1">&#39;CustomTx&#39;</span><span class="p">,</span>
Expand Down
23 changes: 4 additions & 19 deletions docs/multitax/multitax.html
Original file line number Diff line number Diff line change
Expand Up @@ -500,10 +500,6 @@ <h1 class="modulename">
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">nodes</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span>
<span class="n">nodes</span> <span class="o">=</span> <span class="p">[</span><span class="n">nodes</span><span class="p">]</span>

<span class="c1"># Cannot filter root node</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">root_node</span> <span class="ow">in</span> <span class="n">nodes</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Root node [&quot;</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">root_node</span> <span class="o">+</span> <span class="s2">&quot;] cannot be filtered.&quot;</span><span class="p">)</span>

<span class="c1"># Keep track of nodes to be filtered out</span>
<span class="n">filtered_nodes</span> <span class="o">=</span> <span class="nb">set</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_nodes</span><span class="p">)</span>
<span class="c1"># Always keep root</span>
Expand All @@ -512,7 +508,7 @@ <h1 class="modulename">
<span class="k">if</span> <span class="n">desc</span><span class="p">:</span>
<span class="c1"># Keep descendants of the given nodes</span>
<span class="k">for</span> <span class="n">node</span> <span class="ow">in</span> <span class="n">nodes</span><span class="p">:</span>
<span class="c1"># Check if node exists</span>
<span class="c1"># Check if node exists (skips root)</span>
<span class="k">if</span> <span class="n">node</span> <span class="ow">in</span> <span class="n">filtered_nodes</span><span class="p">:</span>
<span class="c1"># For each leaf of the selected nodes</span>
<span class="k">for</span> <span class="n">leaf</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">leaves</span><span class="p">(</span><span class="n">node</span><span class="p">):</span>
Expand All @@ -536,7 +532,6 @@ <h1 class="modulename">

<span class="c1"># Delete aux. data structures</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_reset_aux_data</span><span class="p">()</span>

<span class="bp">self</span><span class="o">.</span><span class="n">check_consistency</span><span class="p">()</span>

<span class="k">def</span> <span class="nf">latest</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">node</span><span class="p">:</span> <span class="nb">str</span><span class="p">):</span>
Expand Down Expand Up @@ -1212,10 +1207,6 @@ <h1 class="modulename">
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">nodes</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span>
<span class="n">nodes</span> <span class="o">=</span> <span class="p">[</span><span class="n">nodes</span><span class="p">]</span>

<span class="c1"># Cannot filter root node</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">root_node</span> <span class="ow">in</span> <span class="n">nodes</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Root node [&quot;</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">root_node</span> <span class="o">+</span> <span class="s2">&quot;] cannot be filtered.&quot;</span><span class="p">)</span>

<span class="c1"># Keep track of nodes to be filtered out</span>
<span class="n">filtered_nodes</span> <span class="o">=</span> <span class="nb">set</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_nodes</span><span class="p">)</span>
<span class="c1"># Always keep root</span>
Expand All @@ -1224,7 +1215,7 @@ <h1 class="modulename">
<span class="k">if</span> <span class="n">desc</span><span class="p">:</span>
<span class="c1"># Keep descendants of the given nodes</span>
<span class="k">for</span> <span class="n">node</span> <span class="ow">in</span> <span class="n">nodes</span><span class="p">:</span>
<span class="c1"># Check if node exists</span>
<span class="c1"># Check if node exists (skips root)</span>
<span class="k">if</span> <span class="n">node</span> <span class="ow">in</span> <span class="n">filtered_nodes</span><span class="p">:</span>
<span class="c1"># For each leaf of the selected nodes</span>
<span class="k">for</span> <span class="n">leaf</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">leaves</span><span class="p">(</span><span class="n">node</span><span class="p">):</span>
Expand All @@ -1248,7 +1239,6 @@ <h1 class="modulename">

<span class="c1"># Delete aux. data structures</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_reset_aux_data</span><span class="p">()</span>

<span class="bp">self</span><span class="o">.</span><span class="n">check_consistency</span><span class="p">()</span>

<span class="k">def</span> <span class="nf">latest</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">node</span><span class="p">:</span> <span class="nb">str</span><span class="p">):</span>
Expand Down Expand Up @@ -1715,7 +1705,7 @@ <h1 class="modulename">
<div id="MultiTax.version" class="classattr">
<div class="attr variable"><a class="headerlink" href="#MultiTax.version">#&nbsp;&nbsp</a>

<span class="name">version</span><span class="default_value"> = &#39;1.3.0&#39;</span>
<span class="name">version</span><span class="default_value"> = &#39;1.3.1&#39;</span>
</div>


Expand Down Expand Up @@ -2041,10 +2031,6 @@ <h1 class="modulename">
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">nodes</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span>
<span class="n">nodes</span> <span class="o">=</span> <span class="p">[</span><span class="n">nodes</span><span class="p">]</span>

<span class="c1"># Cannot filter root node</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">root_node</span> <span class="ow">in</span> <span class="n">nodes</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Root node [&quot;</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">root_node</span> <span class="o">+</span> <span class="s2">&quot;] cannot be filtered.&quot;</span><span class="p">)</span>

<span class="c1"># Keep track of nodes to be filtered out</span>
<span class="n">filtered_nodes</span> <span class="o">=</span> <span class="nb">set</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_nodes</span><span class="p">)</span>
<span class="c1"># Always keep root</span>
Expand All @@ -2053,7 +2039,7 @@ <h1 class="modulename">
<span class="k">if</span> <span class="n">desc</span><span class="p">:</span>
<span class="c1"># Keep descendants of the given nodes</span>
<span class="k">for</span> <span class="n">node</span> <span class="ow">in</span> <span class="n">nodes</span><span class="p">:</span>
<span class="c1"># Check if node exists</span>
<span class="c1"># Check if node exists (skips root)</span>
<span class="k">if</span> <span class="n">node</span> <span class="ow">in</span> <span class="n">filtered_nodes</span><span class="p">:</span>
<span class="c1"># For each leaf of the selected nodes</span>
<span class="k">for</span> <span class="n">leaf</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">leaves</span><span class="p">(</span><span class="n">node</span><span class="p">):</span>
Expand All @@ -2077,7 +2063,6 @@ <h1 class="modulename">

<span class="c1"># Delete aux. data structures</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_reset_aux_data</span><span class="p">()</span>

<span class="bp">self</span><span class="o">.</span><span class="n">check_consistency</span><span class="p">()</span>
</pre></div>

Expand Down
2 changes: 1 addition & 1 deletion docs/search.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion multitax/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "1.3.0"
__version__ = "1.3.1"

__all__ = (
'CustomTx',
Expand Down
7 changes: 1 addition & 6 deletions multitax/multitax.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,10 +365,6 @@ def filter(self, nodes: list, desc: bool = False):
if isinstance(nodes, str):
nodes = [nodes]

# Cannot filter root node
if self.root_node in nodes:
raise ValueError("Root node [" + self.root_node + "] cannot be filtered.")

# Keep track of nodes to be filtered out
filtered_nodes = set(self._nodes)
# Always keep root
Expand All @@ -377,7 +373,7 @@ def filter(self, nodes: list, desc: bool = False):
if desc:
# Keep descendants of the given nodes
for node in nodes:
# Check if node exists
# Check if node exists (skips root)
if node in filtered_nodes:
# For each leaf of the selected nodes
for leaf in self.leaves(node):
Expand All @@ -401,7 +397,6 @@ def filter(self, nodes: list, desc: bool = False):

# Delete aux. data structures
self._reset_aux_data()

self.check_consistency()

def latest(self, node: str):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

setup(
name="multitax",
version="1.3.0",
version="1.3.1",
url="https://www.github.com/pirovc/multitax",
license="MIT",
author="Vitor C. Piro",
Expand Down
10 changes: 0 additions & 10 deletions tests/multitax/unit/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,16 +500,6 @@ def test_filter(self):
self.assertCountEqual(tax.lineage("4.5"), [])
self.assertCountEqual(tax.leaves("1"), ["4.2", "4.3", "5.1", "5.2"])

# No filter for root
tax = CustomTx(files=self.test_file)
self.assertEqual(tax.stats()["nodes"], 14)
with self.assertRaises(ValueError):
tax.filter(tax.root_node)
tax.filter(["2.2", tax.root_node])
tax.filter(tax.root_node, desc=True)
tax.filter(["2.2", tax.root_node], desc=True)
self.assertEqual(tax.stats()["nodes"], 14)

tax = CustomTx(files=self.test_file)
self.assertEqual(tax.stats()["nodes"], 14)
tax.filter("XXXXX", desc=True)
Expand Down

0 comments on commit 396e19c

Please sign in to comment.