Skip to content
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

Check DynamicTableRegion data is in bounds #1168

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft

Check DynamicTableRegion data is in bounds #1168

wants to merge 1 commit into from

Conversation

rly
Copy link
Contributor

@rly rly commented Aug 10, 2024

Motivation

Fix #210

Checklist

  • Did you update CHANGELOG.md with your changes?
  • Does the PR clearly describe the problem and the solution?
  • Have you reviewed our Contributing Guide?
  • Does the PR use "Fix #XXX" notation to tell GitHub to close the relevant issue numbered XXX when the PR is merged?

Copy link

codecov bot commented Aug 10, 2024

Codecov Report

Attention: Patch coverage is 85.18519% with 4 lines in your changes missing coverage. Please review.

Project coverage is 85.65%. Comparing base (3cc7db3) to head (3ba2646).

Files Patch % Lines
src/hdmf/container.py 33.33% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #1168      +/-   ##
==========================================
- Coverage   88.89%   85.65%   -3.24%     
==========================================
  Files          45       45              
  Lines        9834     9853      +19     
  Branches     2794     2802       +8     
==========================================
- Hits         8742     8440     -302     
- Misses        776     1076     +300     
- Partials      316      337      +21     

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

Comment on lines +1419 to +1420
for val in self.data:
self._validate_new_data_element(val)
Copy link
Contributor

Choose a reason for hiding this comment

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

You might want to try this as a list comprehension [self._validate_new_data_element(val) for val in self.data] just because they tend to be faster in Python than regular for loops

Comment on lines +1390 to +1393
for val in data:
if val >= len(table) or val < 0:
error_msg = f"DynamicTableRegion index {val} is out of bounds for {type(table)} '{table.name}'."
self._error_on_new_warn_on_construct(error_msg, error_cls=IndexError)
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of iterating through all the values, I think checking for np.max(data) >= len(table) would be more efficient.

@rly rly marked this pull request as draft August 19, 2024 17:37
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.

Do not allow write with a DynamicTableRegion index that is out of bounds
2 participants