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

Adding literals to feols and fepois api's #680

Merged
merged 11 commits into from
Nov 2, 2024

Conversation

marcandre259
Copy link
Contributor

Reference to #671. Pretty literal interpretation. Added a small validate_literal_argument function, taken from the predict method of Feols (assumption is it may be used elsewhere also).

@marcandre259
Copy link
Contributor Author

pre-commit.ci autofix

Copy link

codecov bot commented Oct 27, 2024

Codecov Report

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

Files with missing lines Patch % Lines
pyfixest/estimation/literals.py 83.33% 2 Missing ⚠️
Flag Coverage Δ
core-tests 77.73% <90.47%> (-0.06%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
pyfixest/did/estimation.py 96.55% <100.00%> (+0.06%) ⬆️
pyfixest/did/lpdid.py 94.62% <100.00%> (+0.05%) ⬆️
pyfixest/estimation/__init__.py 100.00% <100.00%> (ø)
pyfixest/estimation/estimation.py 95.91% <100.00%> (+0.04%) ⬆️
pyfixest/estimation/feols_.py 83.06% <100.00%> (+0.07%) ⬆️
pyfixest/estimation/feols_compressed_.py 83.43% <100.00%> (ø)
pyfixest/estimation/fepois_.py 87.20% <100.00%> (-1.90%) ⬇️
pyfixest/estimation/literals.py 83.33% <83.33%> (ø)

... and 1 file with indirect coverage changes

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.

Looks very good to me. Will leave this open until tomorrow to see if @leostimpfle has some thoughs, and then merge after we get his feedback. Thanks @marcandre259!

Copy link
Collaborator

@leostimpfle leostimpfle left a comment

Choose a reason for hiding this comment

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

Thanks @marcandre259 ! Looks good to me overall, just have a few comments

pyfixest/estimation/literals.py Outdated Show resolved Hide resolved
pyfixest/estimation/literals.py Show resolved Hide resolved
pyfixest/estimation/literals.py Outdated Show resolved Hide resolved
pyfixest/estimation/literals.py Outdated Show resolved Hide resolved
@marcandre259
Copy link
Contributor Author

pre-commit.ci autofix

@s3alfisc
Copy link
Member

pre-commit.ci autofix

@s3alfisc
Copy link
Member

It's a little bit annoying, but whenever the autofix corrects code, one has to run it again to pass the checks (because the previous did not pass as it triggered the fix) @marcandre259

@s3alfisc
Copy link
Member

Looks like mypy is complaining about the use of the _LiteralGenericAlias:

pyfixest/estimation/literals.py:1: error: Module "typing" has no attribute "_LiteralGenericAlias"  [attr-defined]

Maybe we can simply check for a literal type via smth like

    if get_origin(literal) is not Literal:
        raise TypeError("Expected a Literal type as the second argument")

?

I would not overthink this as it's in the end behavior we would (hopefully) catch in a review process?

@s3alfisc
Copy link
Member

s3alfisc commented Oct 30, 2024

Another thing I oversaw in my initial review - feols and fepois check input types in

def _estimation_input_checks(

Maybe we could update them to use the Literal validation function whenever relevant?

@marcandre259
Copy link
Contributor Author

Looks like mypy is complaining about the use of the _LiteralGenericAlias:

pyfixest/estimation/literals.py:1: error: Module "typing" has no attribute "_LiteralGenericAlias"  [attr-defined]

Maybe we can simply check for a literal type via smth like

    if get_origin(literal) is not Literal:
        raise TypeError("Expected a Literal type as the second argument")

?

I would not overthink this as it's in the end behavior we would (hopefully) catch in a review process?

Hi @s3alfisc,

Indeed, I'll modify it with a similar check. I did notice that Literal was not really a type without being specific Literal["..."], at least when trying out type(literal) is Literal. But maybe it works with get_origin then?

@marcandre259
Copy link
Contributor Author

pre-commit.ci autofix

@s3alfisc
Copy link
Member

s3alfisc commented Nov 2, 2024

Thanks @marcandre259 ! This looks good to me know =)

@s3alfisc s3alfisc merged commit a5d735d into py-econometrics:master Nov 2, 2024
8 checks passed
@s3alfisc
Copy link
Member

s3alfisc commented Nov 2, 2024

Just fyi @marcandre259 , the test failures in the main branch stem back from changes to the actions wfl I merged yesterday and are completely unrelated to this PR =)

@marcandre259 marcandre259 deleted the marc-literals branch November 2, 2024 17:43
marcandre259 added a commit to marcandre259/pyfixest that referenced this pull request Nov 13, 2024
* Adding literals to feols and fepois api's

* Adding docstring

* Fix lpdid argument vcov

* literal type

* hunting vcov literals

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Changes refering to initial review

* Whac-a-mole based development

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Check length of valid_types instead looking for generic literal type

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
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