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

Add basic support for linting / format🐍 #26

Merged
merged 2 commits into from
Feb 19, 2024

Conversation

KarelZe
Copy link
Contributor

@KarelZe KarelZe commented Feb 11, 2024

This PR adds basic support for linting/formatting based on ruff, as discussed in #23 .

A minimal rule set (see pyproject.toml) is appied to keep diff in PR small. More rules can be added from https://beta.ruff.rs/docs/rules/. Currently, I isort is used for sorting imports, pep8-naming N for naming conventions, NPY for Numpy best practices, and RUF for ruff-specific rules. You can also ignore rules, either in the pyproject.toml, as done for all lower-case variable names, which contradicts matrix naming conventions or on the code level e.g., # noqa: N802, as done in kernel_estimator.py for function_names due to the same reason.

We should verify that the changes from refactoring / update of numpy random number generation, didn't break anything. Will keep this as WIP until I've performed some tests 🤓

@iancovert Do you want additional rules / different configurations?

@KarelZe KarelZe marked this pull request as draft February 11, 2024 07:23
@iancovert
Copy link
Owner

All the ruff related changes look good to me!

For the random number generation, it looks like this was in just a couple places, right? I think the refactoring in iterated_estimator.py makes sense, but it could be better add a random_state argument to the constructor with a default argument. And the change in utils.py might be a problem, because the sample_subset_feature helper function would now return the same values every time. I think the correct solution is to make the random state an argument to sample_subset_feature, and adjust the two places where it's currently used (iterated_estimator.py and sign_estimator.py) to use their self.rng.

@KarelZe
Copy link
Contributor Author

KarelZe commented Feb 15, 2024

@iancovert Thanks for your feedback. I noticed the same behaviour for sample_subset_feature(...). This needs a fix. 🐛 Will also set random_state as a default argument.

Will update this PR and answer to #24 later this week. 👍

@KarelZe
Copy link
Contributor Author

KarelZe commented Feb 17, 2024

@iancovert After thinking about it again, I decided to revert my changes with regard to numpy.random and disable the rule NPY002, as it could affect the results estimated by the package. I feel like such a change should not be introduced in a linter/formatter PR and rather be adressed separately. Hope this is fine. 😊

I recommend to register the repo to https://pre-commit.ci/ (official pre-commit ci of pre-commit) to keep the hooks up-to-date.

From my point of view, PR is ready for review. 🫡

@KarelZe KarelZe marked this pull request as ready for review February 17, 2024 12:05
@KarelZe KarelZe changed the title [WIP] Add basic support for linting / format🐍 Add basic support for linting / format🐍 Feb 17, 2024
@iancovert
Copy link
Owner

Good call, that makes sense to me. I'll go ahead and merge the PR. Thanks again for adding this!

@iancovert iancovert merged commit 2c98a28 into iancovert:master Feb 19, 2024
@KarelZe
Copy link
Contributor Author

KarelZe commented Feb 19, 2024

@iancovert Thanks for merging the PR. I might pick up work on a PR focusing on migrating to numpy 2.X (https://numpy.org/devdocs/numpy_2_0_migration_guide.html) and RNG, once I find the time.

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.

2 participants