-
Notifications
You must be signed in to change notification settings - Fork 17
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
Split aoi dataframe by chosen criteria #879
Open
izaskr
wants to merge
15
commits into
main
Choose a base branch
from
aoi_events
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
384a417
feat: splitting aois criteria
izaskr ecea48f
feat: splitting aois criteria, fix pydocstyle
izaskr 39a5f00
feat: splitting aois criteria, fix pydocstyle
izaskr b94a301
Merge branch 'main' of https://github.com/aeye-lab/pymovements into a…
izaskr 6406dd2
Merge remote-tracking branch 'origin/aoi_events' into aoi_events
izaskr b65185d
Merge remote-tracking branch 'origin/aoi_events' into aoi_events
izaskr 678a184
Merge branch 'main' of https://github.com/aeye-lab/pymovements into a…
izaskr 2a822b6
Merge remote-tracking branch 'origin/aoi_events' into aoi_events
izaskr c51aadb
Merge remote-tracking branch 'origin/aoi_events' into aoi_events
izaskr a6467e3
Merge branch 'main' of https://github.com/aeye-lab/pymovements into a…
izaskr 07dee8a
Merge branch 'aoi_events' of https://github.com/aeye-lab/pymovements …
izaskr 772987d
Merge branch 'aoi_events' of https://github.com/aeye-lab/pymovements …
izaskr 019bd0d
Merge branch 'aoi_events' of https://github.com/aeye-lab/pymovements …
izaskr eef4d66
Merge branch 'aoi_events' of https://github.com/aeye-lab/pymovements …
izaskr 652d0b0
Merge branch 'aoi_events' of https://github.com/aeye-lab/pymovements …
izaskr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -226,3 +226,101 @@ def test_text_stimulus_unsupported_format(): | |
expected = 'unsupported file format ".pickle".Supported formats are: '\ | ||
'[\'.csv\', \'.ias\', \'.tsv\', \'.txt\']' | ||
assert msg == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
('aoi_file', 'custom_read_kwargs'), | ||
[ | ||
pytest.param( | ||
'tests/files/toy_text_1_1_aoi.csv', | ||
None, | ||
id='toy_text_1_1_aoi', | ||
), | ||
pytest.param( | ||
Path('tests/files/toy_text_1_1_aoi.csv'), | ||
{'separator': ','}, | ||
id='toy_text_1_1_aoi', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. avoid having the same id for different test parametrizations. you could use something like: |
||
), | ||
], | ||
) | ||
def test_text_stimulus_splitting(aoi_file, custom_read_kwargs): | ||
aois_df = pm.stimulus.text.from_file( | ||
aoi_file, | ||
aoi_column='char', | ||
start_x_column='top_left_x', | ||
start_y_column='top_left_y', | ||
width_column='width', | ||
height_column='height', | ||
page_column='page', | ||
custom_read_kwargs=custom_read_kwargs, | ||
) | ||
|
||
aois_df = aois_df.split(by='line_idx') | ||
assert len(aois_df) == 2 | ||
dkrako marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
@pytest.mark.parametrize( | ||
('aoi_file', 'custom_read_kwargs'), | ||
[ | ||
pytest.param( | ||
'tests/files/toy_text_1_1_aoi.csv', | ||
None, | ||
id='toy_text_1_1_aoi', | ||
), | ||
pytest.param( | ||
Path('tests/files/toy_text_1_1_aoi.csv'), | ||
{'separator': ','}, | ||
id='toy_text_1_1_aoi', | ||
), | ||
], | ||
) | ||
def test_text_stimulus_splitting_unique_within(aoi_file, custom_read_kwargs): | ||
aois_df = pm.stimulus.text.from_file( | ||
aoi_file, | ||
aoi_column='char', | ||
start_x_column='top_left_x', | ||
start_y_column='top_left_y', | ||
width_column='width', | ||
height_column='height', | ||
page_column='page', | ||
custom_read_kwargs=custom_read_kwargs, | ||
) | ||
|
||
aois_df = aois_df.split(by='line_idx') | ||
assert all(df.n_unique(subset=['line_idx']) == 1 for df in aois_df) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
('aoi_file', 'custom_read_kwargs'), | ||
[ | ||
pytest.param( | ||
'tests/files/toy_text_1_1_aoi.csv', | ||
None, | ||
id='toy_text_1_1_aoi', | ||
), | ||
pytest.param( | ||
Path('tests/files/toy_text_1_1_aoi.csv'), | ||
{'separator': ','}, | ||
id='toy_text_1_1_aoi', | ||
), | ||
], | ||
) | ||
def test_text_stimulus_splitting_different_between(aoi_file, custom_read_kwargs): | ||
aois_df = pm.stimulus.text.from_file( | ||
aoi_file, | ||
aoi_column='char', | ||
start_x_column='top_left_x', | ||
start_y_column='top_left_y', | ||
width_column='width', | ||
height_column='height', | ||
page_column='page', | ||
custom_read_kwargs=custom_read_kwargs, | ||
) | ||
|
||
aois_df = aois_df.split(by='line_idx') | ||
unique_values = [] | ||
for df in aois_df: | ||
unique_value = df.unique(subset=['line_idx'])['line_idx'].to_list() | ||
unique_values.extend(unique_value) | ||
|
||
assert len(unique_values) == len(set(unique_values)) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I must have missed this in my review two weeks ago.
this line returns a list of
polars.DataFrame
not a list ofTextStimulus
objects.You should probably do something like this:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SiQube I am confused why mypy didn't complain here, as I would expect a type mismatch. I am clueless. Do you have an explanation? I am a bit worried that there's something wrong in our CI.