Skip to content

Commit

Permalink
Merge pull request #556 from AllenInstitute/bugfix/_get_series-error-…
Browse files Browse the repository at this point in the history
…messages

fixes error messages in _get_series
  • Loading branch information
njmei authored Jun 29, 2023
2 parents 797e677 + 509f6ce commit 2599bc1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ All notable changes to this project will be documented in this file.

### Changed

## [1.0.8] = 2023-06-29
Changed:
- Fixed an error that was obscuring underlying errors when trying to _get_series information for a PatchClampSeries

## [1.0.7] = 2022-12-5
Changed:
- Added StimulusType and STIMULUS_TYPE_NAME_MAPPING to stimulus ontology, replacing definitions in EphysDataset
Expand Down
26 changes: 12 additions & 14 deletions ipfx/dataset/ephys_nwb_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,14 @@ def _get_series(self, sweep_number: int,

series = self.nwb.sweep_table.get_series(sweep_number)

if series is None:
if not series:
raise ValueError(
f"No TimeSeries found for sweep number {sweep_number}."
)

matching_series = []

# Look for instances of stimulus or response PatchCLampSeries
# Look for instances of matching series types PatchCLampSeries
for s in series:
if isinstance(s, series_class):
matching_series.append(s)
Expand All @@ -164,30 +164,28 @@ def _get_series(self, sweep_number: int,
if num_series == 1:
return matching_series[0]
else:
# check series type so we can display an appropriate error

if isinstance(series_class, self.STIMULUS):
# simplify series class to stimulus or response for error messages
if series_class == self.STIMULUS:
series_name = "stimulus"
elif isinstance(series_class, self.RESPONSE):
elif series_class == self.RESPONSE:
series_name = "response"
else:
raise TypeError(
f"{type(series_class)} is not a stimulus or response PatchClampSeries"
)
# Unknown series categorization so don't simplify
series_name = series_class

if num_series == 0:
if num_series > 1:
raise ValueError(
f"Could not find any {series_name} PatchClampSeries "
f"Found {num_series} {series_name} PatchClampSeries "
f"{[s.name for s in matching_series]} "
f"for sweep number {sweep_number}."
)
else:
# check how many matching series we have
raise ValueError(
f"Found {num_series} {series_name} PatchClampSeries "
f"{[s.name for s in matching_series]} "
f"Could not find any {series_name} PatchClampSeries "
f"for sweep number {sweep_number}."
)


def get_sweep_data(
self, sweep_number: int
) -> Dict[str, Union[np.ndarray, str, float]]:
Expand Down
2 changes: 1 addition & 1 deletion ipfx/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.7
1.0.8

0 comments on commit 2599bc1

Please sign in to comment.