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

[ENH] Add TsGroup.merge_group method #275

Merged
merged 19 commits into from
May 21, 2024
Merged

Conversation

qian-chu
Copy link
Contributor

@qian-chu qian-chu commented May 6, 2024

Implements #251.

Added a static method TsGroup.merge_group() as well as a tsgroup.merge(). Documentation with examples is included as well.

@qian-chu qian-chu requested a review from gviejo as a code owner May 6, 2024 23:48
Copy link
Collaborator

@BalzaniEdoardo BalzaniEdoardo left a comment

Choose a reason for hiding this comment

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

Hi Qian-Chu.
Thanks for your contribution, this is great. Very neat docstrings, and well thought out method. I would ask you a couple of edits before we can merge this:

  1. Run linters and formatters
black pynapple/core/ts_group.py
isort --check pynapple --profile black
flake8 pynapple --max-complexity 10    
  1. Add tests of your method hitting all the exceptions. you can use @pytest.mark.parametrize to loop over multiple tsgroup and kwargs configs.

Cheers,
Edoardo

def merge(self, *tsgroups, reset_index=False, reset_time_support=False, ignore_metadata=False):
"""
Merge the TsGroup object with other TsGroup objects
See `TsGroup.merge_group` for more details
Copy link
Collaborator

Choose a reason for hiding this comment

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

since this is probably the most user facing method, I would have a nice numpydoc docstring here too!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good suggestion. Could you offer some tips on how to do so while reducing redundancy?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I suggest to move the detailed docstrings from the merge_group to the merge.
In merge_group keep the same initial paragraph describing the method, the parameters, and the returns sections. I'll add a See Also section that points to merge.

qian-chu and others added 3 commits May 7, 2024 18:21
Co-authored-by: Edoardo Balzani <[email protected]>
Co-authored-by: Edoardo Balzani <[email protected]>
Co-authored-by: Edoardo Balzani <[email protected]>
@qian-chu
Copy link
Contributor Author

qian-chu commented May 7, 2024

Hi Qian-Chu. Thanks for your contribution, this is great. Very neat docstrings, and well thought out method. I would ask you a couple of edits before we can merge this:

  1. Run linters and formatters
black pynapple/core/ts_group.py
isort --check pynapple --profile black
flake8 pynapple --max-complexity 10    
  1. Add tests of your method hitting all the exceptions. you can use @pytest.mark.parametrize to loop over multiple tsgroup and kwargs configs.

Cheers, Edoardo

Will do! Thanks for reviewing and providing feedback!

@qian-chu qian-chu requested a review from BalzaniEdoardo May 20, 2024 13:21
Copy link
Collaborator

@BalzaniEdoardo BalzaniEdoardo left a comment

Choose a reason for hiding this comment

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

Good job! The only thing left to do is basically imporoving the docstrings of merge and then it is good to go!

def merge(self, *tsgroups, reset_index=False, reset_time_support=False, ignore_metadata=False):
"""
Merge the TsGroup object with other TsGroup objects
See `TsGroup.merge_group` for more details
Copy link
Collaborator

Choose a reason for hiding this comment

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

I suggest to move the detailed docstrings from the merge_group to the merge.
In merge_group keep the same initial paragraph describing the method, the parameters, and the returns sections. I'll add a See Also section that points to merge.

Comment on lines 760 to 762
nap.TsGroup.merge_group(ts_group, str, dict)
assert str(e_info.value) == f"Input at positions {[2, 3]} are not TsGroup!"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
with pytest.raises(TypeError) as e_info:
nap.TsGroup.merge_group(ts_group, str, dict)
assert str(e_info.value) == f"Input at positions {[2, 3]} are not TsGroup!"
with pytest.raises(TypeError, match=f"Input at positions {[2, 3]} are not TsGroup!"):
nap.TsGroup.merge_group(ts_group, str, dict)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Interestingly, this change gave a perplexing error

E           AssertionError: Regex pattern did not match.
E            Regex: 'Input at positions [2, 3] are not TsGroup!'
E            Input: 'Input at positions [2, 3] are not TsGroup!'
E            Did you mean to `re.escape()` the regex?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed with replacing {[2, 3]} with (.*)

Co-authored-by: Edoardo Balzani <[email protected]>
@coveralls
Copy link

coveralls commented May 20, 2024

Pull Request Test Coverage Report for Build 9151076635

Details

  • 38 of 40 (95.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.3%) to 83.408%

Changes Missing Coverage Covered Lines Changed/Added Lines %
pynapple/core/ts_group.py 38 40 95.0%
Totals Coverage Status
Change from base Build 9117465489: 0.3%
Covered Lines: 2473
Relevant Lines: 2887

💛 - Coveralls

Copy link
Collaborator

@BalzaniEdoardo BalzaniEdoardo left a comment

Choose a reason for hiding this comment

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

A couple of fixes on how the docstrings are rendered by mkdocs

qian-chu and others added 2 commits May 20, 2024 16:06
Co-authored-by: Edoardo Balzani <[email protected]>
Co-authored-by: Edoardo Balzani <[email protected]>
@BalzaniEdoardo BalzaniEdoardo changed the base branch from main to dev May 20, 2024 14:08
@BalzaniEdoardo
Copy link
Collaborator

I re-based this into the dev branch, but up to @gviejo.

@qian-chu this is definitely going to be in main but we usually have merge first into dev, so that we have some time to try out the new feature.

@qian-chu
Copy link
Contributor Author

Many thanks @BalzaniEdoardo for all the suggestions. I just moved the examples from merge_group() to merge(). Feel free to take a look. Not sure how to implement See Also merge_group() as a link but I did leave a mentioning there :)

I have no problem with dev vs main! Take your time.

@BalzaniEdoardo
Copy link
Collaborator

Many thanks @BalzaniEdoardo for all the suggestions. I just moved the examples from merge_group() to merge(). Feel free to take a look. Not sure how to implement See Also merge_group() as a link but I did leave a mentioning there :)

I have no problem with dev vs main! Take your time.

Great, I'll add the link, no worries!

Copy link

codecov bot commented May 21, 2024

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

ℹ️ You can also turn on project coverage checks and project coverage reporting on Pull Request comment

Thanks for integrating Codecov - We've got you covered ☂️

@gviejo
Copy link
Contributor

gviejo commented May 21, 2024

Great PR. Thank you @qian-chu

@gviejo gviejo merged commit ff231e0 into pynapple-org:dev May 21, 2024
12 checks passed
@gviejo gviejo mentioned this pull request May 21, 2024
Merged
@qian-chu qian-chu deleted the merge_tsgroup branch May 21, 2024 21:40
@gviejo gviejo mentioned this pull request May 22, 2024
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.

4 participants