Skip to content

Conversation

@bendichter
Copy link
Contributor

@bendichter bendichter requested a review from stephprince October 9, 2025 13:17
@bendichter
Copy link
Contributor Author

@stephprince this PR has been sitting for over a month. Can you please review it?

@stephprince
Copy link
Contributor

Yes I can take a look this afternoon! Sorry about that - thanks for the ping

Copy link
Contributor

@stephprince stephprince left a comment

Choose a reason for hiding this comment

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

@bendichter added my review - can you also add a best practice documentation section?

Comment on lines +332 to +341
# Check for timestamp column (possibly with duration)
if "timestamp" in table.colnames and len(table["timestamp"]) > 0:
timestamp_data = table["timestamp"]
start_times.append(float(timestamp_data[0]))

if "duration" in table.colnames and len(table["duration"]) > 0:
duration_data = table["duration"]
end_times.append(float(timestamp_data[-1] + duration_data[-1]))
else:
end_times.append(float(timestamp_data[-1]))
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we recommend storing data this way somewhere? This seems relatively arbitrary to look for (vs. the start_time/end_time and spike_times columns we know exist in DynamicTables from the schema).

Suggested change
# Check for timestamp column (possibly with duration)
if "timestamp" in table.colnames and len(table["timestamp"]) > 0:
timestamp_data = table["timestamp"]
start_times.append(float(timestamp_data[0]))
if "duration" in table.colnames and len(table["duration"]) > 0:
duration_data = table["duration"]
end_times.append(float(timestamp_data[-1] + duration_data[-1]))
else:
end_times.append(float(timestamp_data[-1]))

Copy link
Contributor

Choose a reason for hiding this comment

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

There are some other inspector checks that search for column names ending with _time. I think those could be checked for duration

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is for ndx-events. I should have mentioned that somewhere, huh?

Comment on lines +328 to +330
start_times.append(float(table["start_time"][0]))
if "stop_time" in table.colnames and len(table["stop_time"]) > 0:
end_times.append(float(table["stop_time"][-1]))
Copy link
Contributor

Choose a reason for hiding this comment

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

We could also check max/min of all start and stop times if we don't want to assume that these columns are also following ascending order best practices

Comment on lines +549 to +570
def test_check_table_time_columns_duration_with_timestamp():
"""Test with timestamp column."""
table = DynamicTable(name="events", description="test events")
table.add_column(name="timestamp", description="event timestamps")
table.add_row(timestamp=0.0)
table.add_row(timestamp=100.0)

assert check_table_time_columns_duration(table) is None


def test_check_table_time_columns_duration_with_timestamp_and_duration():
"""Test with timestamp and duration columns."""
one_year = 31557600.0
table = DynamicTable(name="events", description="test events")
table.add_column(name="timestamp", description="event timestamps")
table.add_column(name="duration", description="event durations")
table.add_row(timestamp=0.0, duration=10.0)
table.add_row(timestamp=one_year, duration=1000.0)

result = check_table_time_columns_duration(table)
assert result is not None
assert "exceeds the threshold" in result.message
Copy link
Contributor

Choose a reason for hiding this comment

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

See comment in _tables.py about these column names and whether we should keep these tests

assert check_table_time_columns_are_not_negative(test_table) is None


def test_check_table_time_columns_duration_pass_short():
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add tests for the Units table / spike_times case?

@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 71.42857% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.51%. Comparing base (d8382c9) to head (8d0c28b).

Files with missing lines Patch % Lines
src/nwbinspector/checks/_tables.py 71.42% 10 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##              dev     #628      +/-   ##
==========================================
+ Coverage   73.03%   76.51%   +3.47%     
==========================================
  Files          47       47              
  Lines        1587     1622      +35     
==========================================
+ Hits         1159     1241      +82     
+ Misses        428      381      -47     
Files with missing lines Coverage Δ
src/nwbinspector/checks/__init__.py 100.00% <ø> (ø)
src/nwbinspector/checks/_tables.py 91.55% <71.42%> (-5.93%) ⬇️

... and 4 files with indirect coverage changes

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

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.

4 participants