From 8d27b88b898fe458d5f4d55cbe58b84e9afde1a3 Mon Sep 17 00:00:00 2001 From: Jaffar Hussein Date: Mon, 16 Dec 2024 18:34:25 +0100 Subject: [PATCH 1/2] UP my solution --- numpy_questions.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/numpy_questions.py b/numpy_questions.py index 07a10c1..5bb777d 100644 --- a/numpy_questions.py +++ b/numpy_questions.py @@ -39,9 +39,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 +66,9 @@ 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 From 12a4eef3848f369962a93a9122df0c1a1af563d0 Mon Sep 17 00:00:00 2001 From: Jaffar Hussein Date: Mon, 16 Dec 2024 20:05:53 +0100 Subject: [PATCH 2/2] Updates GitHub Actions to use Python 3.11 and ruff for linting; update README --- .github/workflows/python-app.yml | 20 ++++++++------------ README.md | 2 +- numpy_questions.py | 9 ++++++++- 3 files changed, 17 insertions(+), 14 deletions(-) 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 5bb777d..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 @@ -68,7 +69,13 @@ def wallis_product(n_terms): # terms in the product. For example 10000. if n_terms == 0: return 2 + product = 1 - for i in range(1, n_terms+1): + for i in range(1, n_terms + 1): product *= (4 * i**2) / (4 * i**2 - 1) + + + + + return 2 * product