Skip to content

Conversation

@pollytur
Copy link
Contributor

Small PR to address issues #32 , #70 , #73

@gitnotebooks
Copy link

gitnotebooks bot commented Dec 12, 2025

Review these changes at https://app.gitnotebooks.com/sensorium-competition/experanto/pull/90

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses issues #32, #70, and #73 by introducing a return_valid parameter to interpolation methods, removing unused code, and renaming a confusing transform option. The changes enable callers to optionally request validation masks from interpolation operations, making the API more flexible while maintaining backward compatibility through default parameter values.

Key Changes:

  • Added return_valid parameter to all interpolator classes to conditionally return validation masks
  • Renamed "standardize" transform mode to "normalize_variance_only" for clarity
  • Removed unused namedtuple imports and DataPoint class

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
experanto/interpolators.py Added return_valid parameter to abstract method and all concrete implementations (SequenceInterpolator, PhaseShiftedSequenceInterpolator, ScreenInterpolator, TimeIntervalInterpolator) with conditional return logic
experanto/experiment.py Updated interpolate method signature to accept and propagate return_valid parameter; removed unused namedtuple import
experanto/datasets.py Updated interpolate calls to use return_valid=False; renamed "standardize" to "normalize_variance_only"; removed unused namedtuple and DataPoint
configs/default.yaml Updated normalization config value from "standardize" to "normalize_variance_only"
docs/source/concepts/demo_configs.rst Updated example config to use "normalize_variance_only"
README.md Added documentation badge link

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 68 to 70
values[d], valid[d] = interp.interpolate(
times, return_valid=return_valid
)
Copy link

Copilot AI Dec 12, 2025

Choose a reason for hiding this comment

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

When return_valid is False, interp.interpolate() will return only the values (not a tuple), causing an unpacking error. The code attempts to unpack into two variables (values[d], valid[d]) but will receive only one value when return_valid=False. This should be handled conditionally similar to how it's done in lines 73-75 and 76-79.

Suggested change
values[d], valid[d] = interp.interpolate(
times, return_valid=return_valid
)
if return_valid:
values[d], valid[d] = interp.interpolate(
times, return_valid=return_valid
)
else:
values[d] = interp.interpolate(
times, return_valid=return_valid
)

Copilot uses AI. Check for mistakes.
Comment on lines 73 to 75
values, valid = self.devices[device].interpolate(
times, return_valid=return_valid
)
Copy link

Copilot AI Dec 12, 2025

Choose a reason for hiding this comment

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

When return_valid is False, the interpolate call will return only the values (not a tuple), causing an unpacking error. The code attempts to unpack into two variables (values, valid) but will receive only one value when return_valid=False. Consider handling this conditionally to match the actual return behavior.

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 7 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

def interpolate(
self,
times: slice,
device: Interpolator | None = None,
Copy link

Copilot AI Dec 12, 2025

Choose a reason for hiding this comment

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

The type annotation for the device parameter is Interpolator | None, but the code at line 79 checks isinstance(device, str), indicating that device can also be a string (device name). The type annotation should be str | Interpolator | None or Union[str, Interpolator, None] to accurately reflect the accepted types.

Suggested change
device: Interpolator | None = None,
device: Union[str, Interpolator, None] = None,

Copilot uses AI. Check for mistakes.
times: slice,
device: Interpolator | None = None,
return_valid: bool = False,
) -> Union[tuple[np.ndarray, np.ndarray], np.ndarray]:
Copy link

Copilot AI Dec 12, 2025

Choose a reason for hiding this comment

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

The return type annotation Union[tuple[np.ndarray, np.ndarray], np.ndarray] is incorrect. When device is None, the function returns dictionaries (either just values dict or (values, valid) tuple of dicts), not numpy arrays. The return type should be Union[tuple[dict, dict], dict, tuple[np.ndarray, np.ndarray], np.ndarray] or a more specific type that accurately represents both the dict and array cases.

Copilot uses AI. Check for mistakes.
out[mask, i] = True

return out
return (out, valid) if return_valid else out
Copy link

Copilot AI Dec 12, 2025

Choose a reason for hiding this comment

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

The return statement at line 589 correctly handles the return_valid parameter, but line 564 (the early return when n_times == 0) does not respect this parameter. This creates inconsistent return types depending on whether the times array is empty or not. While line 564 is outside the diff region, the inconsistency is introduced by adding the return_valid parameter without updating all return paths.

Copilot uses AI. Check for mistakes.
values[d] = vals
valid[d] = vlds
else:
values[d] = res
Copy link

Copilot AI Dec 12, 2025

Choose a reason for hiding this comment

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

When device is None, the function builds values and potentially valid dictionaries, but never returns them. The function should return (values, valid) when return_valid=True or just values when return_valid=False at the end of this branch.

Suggested change
values[d] = res
values[d] = res
if return_valid:
return values, valid
else:
return values

Copilot uses AI. Check for mistakes.
Comment on lines +516 to 521
def interpolate(
self, times: np.ndarray, return_valid: bool = False
) -> Union[tuple[np.ndarray, np.ndarray], np.ndarray]:
"""
Interpolate time intervals for labeled events.

Copy link

Copilot AI Dec 12, 2025

Choose a reason for hiding this comment

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

The docstring does not document the new return_valid parameter that was added to the function signature. The parameter should be documented in the Parameters section, and the Returns section should be updated to reflect that the return type varies based on this parameter.

Copilot uses AI. Check for mistakes.
Comment on lines +516 to 521
def interpolate(
self, times: np.ndarray, return_valid: bool = False
) -> Union[tuple[np.ndarray, np.ndarray], np.ndarray]:
"""
Interpolate time intervals for labeled events.

Copy link

Copilot AI Dec 12, 2025

Choose a reason for hiding this comment

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

The new return_valid parameter is not tested in any of the TimeIntervalInterpolator tests. Tests should be added to verify that when return_valid=True, the function returns a tuple of (output, valid_mask), and when return_valid=False (the default), it returns only the output array.

Copilot uses AI. Check for mistakes.
Comment on lines 37 to 38
...
# returns interpolated signal and boolean mask of valid samples
Copy link

Copilot AI Dec 12, 2025

Choose a reason for hiding this comment

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

The abstract method signature now includes the return_valid parameter, but there's no docstring explaining what this parameter does. Since this is an abstract method that all interpolators must implement, it should have comprehensive documentation explaining the parameter and return value behavior.

Suggested change
...
# returns interpolated signal and boolean mask of valid samples
"""
Interpolate the signal at the specified time points.
Parameters
----------
times : np.ndarray
Array of time points at which to interpolate the signal.
return_valid : bool, optional
If True, also return a boolean mask indicating which samples are valid.
If False (default), only the interpolated signal is returned.
Returns
-------
np.ndarray or tuple of (np.ndarray, np.ndarray)
If return_valid is False, returns the interpolated signal as a numpy array.
If return_valid is True, returns a tuple containing the interpolated signal and
a boolean numpy array mask of valid samples.
"""
...

Copilot uses AI. Check for mistakes.
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.

1 participant