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

TypeError: tuple indices must be integers or slices, not str #43

Open
MeisterP opened this issue Sep 18, 2022 · 5 comments
Open

TypeError: tuple indices must be integers or slices, not str #43

MeisterP opened this issue Sep 18, 2022 · 5 comments
Labels
bug Something isn't working

Comments

@MeisterP
Copy link

MeisterP commented Sep 18, 2022

After updating to v0.2.3 (September 2022)
I get the following error when calling correct_rr(rr):

Cleaning the RR interval time series.
... correcting 3 missed interval(s).
... correcting 1 extra interval(s).
... correcting 89 ectopic interval(s).
... correcting 5 short interval(s).
... correcting 5 long interval(s).
Traceback (most recent call last):
  File "<string>", line 79, in <module>
TypeError: tuple indices must be integers or slices, not str

While trying to disable things one by one to debug (eg. correct_rr(rr, missed_correction=False) I got:

Cleaning the RR interval time series.
... correcting 1 extra interval(s).
... correcting 89 ectopic interval(s).
... correcting 5 short interval(s).
... correcting 5 long interval(s).
Traceback (most recent call last):
  File "<string>", line 77, in <module>
  File "/usr/lib/python3.10/site-packages/systole/correction.py", line 363, in correct_rr
    return _correct_rr(
  File "/usr/lib/python3.10/site-packages/systole/correction.py", line 263, in _correct_rr
    return clean_rr, (nMissed, nExtra, nEctopic, nShort, nLong)
UnboundLocalError: local variable 'nMissed' referenced before assignment

correct_rr(rr, n_iterations=2) doesn't work either:

Traceback (most recent call last):
  File "<string>", line 77, in <module>
TypeError: correct_rr() got an unexpected keyword argument 'n_iterations'

With version 0.2.2 correct_rr(rr, n_iterations=2, missed_correction=False) works as expected without errors.

@LegrandNico
Copy link
Contributor

Thank you for reporting this, I suspect this might be due to artefacts close to each other, can you share the data you are using so I can reproduce the error?

@MeisterP
Copy link
Author

My code is failing because the output of the correct_rr() function changed.

import pandas as pd
from systole.correction import correct_rr

df = pd.read_csv('data.csv')
correct = correct_rr(df['R-R'])

with version 0.2.2:

print(correct)
{'clean_rr': array([565., 560., 560., ..., 507., 512., 509.]), 'ectopic': 66, 'short': 40, 'long': 11, 'extra': 17, 'missed': 0}

print(correct['clean_rr'])
[565. 560. 560. ... 507. 512. 509.]

with version 0.2.3:

print(correct)
(array([565., 560., 560., ..., 507., 512., 509.]), (0, 17, 21, 30, 10))

print(correct['clean_rr'])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: tuple indices must be integers or slices, not str

@LegrandNico
Copy link
Contributor

It looks like the function is working correctly but the way it returns the results have changed:
https://embodied-computation-group.github.io/systole/generated/correction/systole.correction.correct_rr.html#systole.correction.correct_rr

It is now returning a tuple like:

clean_rr, (nMissed, nExtra, nEctopic, nShort, Long) = correct_rr(df['R-R'])

If you use the code above it should work. Sorry for this refactoring, the function has been completely rewritten in this release.

@MeisterP
Copy link
Author

MeisterP commented Sep 19, 2022

There's no need to be sorry. Thanks for your work and support. Much appreciated. 👍

Not sure whether I'm misreading the docs... but I can't get arguments to work.

correct = correct_rr(df['R-R'], extra_correction=False)
Cleaning the RR interval time series.
... correcting 21 ectopic interval(s).
... correcting 30 short interval(s).
... correcting 12 long interval(s).
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.10/site-packages/systole/correction.py", line 363, in correct_rr
    return _correct_rr(
  File "/usr/lib/python3.10/site-packages/systole/correction.py", line 263, in _correct_rr
    return clean_rr, (nMissed, nExtra, nEctopic, nShort, nLong)
UnboundLocalError: local variable 'nExtra' referenced before assignment
correct = correct_rr(df['R-R'], n_iterations=2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: correct_rr() got an unexpected keyword argument 'n_iterations'

@LegrandNico LegrandNico added the bug Something isn't working label Sep 22, 2022
@LegrandNico
Copy link
Contributor

I see the error comes from the absence of extra correction that is not correctly accounted for in the code, I will fix that as soon as possible. Thank you for pointing that out.

For the second example, the n_iteration argument has been removed in the new API to better fit with the original paper, so the function will not allow running multiple iterations of the algorithm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants