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

Applying linting to notebooks #445

Merged
merged 3 commits into from
Oct 10, 2024

Conversation

CompRhys
Copy link
Contributor

@CompRhys CompRhys commented Oct 7, 2024

Updates to use a more recent version of ruff from astral rather than the initial action written for early version before astral was formed around ruff. Applies ruff to notebooks inside the repo.

Added nbstripout action to remove unnecessary information from the tutorial notebooks to reduce the diffs that are expected when run by different users

@jduerholt
Copy link
Contributor

Hi @CompRhys,

thanks for your PR. I am unsure about the nbstripout, as I find it nice to have the outputs in the notebooks for didactic purposes, especially as we link then sometimes also directly into mkdocs. @bertiqwerty: what do you think?

It seems that you are much more experienced with Ruff than me, what do you think of using Ruff also for formatting and get rid of black? https://docs.astral.sh/ruff/formatter/

Would you mind to implement this?

Best,

Johannes

@bertiqwerty
Copy link
Contributor

Hi @CompRhys,

thanks for your PR. I am unsure about the nbstripout, as I find it nice to have the outputs in the notebooks for didactic purposes, especially as we link then sometimes also directly into mkdocs. @bertiqwerty: what do you think?

It seems that you are much more experienced with Ruff than me, what do you think of using Ruff also for formatting and get rid of black? https://docs.astral.sh/ruff/formatter/

Would you mind to implement this?

Best,

Johannes

Hi all,

I am in favor of using a new Ruff-version and also of using ruff format instead of Black.

About the notebooks, I agree with Johannes that it is good to show the output.

@CompRhys
Copy link
Contributor Author

CompRhys commented Oct 8, 2024

Okay! sure can update the linting actions to make use of the pre-commit settings such that there's only one place where the ruff version is controlled. I have removed all the obvious # noqa: <xyz> and # type: ignore comments and then will go back and try fix/re-add where necessary for pyright. Switched to using the pyright ci action suggested by microsoft https://github.com/microsoft/pyright/blob/main/docs/ci-integration.md. When running the notebooks they're spammed with warnings about EI vs LogEI, I will rerun to generate the outputs before this gets merged but first do you guys agree that it makes sense to swap all the defaults/tutorials to use LogEI? #444 and https://github.com/Radical-AI/bofire/tree/logei-defaults

@CompRhys CompRhys force-pushed the lint-notebooks branch 2 times, most recently from 45a49db to 83e9662 Compare October 8, 2024 17:27
@CompRhys
Copy link
Contributor Author

CompRhys commented Oct 8, 2024

@jduerholt @bertiqwerty I have done the above updates and rebased so that we kept the outputs that were there before (I have kept the nbstripout action as is cleans up some user specific metadata but configured it to keep the outputs). Testing on my local branch there are now some tests that are failing, I am looking at these now and will let you know when I have fixed them such that they can be re run here and maybe this can be merged

- name: Run pre-commit
run: pre-commit run --all-files --show-diff-on-failure

- name: Pyright
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ideally we could move this inside the pre-commit action but there appear to be issues with getting pyright to work with pre-commit

@CompRhys
Copy link
Contributor Author

CompRhys commented Oct 8, 2024

I think the tests that were failing are flaky, here they passed but the same code being tested on my fork failed.

@jduerholt
Copy link
Contributor

I think the tests that were failing are flaky, here they passed but the same code being tested on my fork failed.

Yeah, there are some flaky tests, espececially in the DoE module, but @Osburg is currently working on a a refactoring of the whole module which will hopefully also cure the flaky tests ;)

Thanks for the PR. @bertiqwerty, I think it makes sense that you also have a look on it as most of the pipelines and checks were implemented by you.

@jduerholt
Copy link
Contributor

One think that catched my attention:

What do you think of adding a pyright section to pyproject.toml (https://github.com/microsoft/pyright/blob/main/docs/configuration.md). There we could then for example define that it is not throwing an error when one overrites variables or methods, which would significantly reduce the number of type: ignore in the code (https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportIncompatibleMethodOverride).

@bertiqwerty
Copy link
Contributor

One think that catched my attention:

What do you think of adding a pyright section to pyproject.toml (https://github.com/microsoft/pyright/blob/main/docs/configuration.md). There we could then for example define that it is not throwing an error when one overrites variables or methods, which would significantly reduce the number of type: ignore in the code (https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportIncompatibleMethodOverride).

I think we should keep the type ignores because incompatible override is not very nice and at least we should mark it as such.

@jduerholt
Copy link
Contributor

I think we should keep the type ignores because incompatible override is not very nice and at least we should mark it as such.

Hmm, but we do it a lot in the data models (to guarantee proper serialization and deserialization using the type attribute), just have a look at the new type: ignore added in this PR ...

@bertiqwerty
Copy link
Contributor

bertiqwerty commented Oct 9, 2024

This just means that we have a lot of type violations because a Literal["something"] is not a str (if it were a str you could assign any value of type str which you cannot). Maybe we should replace type: str by type: Any in the base class because the derived types are never str but always some kind of Literal["something"]. I have not found a way to restrict this to any kind of Literal, hence just Any.

@jduerholt
Copy link
Contributor

Hmm, ok. Then we keep it as it is currently and perhaps fix this in a later PR.

@CompRhys
Copy link
Contributor Author

CompRhys commented Oct 9, 2024

So when looking at pyright I removed them all and then added all the ones that created issues back and then added a bunch of extra ones where it was now complaining. I wasn't really sure as to why the changes I made created new typinging issues as I only manually changed one bit of logic to cast an dataframe to numpy before calling ravel due to an incoming pandas deprecation.

If you guys are happy with this PR as it is I think it would be good to merge and then this pyright stuff and then also changing the tutorials to follow the LogEI best practice can be done in another PR(s)

@jduerholt
Copy link
Contributor

I think, that there is a new pyright version, which is flagging more than the old one, that we have used so far ....

@CompRhys
Copy link
Contributor Author

CompRhys commented Oct 9, 2024

I pinned the version in the action to the version that was in the setup.py file previously so for the action I don't think so but perhaps as I was fixing locally I probably am using the most recent version due to pylance which might be the cause

Copy link
Contributor

@jduerholt jduerholt left a comment

Choose a reason for hiding this comment

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

Thanks for this effort @CompRhys . Looks good to me! After @bertiqwerty had a look we can merge it ;) Best, Johannes

Copy link
Contributor

@bertiqwerty bertiqwerty 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 @CompRhys. Looks good to me!

@bertiqwerty bertiqwerty merged commit 27e4693 into experimental-design:main Oct 10, 2024
9 checks passed
@CompRhys CompRhys deleted the lint-notebooks branch October 11, 2024 17:45
@CompRhys CompRhys mentioned this pull request Nov 27, 2024
@CompRhys CompRhys mentioned this pull request Nov 27, 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.

3 participants