Skip to content

feat: raise helpful error message for existing event properties #1046

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

Open
wants to merge 35 commits into
base: main
Choose a base branch
from

Conversation

xiaotiansu
Copy link
Contributor

@xiaotiansu xiaotiansu commented Mar 14, 2025

Hi, my first commit of code, hope I'm doing it correctly :)

Fixes #

Implemented changes

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

  • raise ValueError if the computed property already exists in the event dataframe

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?

Please describe the tests that you ran to verify your changes.
Provide instructions so we can reproduce.
Please also list any relevant details for your test configuration

  • passed 579 tests for dataset: tox -e py39 -- tests/unit/events

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

@github-actions github-actions bot added the enhancement New feature or request label Mar 14, 2025
Copy link

codecov bot commented Mar 14, 2025

Codecov Report

Attention: Patch coverage is 94.44444% with 2 lines in your changes missing coverage. Please review.

Project coverage is 99.94%. Comparing base (6245bbf) to head (3d410dd).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/pymovements/dataset/dataset.py 50.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##              main    #1046      +/-   ##
===========================================
- Coverage   100.00%   99.94%   -0.06%     
===========================================
  Files           84       86       +2     
  Lines         3654     3722      +68     
  Branches       646      652       +6     
===========================================
+ Hits          3654     3720      +66     
- Misses           0        1       +1     
- Partials         0        1       +1     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

Great! Thank you so much for your initiative!

Some of the tests don't pass because event_properties can also be a dict.
I posted a short proposal on how to change your code accordingly.

You will also need to add at least two test cases here:

@pytest.mark.parametrize(
('property_kwargs', 'exception', 'msg_substrings'),
[
pytest.param(
{'event_properties': 'foo'},
pm.exceptions.InvalidProperty,
('foo', 'invalid', 'valid', 'peak_velocity'),
id='invalid_property',
),
],
)
def test_event_dataframe_add_property_raises_exceptions(

One for the ValueError and one for the TypeError.

@dkrako dkrako mentioned this pull request Mar 17, 2025
19 tasks
@xiaotiansu xiaotiansu requested a review from dkrako March 24, 2025 10:34
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.

Great, this looks quite good already, but please make sure that all tests pass.

There are a few syntax errors left in your code, that's why the tests fail. The error messages in the test runs point you to the error: https://github.com/aeye-lab/pymovements/actions/runs/14032843428?pr=1046

@SiQube
Copy link
Member

SiQube commented Mar 24, 2025

this PR gets screwed over by autopep8, see hhatto/autopep8#765 for the issue. maybe we should deactivate autopep8?

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.

Great, finally linting and all tests pass! Was a bit complicated with all the type unions. There seemed to be a confusion between EventProcessor and EventGazeProcessor, so I helped out a bit to not burden you with these details.

The last thing what's missing now is covering all the new exceptions with tests.

event_property_names = [property[0] for property in processor.event_properties]
existing_columns = set(self.events[0].columns) & set(event_property_names)
if existing_columns:
raise ValueError(
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not covered by any tests anymore. Please add a test here:

@pytest.mark.parametrize(
('property_kwargs', 'exception', 'msg_substrings'),
[
pytest.param(
{'event_properties': 'foo'},
pm.exceptions.InvalidProperty,
('foo', 'invalid', 'valid', 'peak_velocity'),
id='invalid_property',
),
],
)
def test_event_dataframe_add_property_raises_exceptions(
gaze_dataset_configuration,
property_kwargs,
exception,
msg_substrings,
):

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @xiaotiansu maybe you overlooked this, there's one final test needed to get full coverage.

After adding the test we'll be ready to merge. Thanks for all the work so far!

@xiaotiansu xiaotiansu changed the title feat: raise helpful error message for existing event properties (#1041) feat: raise helpful error message for existing event properties Mar 26, 2025
@dkrako dkrako linked an issue Mar 28, 2025 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

raise helpful error message if event property column already exists
3 participants