Skip to content

Adding update_node signal and connected them to spatial filters#266

Merged
JoOkuma merged 11 commits intoroyerlab:mainfrom
yfukai:node_update_in_filters
Feb 27, 2026
Merged

Adding update_node signal and connected them to spatial filters#266
JoOkuma merged 11 commits intoroyerlab:mainfrom
yfukai:node_update_in_filters

Conversation

@yfukai
Copy link
Contributor

@yfukai yfukai commented Feb 19, 2026

This PR adds update_node signal to the graphs, and connected them to (BBox)SpatialFilter so that the rtrees are correctly udpated.

@yfukai yfukai marked this pull request as ready for review February 19, 2026 06:51
@codecov-commenter
Copy link

codecov-commenter commented Feb 19, 2026

Codecov Report

❌ Patch coverage is 90.47619% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.22%. Comparing base (e10d8c3) to head (6aa3bc6).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/tracksdata/graph/filters/_spatial_filter.py 74.35% 6 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #266      +/-   ##
==========================================
+ Coverage   88.18%   88.22%   +0.03%     
==========================================
  Files          56       56              
  Lines        4308     4398      +90     
  Branches      749      780      +31     
==========================================
+ Hits         3799     3880      +81     
- Misses        319      324       +5     
- Partials      190      194       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@JoOkuma JoOkuma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @yfukai,
Thanks for the PR.
I'm a bit worried it might make things slower, but it seems safe based on the benchmarks CI.

)
else:
if self._graph.num_nodes() == 0:
raise ValueError("Spatial filter is not initialized")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe also improve the error message.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I found that the num_nodes must not be zero, since we emit the events after adding the nodes. I simply deleted this if clause.

node_ids = self.node_ids()

emit_node_updated = is_signal_on(self.node_updated)
old_attrs_by_id = {node_id: dict(self._graph[node_id]) for node_id in node_ids} if emit_node_updated else None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as the other comment. Can you make this optional depending on is_signal_on

Comment on lines 1759 to 1772
updated_node_ids = self.node_ids() if node_ids is None else list(node_ids)
if len(updated_node_ids) == 0:
return
attr_keys = self.node_attr_keys()
old_df = self.filter(node_ids=updated_node_ids).node_attrs(attr_keys=[DEFAULT_ATTR_KEYS.NODE_ID, *attr_keys])
old_attrs_by_id = {
row[DEFAULT_ATTR_KEYS.NODE_ID]: {key: row[key] for key in attr_keys} for row in old_df.rows(named=True)
}

self._update_table(self.Node, node_ids, DEFAULT_ATTR_KEYS.NODE_ID, attrs)
new_df = self.filter(node_ids=updated_node_ids).node_attrs(attr_keys=[DEFAULT_ATTR_KEYS.NODE_ID, *attr_keys])
new_attrs_by_id = {
row[DEFAULT_ATTR_KEYS.NODE_ID]: {key: row[key] for key in attr_keys} for row in new_df.rows(named=True)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you only trigger this only if is_signal_on

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's definitely better, thanks!

Copy link
Contributor Author

@yfukai yfukai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I removed all the unnecessary dict calls and moved heavy computation inside the is_signal_on blocks! Maybe we can make events for bulk updates in the future.

)
else:
if self._graph.num_nodes() == 0:
raise ValueError("Spatial filter is not initialized")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I found that the num_nodes must not be zero, since we emit the events after adding the nodes. I simply deleted this if clause.

Comment on lines 1759 to 1772
updated_node_ids = self.node_ids() if node_ids is None else list(node_ids)
if len(updated_node_ids) == 0:
return
attr_keys = self.node_attr_keys()
old_df = self.filter(node_ids=updated_node_ids).node_attrs(attr_keys=[DEFAULT_ATTR_KEYS.NODE_ID, *attr_keys])
old_attrs_by_id = {
row[DEFAULT_ATTR_KEYS.NODE_ID]: {key: row[key] for key in attr_keys} for row in old_df.rows(named=True)
}

self._update_table(self.Node, node_ids, DEFAULT_ATTR_KEYS.NODE_ID, attrs)
new_df = self.filter(node_ids=updated_node_ids).node_attrs(attr_keys=[DEFAULT_ATTR_KEYS.NODE_ID, *attr_keys])
new_attrs_by_id = {
row[DEFAULT_ATTR_KEYS.NODE_ID]: {key: row[key] for key in attr_keys} for row in new_df.rows(named=True)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's definitely better, thanks!

Copy link
Member

@JoOkuma JoOkuma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @yfukai, sorry for the delay. I've been quite busy.

It looks good to me, but I left a few minor comments regarding the type casting.

Some seem unnecessary, and I'm worried about additional overhead.
Don't hesitate to let me know if they are required.

yfukai and others added 3 commits February 27, 2026 10:19
Co-authored-by: Jordão Bragantini <jordao.bragantini@gmail.com>
Co-authored-by: Jordão Bragantini <jordao.bragantini@gmail.com>
Co-authored-by: Jordão Bragantini <jordao.bragantini@gmail.com>
@yfukai
Copy link
Contributor Author

yfukai commented Feb 27, 2026

Thanks for the comments, I completely agree. Reflected.

@JoOkuma
Copy link
Member

JoOkuma commented Feb 27, 2026

Thanks @yfukai, merged, I'll take a look at the other PRs tomorrow

@JoOkuma JoOkuma merged commit 55c858b into royerlab:main Feb 27, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants