Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Bknight regex migration #551

Merged
merged 8 commits into from
Jul 16, 2024

Conversation

b-knight
Copy link
Contributor

@b-knight b-knight commented Jul 14, 2024

Extension of initial PR.
This pull request primarily involves changes to the pyfixest package, specifically the feols_.py and dev_utils.py files. The changes are aimed at improving code quality and readability, as well as introducing a new utility function to extract variable levels.

Code quality and readability improvements:

New utility function and its usage:

  • pyfixest/utils/dev_utils.py: Added a new utility function _extract_variable_level to extract variable and level from a given string. This function uses regular expressions to match patterns and extract the required information. If the patterns are not found, a ValueError is raised.
  • pyfixest/estimation/feols_.py: Replaced the regular expression matching and extraction logic in the fixef method with a call to the new _extract_variable_level function. This change simplifies the code and improves readability.
  • tests/test_predict_resid_fixef.py: Added a new test case test_extract_variable_level to verify the correct extraction of lists, floats, and integers by the _extract_variable_level function.

Other changes:

@b-knight b-knight force-pushed the bknight_regex_migration branch from 5380439 to 1b25bba Compare July 14, 2024 23:05
Copy link
Member

@s3alfisc s3alfisc left a comment

Choose a reason for hiding this comment

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

Happy to merge after the unit tests run succesfully!

@all-contributors please add @b-knight for code.


variable = c_match.group(1)
level = t_match.group(1)
return 'C(' + variable + ')', level[0 : level.rfind("]")]
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we want to drop the C(...) wrapper here? Then we could also drop it further below?

Copy link
Member

Choose a reason for hiding this comment

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

Actually, let's do this in a separate PR, as this clashes with Apoorva's PR #553. Likely easier to merge both as is and then adjust =)

Copy link
Member

Choose a reason for hiding this comment

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

On this part: level[0 : level.rfind("]")] - did you encountered a string where it was needed because the regex did not handle it by itself, or is this just to be on the safe side?

Copy link
Contributor Author

@b-knight b-knight Jul 15, 2024

Choose a reason for hiding this comment

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

The regex matching was leading to values like 'f3' whereas the unit test was expecting 'C(f3)' so this wrapper is necessary to clear the unit test. Similarly, the initial matching was outputting values such as "['ios'" and "['ios', 'android'" with the rightmost bracket missing.

Copy link

codecov bot commented Jul 15, 2024

Codecov Report

Attention: Patch coverage is 95.23810% with 1 line in your changes missing coverage. Please review.

Files Coverage Δ
pyfixest/estimation/feols_.py 90.64% <100.00%> (ø)
tests/test_predict_resid_fixef.py 92.80% <100.00%> (+0.49%) ⬆️
pyfixest/utils/dev_utils.py 84.81% <90.00%> (ø)

... and 27 files with indirect coverage changes

@s3alfisc s3alfisc merged commit d726fad into py-econometrics:master Jul 16, 2024
7 checks passed
@s3alfisc
Copy link
Member

@all-contributors please add @b-knight for code

Copy link
Contributor

@s3alfisc

This project's configuration file has malformed JSON: .all-contributorsrc. Error:: Unexpected string in JSON at position 3438

@s3alfisc
Copy link
Member

@all-contributors please add @b-knight for code

Copy link
Contributor

@s3alfisc

I've put up a pull request to add @b-knight! 🎉

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

Successfully merging this pull request may close these issues.

2 participants