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

Split aoi dataframe by chosen criteria #879

wants to merge 15 commits into from

Conversation

izaskr
Copy link
Collaborator

@izaskr izaskr commented Oct 24, 2024

Description

The change introduces a splitting function for the aoi dataframe in the TextStimulus class. This allows for the aoi file to be split according to some criteria, e.g. pages.

Implemented changes

Insert a description of the changes implemented in the pull request.

  • Add a method to split the aoi dataframe by some criteria into a list of dataframes.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change is or requires a documentation update

How Has This Been Tested?

  • Test test_text_stimulus_splitting checks if the number of resulting dataframes equals the expected length.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • I have checked my code and corrected any misspellings

Copy link

codecov bot commented Oct 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (2d48f2f) to head (652d0b0).

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #879   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           74        74           
  Lines         3372      3374    +2     
  Branches       594       594           
=========================================
+ Hits          3372      3374    +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@dkrako dkrako left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if the Textstimulus.aois attribute should change types.

Before calling split_aois_by() the type is pl.DataFrame afterwards it's a list of dataframes. It would be nice to have just one type for the aois field.

Also, when you just split the data, you won't know the splitting criteria anymore, i.e. you won't know which dataframe is which belonging to which page.

Can you include a short code example where and how you expect the method to be used? It is probably part of a greater plan.

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

Copy link
Contributor

@dkrako dkrako left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a few things about the testing and we're ready to go!

tests/unit/stimulus/text_test.py Show resolved Hide resolved
Copy link
Contributor

@dkrako dkrako left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks a lot! just some more details on the tests and we're ready to merge

tests/unit/stimulus/text_test.py Outdated Show resolved Hide resolved
tests/unit/stimulus/text_test.py Outdated Show resolved Hide resolved
Copy link
Contributor

@dkrako dkrako left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @izaskr for your work!

Unfortunately I have missed a crucial line during my review two weeks ago as the split() method doesn't return list[TextStimulus].

I have posted a small code snippet how to change the logic accordingly, shouldn't be much work.

This change would also need an additional test: please check that all fields (e.g. aoi_column, width_column, etc.) in the returned TextStimulus splits are equal to the original TextStimulus.

list[TextStimulus]
A list of TextStimulus objects.
"""
return self.aois.partition_by(by=by, as_dict=False)
Copy link
Contributor

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 of TextStimulus objects.

You should probably do something like this:

return [
    TextStimulus(
        aois=df,
        aoi_column=self.aoi_column,
        width_column=self.width_column,
        ...,  # remaining fields
        page_column=self.page_column,
    )
    for df in self.aois.partition_by(by=by, as_dict=False)
]

Copy link
Contributor

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.

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

Successfully merging this pull request may close these issues.

3 participants