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

Split aoi dataframe by chosen criteria #879

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/pymovements/stimulus/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,20 @@ def __init__(
self.end_y_column = end_y_column
self.page_column = page_column

def split_aois_by(
dkrako marked this conversation as resolved.
Show resolved Hide resolved
self,
by: str | list[str],
) -> None:
"""Split the AOI df.

Parameters
----------
by: str | list[str]
Splitting criteria

"""
self.aois = self.aois.partition_by(by=by, as_dict=False)


def from_file(
aoi_path: str | Path,
Expand Down
31 changes: 31 additions & 0 deletions tests/unit/stimulus/text_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,34 @@ def test_text_stimulus_unsupported_format():
expected = 'unsupported file format ".pickle".Supported formats are: '\
'[\'.csv\', \'.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',
Copy link
Contributor

@dkrako dkrako Oct 24, 2024

Choose a reason for hiding this comment

The 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: toy_text_1_1_aoi_sep

),
],
)
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.split_aois_by(by='line_idx')
assert len(aois_df.aois) == 2
Loading