aeye-lab / pymovements

A python package for processing eye movement data
https://pymovements.readthedocs.io
MIT License
61 stars 12 forks source link

feat!: Add GazeDataFrame.transform() #440

Closed dkrako closed 1 year ago

dkrako commented 1 year ago

This PR implements a general GazeDataFrame.transform() method which applies any transform method from pymovements.gaze.transforms.

codecov[bot] commented 1 year ago

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (43908f6) 100.00% compared to head (cf1e5af) 100.00%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #440 +/- ## ========================================= Coverage 100.00% 100.00% ========================================= Files 55 55 Lines 2090 2152 +62 Branches 475 503 +28 ========================================= + Hits 2090 2152 +62 ``` | [Files Changed](https://app.codecov.io/gh/aeye-lab/pymovements/pull/440?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aeye-lab) | Coverage Δ | | |---|---|---| | [src/pymovements/gaze/transforms\_pl/pos2acc.py](https://app.codecov.io/gh/aeye-lab/pymovements/pull/440?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aeye-lab#diff-c3JjL3B5bW92ZW1lbnRzL2dhemUvdHJhbnNmb3Jtc19wbC9wb3MyYWNjLnB5) | `100.00% <ø> (ø)` | | | [src/pymovements/gaze/gaze\_dataframe.py](https://app.codecov.io/gh/aeye-lab/pymovements/pull/440?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aeye-lab#diff-c3JjL3B5bW92ZW1lbnRzL2dhemUvZ2F6ZV9kYXRhZnJhbWUucHk=) | `100.00% <100.00%> (ø)` | | | [src/pymovements/gaze/transforms\_pl/\_\_init\_\_.py](https://app.codecov.io/gh/aeye-lab/pymovements/pull/440?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aeye-lab#diff-c3JjL3B5bW92ZW1lbnRzL2dhemUvdHJhbnNmb3Jtc19wbC9fX2luaXRfXy5weQ==) | `100.00% <100.00%> (ø)` | | | [...rc/pymovements/gaze/transforms\_pl/center\_origin.py](https://app.codecov.io/gh/aeye-lab/pymovements/pull/440?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aeye-lab#diff-c3JjL3B5bW92ZW1lbnRzL2dhemUvdHJhbnNmb3Jtc19wbC9jZW50ZXJfb3JpZ2luLnB5) | `100.00% <100.00%> (ø)` | | | [src/pymovements/gaze/transforms\_pl/pix2deg.py](https://app.codecov.io/gh/aeye-lab/pymovements/pull/440?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aeye-lab#diff-c3JjL3B5bW92ZW1lbnRzL2dhemUvdHJhbnNmb3Jtc19wbC9waXgyZGVnLnB5) | `100.00% <100.00%> (ø)` | | | [src/pymovements/gaze/transforms\_pl/pos2vel.py](https://app.codecov.io/gh/aeye-lab/pymovements/pull/440?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aeye-lab#diff-c3JjL3B5bW92ZW1lbnRzL2dhemUvdHJhbnNmb3Jtc19wbC9wb3MydmVsLnB5) | `100.00% <100.00%> (ø)` | | | [...c/pymovements/gaze/transforms\_pl/savitzky\_golay.py](https://app.codecov.io/gh/aeye-lab/pymovements/pull/440?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aeye-lab#diff-c3JjL3B5bW92ZW1lbnRzL2dhemUvdHJhbnNmb3Jtc19wbC9zYXZpdHpreV9nb2xheS5weQ==) | `100.00% <100.00%> (ø)` | | | [src/pymovements/utils/checks.py](https://app.codecov.io/gh/aeye-lab/pymovements/pull/440?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aeye-lab#diff-c3JjL3B5bW92ZW1lbnRzL3V0aWxzL2NoZWNrcy5weQ==) | `100.00% <100.00%> (ø)` | |

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

dkrako commented 1 year ago

I have ignored one line for pylint for this error: cell-var-from-loop

caused by these lines: https://github.com/aeye-lab/pymovements/blob/40f85a63bf188e264fc52fff4515ff881e754d44/src/pymovements/gaze/transforms_pl/pix2deg.py#L79-L86

But now I have read a bit further and found this reddit thread: https://www.reddit.com/r/learnpython/comments/kvct0d/pylint_cell_variable_val_defined_in_loop_why/

I toyed around a bit and pylint has actually exposed a bug here I think. I will have to revisit this next week.

dkrako commented 1 year ago

Wow pylint really exposed a bug here. I didn't know that was a potential problem in python.

If I understand correctly, the unexpected behavior comes from the delayed creation of the lambda function. In the previous code snippet component would then always be the final value (n_components - 1).

As a very simple example, the output of this is crazy:

>>> multipliers = [lambda x : i * x for i in range(4)]
>>> print([m(2) for m in multipliers])
[6, 6, 6, 6]

This is the fix for the problematic code of my last comment:

https://github.com/aeye-lab/pymovements/blob/a1dfad6ce83aac0226b97f71e864fbcc09716ce0/src/pymovements/gaze/transforms_pl/pix2deg.py#L81-L86

with

https://github.com/aeye-lab/pymovements/blob/a1dfad6ce83aac0226b97f71e864fbcc09716ce0/src/pymovements/gaze/transforms_pl/pix2deg.py#L91-L93

I would have liked to use functools.partial, but that way you can't fill the second positional argument and leave the first as positional argument