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

[FIX] KeyError in _eventrelated_addinfo #868

Merged

Conversation

SimonLafran
Copy link
Contributor

Fixes #867

_eventrelated_addinfo in epochs/eventrelated_utils.py has these lines:

if "Index" in epoch.columns:
    output["Event_Onset"] = epoch.loc[np.min(np.abs(epoch.index))]["Index"]

np.min(np.abs(...)) returns the smallest absolute time offset in seconds. If the smallest absolute value is of a negative time offset, then it produces a non-existent index, causing an error when indexing in epoch.loc.

This commit replaces it with iloc[np.argmin(np.abs(...))], indexing by integer index.

See neuropsychology#867 (comment)

_eventrelated_addinfo in epochs/eventrelated_utils.py has these lines:

```
if "Index" in epoch.columns:
    output["Event_Onset"] = epoch.loc[np.min(np.abs(epoch.index))]["Index"]
```

np.min(np.abs(...) returns the smallest absolute time offset in seconds.
If the smallest absolute value is of a negative time offset, then it
produces a non-existent index, causing an error when indexing in
epoch.loc.

This commit replaces it with iloc[np.argmin(np.abs(...))], indexing by
integer index.
@welcome
Copy link

welcome bot commented Jul 15, 2023

Thanks for opening this pull request! We'll make sure it's perfect before merging 🤗 force
Make sure to read the contributing guide. Also, if you think that your contribution is worthy of it, you can consider adding yourself to the Contributors list (feel free to ask us if you have any doubts).

@codecov-commenter
Copy link

codecov-commenter commented Jul 15, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: -0.06 ⚠️

Comparison is base (1c1651d) 55.28% compared to head (ac08ef3) 55.23%.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #868      +/-   ##
==========================================
- Coverage   55.28%   55.23%   -0.06%     
==========================================
  Files         297      297              
  Lines       13918    13918              
==========================================
- Hits         7695     7688       -7     
- Misses       6223     6230       +7     
Impacted Files Coverage Δ
neurokit2/epochs/eventrelated_utils.py 91.66% <100.00%> (ø)

... and 2 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@DominiqueMakowski
Copy link
Member

Nice catch @SimonLafran thanks ☺️

@DominiqueMakowski DominiqueMakowski merged commit a802b57 into neuropsychology:dev Jul 17, 2023
@welcome
Copy link

welcome bot commented Jul 17, 2023

landing
Congrats on merging your first pull request! 🎉🍾 We're looking forward to your next one!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants