Skip to content

Commit bbe57f0

Browse files
authored
Merge branch 'master' into issue/logistic_regression
2 parents acd2f67 + cc6c9e4 commit bbe57f0

275 files changed

Lines changed: 16269 additions & 2280 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.devcontainer/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ This is **Devcontainer** configuration to provide a consistent development envir
1313

1414
## Usage
1515

16-
1. Install [**Docker** ](https://www.docker.com/get-started/) and [**Visual Studio Code**](https://code.visualstudio.com/)
16+
1. Install [**Docker**](https://www.docker.com/get-started/) and [**Visual Studio Code**](https://code.visualstudio.com/)
1717
2. Install the **Remote - Containers** extension in VS Code
1818

1919
- Do `CTRL+P`, paste this command and press `Enter`
2020

2121
```shell
2222
ext install ms-vscode-remote.remote-containers
2323
```
24+
2425
3. Open this repository in VS Code
2526
4. When prompted, click **"Reopen in Container"**
2627
5. Wait for the environment to build and initialize

.devcontainer/devcontainer.json

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
{
22
"name": "Python 3",
3-
"build": {
4-
"dockerfile": "Dockerfile",
5-
"context": "..",
6-
"args": {
7-
// Update 'VARIANT' to pick a Python version: 3, 3.11, 3.10, 3.9, 3.8
8-
// Append -bullseye or -buster to pin to an OS version.
9-
// Use -bullseye variants on local on arm64/Apple Silicon.
10-
"VARIANT": "3.13-bookworm"
11-
}
12-
},
133

14-
"postCreateCommand": "zsh .devcontainer/post_install",
4+
// Use a prebuilt dev container image instead of building from a local
5+
// Dockerfile. The repo migrated its dependencies to pyproject.toml, so the
6+
// old Dockerfile's `COPY requirements.txt` step no longer had a file to copy
7+
// and the image build failed. The upstream images already ship Python + a
8+
// full toolchain, so pulling one is both faster and less to maintain.
9+
//
10+
// This repo tracks the latest-and-greatest CPython on the newest stable
11+
// Debian. Images are published per CPython minor version on Debian 13
12+
// "Trixie" (3.11-trixie ... 3.14-trixie); bump this to the newest available
13+
// when a new stable CPython ships.
14+
// NOTE: these images do not publish free-threaded (`t`) variants, so 3.14t
15+
// cannot be selected via the tag alone -- but the repo's `.python-version`
16+
// pins 3.14t, and `uv run`/`uv sync` in the container honor it, so uv gives
17+
// contributors free-threaded 3.14t regardless of the base tag.
18+
"image": "mcr.microsoft.com/devcontainers/python:latest",
19+
20+
// Install the tools post_install and CI expect (pre-commit + ruff), plus uv
21+
// for the free-threaded workflow above, then run the existing setup script.
22+
"postCreateCommand": "pipx install pre-commit ruff uv && zsh .devcontainer/post_install",
1523

1624
// Configure tool-specific properties.
1725
"customizations": {
@@ -20,26 +28,30 @@
2028
// Set *default* container specific settings.json values on container create.
2129
"settings": {
2230
"python.defaultInterpreterPath": "/usr/local/bin/python",
23-
"python.linting.enabled": true,
24-
"python.formatting.blackPath": "/usr/local/py-utils/bin/black",
25-
"python.linting.mypyPath": "/usr/local/py-utils/bin/mypy",
31+
// Formatting/linting is handled by Ruff (matches pre-commit and CI).
32+
"editor.formatOnSave": true,
33+
"[python]": {
34+
"editor.defaultFormatter": "charliermarsh.ruff",
35+
"editor.codeActionsOnSave": {
36+
"source.fixAll": "explicit",
37+
"source.organizeImports": "explicit"
38+
}
39+
},
2640
"terminal.integrated.defaultProfile.linux": "zsh"
2741
},
2842

2943
// Add the IDs of extensions you want installed when the container is created.
3044
"extensions": [
3145
"ms-python.python",
32-
"ms-python.vscode-pylance"
46+
"ms-python.vscode-pylance",
47+
"charliermarsh.ruff"
3348
]
3449
}
3550
},
3651

3752
// Use 'forwardPorts' to make a list of ports inside the container available locally.
3853
// "forwardPorts": [],
3954

40-
// Use 'postCreateCommand' to run commands after the container is created.
41-
// "postCreateCommand": "pip3 install --user -r requirements.txt",
42-
4355
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
4456
"remoteUser": "vscode"
4557
}

.github/dependabot.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ updates:
66
directory: "/"
77
schedule:
88
interval: "daily"
9+
cooldown:
10+
default-days: 7

.github/pull_request_template.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1-
### Describe your change:
2-
3-
1+
### Describe your change
42

53
* [ ] Add an algorithm?
64
* [ ] Fix a bug or typo in an existing algorithm?
75
* [ ] Add or change doctests? -- Note: Please avoid changing both code and tests in a single pull request.
86
* [ ] Documentation change?
97

10-
### Checklist:
8+
### Checklist
9+
1110
* [ ] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md).
1211
* [ ] This pull request is all my own work -- I have not plagiarized.
1312
* [ ] I know that pull requests will not be merged if they fail the automated tests.
14-
* [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
13+
* [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
1514
* [ ] All new Python files are placed inside an existing directory.
1615
* [ ] All filenames are in all lowercase characters with no spaces or dashes.
1716
* [ ] All functions and variable names follow Python naming conventions.
1817
* [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html).
1918
* [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing.
2019
* [ ] All new algorithms include at least one URL that points to Wikipedia or another similar explanation.
21-
* [ ] If this pull request resolves one or more open issues then the description above includes the issue number(s) with a [closing keyword](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue): "Fixes #ISSUE-NUMBER".
20+
* [ ] If this pull request resolves one or more open issues, then the description above includes the issue number(s) with a [closing keyword](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue): "Fixes #ISSUE-NUMBER".
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# Skill: Code review for TheAlgorithms/Python
2+
3+
Review a pull request against the rules already written in
4+
[`CONTRIBUTING.md`](../../../CONTRIBUTING.md). The goal is a review that any
5+
reviewer (human or AI) can run the same way every time, and that produces a clear,
6+
kind, actionable verdict.
7+
8+
## How to run this skill
9+
10+
Read the PR diff, then work through the four `CONTRIBUTING.md` sections in order
11+
and emit the fixed output shape below. Cite the exact rule you are applying and
12+
suggest the fix — never just "rejected".
13+
14+
### 1. Before contributing / Is this an algorithm?
15+
16+
- [ ] The change adds, fixes, or documents **one algorithm** — not multiple, and
17+
not both code and doctest changes in the same PR.
18+
- [ ] It is a genuine algorithm or data structure (see the *What is an Algorithm?*
19+
section), not a script, snippet, how-to-use for an existing API, or exercise
20+
dump.
21+
- [ ] It is **not already in the repository** (search the existing directories).
22+
- [ ] **No earlier open PR** already does the same thing — link it if one exists.
23+
- [ ] Properly attributed — no plagiarism; prior sources credited.
24+
25+
### 2. Coding Style
26+
27+
- [ ] `from __future__ import annotations` is not needed because this repo only uses
28+
the latest version of CPython.
29+
- [ ] File and directory names are lowercase, use underscores, and land inside an
30+
existing directory.
31+
- [ ] Public functions/classes have **type hints**.
32+
- [ ] Public functions have **doctests that actually pass**.
33+
- [ ] Descriptive variable and function names (no single letters where a word helps).
34+
- [ ] Code is formatted and lint-clean (`ruff`, `pre-commit`).
35+
36+
> **Optional hint:** When a PR hand-writes a simple class that is mostly a
37+
> bundle of fields (a manual `__init__` plus `__repr__`/`__eq__`), it is worth
38+
> **suggesting** `from typing import NamedTuple` or
39+
> `from dataclasses import dataclass` where they would simplify the code. These
40+
> are underutilized tools that our contributors would benefit from using where
41+
> they make sense. Offer it as an optional improvement, not a blocker — do not
42+
> request changes solely because a class was written the longhand way.
43+
44+
#### When a PR fails `ruff check`
45+
46+
Don't just report the failure — try the mechanical fixes and recommend the one
47+
that works, in this order:
48+
49+
1. Run `ruff check --fix file_path.py`. If that makes the file pass, recommend
50+
that solution — these are the fixes `ruff` considers **safe**.
51+
2. If it still fails, run `ruff check --fix --unsafe-fixes file_path.py`. If that
52+
makes the file pass **and** the resulting diff is genuinely safe (it preserves
53+
behavior — review it, don't trust it blindly), recommend that solution and note
54+
that it required `--unsafe-fixes`.
55+
3. If neither passes, or the unsafe fix would change behavior, describe the
56+
remaining rule violations and the manual change the author needs to make.
57+
58+
Always quote the exact rule code(s) `ruff` reports (e.g., `ruff rule UP047`,
59+
`ruff rule RUF100`) so the author can run those commands to read the rules being
60+
flagged. Also, paste the concrete command you ran.
61+
62+
### 3. Other Requirements for Submissions
63+
64+
- [ ] At least one **Wikipedia (or equivalent) URL** documenting the algorithm.
65+
- [ ] Docstring explains what the function does and its parameters/returns.
66+
- [ ] No unnecessary third-party dependencies.
67+
68+
### 4. Verdict — fixed output shape
69+
70+
Emit exactly these headings so reviews are comparable and easy to automate:
71+
72+
```text
73+
### Is this an algorithm? — <yes/no + one-line why>
74+
### Duplicate / prior-art check — <#NNNN | none found>
75+
### Coding style — <pass | issues: …>
76+
### Other requirements (doctests, type hints, descriptive names, Wikipedia URL) — <pass | issues: …>
77+
### Verdict — <approve | request changes | close> + one-line reason
78+
```
79+
80+
## Tone
81+
82+
Be specific and kind. Point at the exact `CONTRIBUTING.md` rule and offer the fix
83+
rather than a bare rejection — first-time and Hacktoberfest contributors are more
84+
likely to come back and improve the PR when the path forward is clear.
85+
86+
## Map findings to labels
87+
88+
Where a finding matches an existing label, name it so the review lines up with the
89+
maintenance/cleanup tooling:
90+
91+
- missing/failing doctests → `require tests`
92+
- missing type hints → `require type hints`
93+
- non-descriptive names → `require descriptive names`
94+
- CI red → `tests are failing`
95+
- otherwise ready for a maintainer → `awaiting reviews`
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Skill: New pull request for TheAlgorithms/Python
2+
3+
Create a new pull request using the rules already written in
4+
[`CONTRIBUTING.md`](../../../CONTRIBUTING.md). The goal is that creating a new
5+
pull request (human or AI) can run the same way every time, and that produces a
6+
clear, kind, tested, type-hinted, mergeable contribution.
7+
8+
## How to run this skill
9+
10+
Make sure that the local `master` branch is synced with `upstream/master` before
11+
creating a new pull request.
12+
13+
Create a new clearly named branch for the pull request. Pull request changes must
14+
not be made or submitted on the `master` branch.
15+
16+
Never hand-edit or revert the `uv.lock` file. If you add a legitimate
17+
dependency, let the `uv-lock` pre-commit hook regenerate it — do not touch it by
18+
hand. A hand-modified `uv.lock` makes the `algorithms-keeper` bot close the pull
19+
request as invalid, and even a repo maintainer cannot undo that.
20+
21+
Always check at least one Markdown checkbox in the pull request description (the "Describe your change" section), or the
22+
`algorithms-keeper` bot will close the pull request as invalid — and it does
23+
this *before* a human reads the PR, so a genuinely good change gets closed for a
24+
formatting reason. This applies to **every** pull request, including CI, docs,
25+
and tooling changes that are not algorithms: tick the boxes that genuinely apply
26+
so the body is never submitted with all boxes empty. Any repo maintainer can
27+
undo this if you @mention them on the closed pull request, but re-opening is
28+
often unreliable, so it is far better to get it right the first time.
29+
30+
### 1. Before contributing / Is this an algorithm?
31+
32+
- [ ] The change adds, fixes, or documents **one algorithm** — not multiple, and
33+
not both code and doctest changes in the same PR.
34+
- [ ] It is a genuine algorithm or data structure (see the *What is an Algorithm?*
35+
section), not a script, snippet, how-to-use for an existing API, or exercise
36+
dump.
37+
- [ ] It is **not already in the repository** (search the existing directories).
38+
- [ ] **No earlier open PR** already does the same thing — link it if one exists.
39+
- [ ] Properly attributed — no plagiarism; prior sources credited.
40+
41+
### 2. Coding Style
42+
43+
- [ ] `from __future__ import annotations` is not needed because this repo only uses
44+
the latest version of CPython.
45+
- [ ] File and directory names are lowercase, use underscores, and land inside an
46+
existing directory.
47+
- [ ] Public functions/classes have **type hints**.
48+
- [ ] Public functions have **doctests that actually pass**.
49+
- [ ] Descriptive variable and function names (no single letters where a word helps).
50+
- [ ] For a simple class that is mostly a bundle of fields, **consider**
51+
`from typing import NamedTuple` or `from dataclasses import dataclass`
52+
instead of a hand-written `__init__`/`__repr__`/`__eq__`. These are
53+
underutilized tools that make simple classes shorter and clearer — use
54+
them where they genuinely simplify the code, not everywhere.
55+
- [ ] Code is formatted and lint-clean (`ruff`, `pre-commit`).
56+
- [ ] `DIRECTORY.md` and `README.md` are **not hand-edited** — the
57+
`algorithms-keeper` bot regenerates them automatically after merge.
58+
59+
### 3. Other Requirements for Submissions
60+
61+
- [ ] At least one **Wikipedia (or equivalent) URL** documenting the algorithm.
62+
- [ ] Docstring explains what the function does and its parameters/returns.
63+
- [ ] No unnecessary third-party dependencies.
64+
65+
## Before you click "Create pull request"
66+
67+
This is the final gate. Do not open the pull request until every item here is true:
68+
69+
- [ ] At least one Markdown checkbox in the PR description is checked. **Verify
70+
this by re-reading the rendered body** — if every box is still `- [ ]`, the
71+
`algorithms-keeper` bot will auto-close the PR before any human sees it.
72+
Check the boxes that genuinely apply to this change; never submit an
73+
all-empty checklist, even for a CI, docs, or tooling PR.
74+
- [ ] The branch is not `master`, and `master` is synced with `upstream/master`.
75+
- [ ] `uv.lock` was not hand-edited.

0 commit comments

Comments
 (0)