Skip to content

Commit

Permalink
Change Filter Shallow Copies to Deep Copies (LLNL#175)
Browse files Browse the repository at this point in the history
* Change filter copies to deepcopies

* Add unit test
  • Loading branch information
michaelmckinsey1 authored Jun 17, 2024
1 parent 3950c53 commit c2a0172
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
3 changes: 3 additions & 0 deletions thicket/tests/test_filter_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ def filter_one_column(th, columns_values):
# check if output is a thicket object
assert isinstance(new_th, Thicket)

# check filtered Thicket is separate object
assert th.graph is not new_th.graph

# metadata table: compare profile hash keys after filter to expected
metadata_profile = new_th.metadata.index.tolist()
assert metadata_profile == exp_index
Expand Down
4 changes: 4 additions & 0 deletions thicket/tests/test_filter_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ def check_filter_stats(th, columns_values):
# check if output is a thicket object
assert isinstance(new_th, Thicket)

# check filtered Thicket is separate object
# We can't check th.graph because of squash in filter_stats
assert th.statsframe.graph is not new_th.statsframe.graph

# filtered nodes in aggregated statistics table
stats_nodes = sorted(
new_th.statsframe.dataframe.index.drop_duplicates().tolist()
Expand Down
8 changes: 4 additions & 4 deletions thicket/thicket.py
Original file line number Diff line number Diff line change
Expand Up @@ -1090,8 +1090,8 @@ def filter_metadata(self, select_function):
# Get index name
index_name = self.metadata.index.name

# create a copy of the thicket object
new_thicket = self.copy()
# create a deepcopy of the thicket object
new_thicket = self.deepcopy()

# filter metadata table
filtered_rows = new_thicket.metadata.apply(select_function, axis=1)
Expand Down Expand Up @@ -1242,8 +1242,8 @@ def filter_stats(self, filter_function):
Returns:
(thicket): new thicket object with applied filter function
"""
# copy thicket
new_thicket = self.copy()
# deepcopy thicket
new_thicket = self.deepcopy()

# filter aggregated statistics table
filtered_rows = new_thicket.statsframe.dataframe.apply(filter_function, axis=1)
Expand Down

0 comments on commit c2a0172

Please sign in to comment.