diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 520892d..03a3c2d 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -31,20 +31,16 @@ jobs: name: Check code style runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Set up Python 3.8 - uses: actions/setup-python@v2 + - uses: actions/checkout@v4 + - name: Set up Python 3.11 + uses: actions/setup-python@v4 with: - python-version: 3.8 + python-version: 3.11 - name: Install dependencies run: | - pip install flake8 pydocstyle - - name: Lint with flake8 + python -m pip install --upgrade pip + pip install ruff + - name: Lint with ruff run: | - # stop the build if there are Python syntax errors or undefined names - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics - # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - flake8 . --count --max-complexity=10 --max-line-length=80 --statistics - - name: Check doc style with pydocstyle - run: pydocstyle + ruff check --output-format=github . diff --git a/README.md b/README.md index 823291d..d9f6cea 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ - Create a branch called `my_user_name` using `git checkout -b my_user_name` - Make the changes to complete the assignment. You have to modify the files that contain `questions` in their name. Do not modify the files that start with `test_`. - Check locally that your solution meet the test by running `pytest` from the root of the repo. You may need to install `pytest` using `pip` or `conda`. - - Check the code formating for your solution using `flake8`. You may need to install `flake8` using `pip` or `conda`. + - Check the code formating for your solution using `ruff`. You may need to install `ruff` using `pip` or `conda`. - Open the pull request on GitHub: - Create a commit with `git add -u` and `git commit -m "UP my solution"` - Push your branch on your fork: `git push -u origin my_user_name` diff --git a/numpy_questions.py b/numpy_questions.py index 07a10c1..25674ee 100644 --- a/numpy_questions.py +++ b/numpy_questions.py @@ -15,6 +15,7 @@ This will be enforced with `flake8`. You can check that there is no flake8 errors by calling `flake8` at the root of the repo. """ + import numpy as np @@ -39,9 +40,11 @@ def max_index(X): """ i = 0 j = 0 - + if not isinstance(X, np.ndarray) or X.ndim != 2: + raise ValueError() # TODO - + max_val = np.max(X) + i, j = np.where(X == max_val) return i, j @@ -64,4 +67,15 @@ def wallis_product(n_terms): """ # XXX : The n_terms is an int that corresponds to the number of # terms in the product. For example 10000. - return 0. + if n_terms == 0: + return 2 + + product = 1 + for i in range(1, n_terms + 1): + product *= (4 * i**2) / (4 * i**2 - 1) + + + + + + return 2 * product