-
Notifications
You must be signed in to change notification settings - Fork 9
Add Root Node to Graph #192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
65c9c5e to
64ade20
Compare
ilumsden
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly looks good.
The only change that really needs to be made is the one about pop(). The other two are just suggestions.
thicket/thicket.py
Outdated
|
|
||
| new_node = hatchet.node.Node( | ||
| frame_obj=frame.Frame(attrs=attrs), hnid=len(self.graph) | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're going to do frame.Frame, why not also do node.Node? Or, better yet, just do the imports in a way that let's you do Node and Frame.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was using node.Node but we use node as a variable name in squash and I'm using it in get_node(). Not a big deal, so I'll just import Node and Frame
thicket/thicket.py
Outdated
| warnings.warn(f'More than one node with name "{name}". Returning a list') | ||
| return node | ||
|
|
||
| return node.pop() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better to just return node[0]. pop will do things like resizing (see the source code), which isn't needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3ecea5b to
7294aac
Compare
ilumsden
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This mostly looks good at this point. Just a couple of minor changes.
thicket/tests/test_add_root_node.py
Outdated
|
|
||
|
|
||
| def test_add_root_node(literal_thickets): | ||
| tk, tk2, tk3 = literal_thickets |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you're not using tk2 or tk3, change this line to the following:
tk, _, _ = literal_thicketsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thicket/tests/test_get_node.py
Outdated
|
|
||
|
|
||
| def test_get_node(literal_thickets): | ||
| tk, tk2, tk3 = literal_thickets |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See previous comment about use of underscores here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thicket/thicket.py
Outdated
| warnings.warn(f'More than one node with name "{name}". Returning a list') | ||
| return node | ||
| elif len(node) == 0: | ||
| raise ValueError(f'Node with name "{name}" not found.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would raise a KeyError here instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thicket/thicket.py
Outdated
| node = [n for n in self.graph.traverse() if n.frame["name"] == name] | ||
|
|
||
| if len(node) > 1: | ||
| warnings.warn(f'More than one node with name "{name}". Returning a list') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this warning is necessary as long as we document the return type correctly. Regardless if this warning is kept or removed, the docstring needs to be updated to indicate that it can return either Node or List[Node].
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ilumsden
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
@pearce8 this is ready for your review
Examples of
add_root_nodeandget_nodecan be found in the notebook in thicket-tutorial/48add_root_nodeenables adding a root node to theThicket.graphand correspondingThicket.statsframeandThicket.dataframeobjects.get_nodeprovides a simpler interface for grabbing a node object by its name in the Thicket instead of using something like[n for n in self.graph.traverse() if n.frame["name"] == name][0]. This function is optional for this PR or could be its own PR; I am proposing it here.