profile
viewpoint
Christian Clauss cclauss Christian Clauss Switzerland https://www.patreon.com/cclauss Working hard to find and fix bugs in software and to ensure that Python code is properly ported to Python 3. Building related tools and automated systems.

cclauss/500lines 1

500 Lines or Less

cclauss/adapter_pattern 1

Python adapter pattern where adapters are autoloaded from an adapters directory

cclauss/.github 0

Default configuration for @cclauss repos

cclauss/100-Days-Of-ML-Code 0

100 Days of ML Coding

cclauss/12306 0

12306智能刷票,订票

cclauss/2D_detection 0

TensorFlow implementation of SqueezeDet, trained on the KITTI dataset.

cclauss/30-Days-Of-Python 0

A 30 days of python programming challenge

cclauss/3d-photo-inpainting 0

[CVPR 2020] 3D Photography using Context-aware Layered Depth Inpainting

cclauss/3D-SDN 0

[NeurIPS 2018] 3D-Aware Scene Manipulation via Inverse Graphics

cclauss/3dpwn 0

VirtualBox 3D exploits & PoCs

PR opened xcodz-dot/denver

Fix a typo discovered by codespell

https://github.com/xcodz-dot/denver/runs/1171933875?check_suite_focus=true#step:6:10

+2 -2

0 comment

1 changed file

pr created time in 9 minutes

push eventcclauss/denver

Christian Clauss

commit sha 3958a6bf86b80bf4be1cce765bdeb5f527f7204a

Fix a typo discovered by codespell https://github.com/xcodz-dot/denver/runs/1171933875?check_suite_focus=true#step:6:10

view details

push time in 9 minutes

delete branch cclauss/denver

delete branch : patch-1

delete time in 38 minutes

pull request commentxcodz-dot/denver

GitHub Action to lint Python code

Resolved. https://docs.github.com/en/enterprise/2.13/user/articles/resolving-a-merge-conflict-on-github

cclauss

comment created time in an hour

push eventcclauss/denver

xcodz-dot

commit sha 74c529255a491e756cefca62c2a04ed0af752626

README.md Upgraded to include link to documentation

view details

xcodz-dot

commit sha 5b8ef45643609287c8d859281fe52b91467e2c18

Updated the function with some documentation

view details

xcodz-dot

commit sha ea5c187cf0c63e294d1f8c9cfa41cc6e464d40fb

Updated documentation

view details

xcodz-dot

commit sha ad74de2f999da48622f13dedfbd9f15f2bd26bb1

Updated documentation

view details

xcodz-dot

commit sha 2dde3b53bf762d3effd08407aa5a51ca5e64aebc

Updated documentation

view details

xcodz-dot

commit sha 472b8df81a220a6b9435cd79321dafa0fcdb2c50

Updated documentation

view details

Christian Clauss

commit sha a88fc6612241b7e0205568520deed4c5deafb921

Merge branch 'master' into patch-1

view details

push time in an hour

issue commentscipy/scipy

special.factorial test failure with Python 3.9

How does one install scipy on Python 3.9 release candidate 2 on Ubuntu?

andyfaff

comment created time in 7 hours

delete branch cclauss/pythonista-module-versions

delete branch : pyup-update-pytest-3.0.5-to-6.0.2

delete time in 7 hours

push eventcclauss/pythonista-module-versions

pyup-bot

commit sha d45c8c93f0f4e3dcf02b9a1708758d8bc721de81

Update pytest from 3.0.5 to 6.1.0

view details

push time in 7 hours

push eventTheAlgorithms/Python

Christian Clauss

commit sha d5b182a0f82753794b5d7167eeaa332bf3ceca82

Update requirements.txt

view details

push time in 8 hours

push eventTheAlgorithms/Python

Christian Clauss

commit sha 35134bf34c0a00763dcc26a1677608e5822779cb

Update .travis.yml

view details

push time in 8 hours

push eventcclauss/openlibrary

pyup-bot

commit sha 440afbf3c50223f1b4da42ff6e13d4e99bb350b7

Update pytest from 6.0.1 to 6.1.0

view details

push time in 8 hours

push eventcclauss/openlibrary

pyup-bot

commit sha db0b54806e28aac4f9d1e597826fe9002d904026

Update pytest from 4.6.9 to 6.1.0

view details

push time in 8 hours

create barnchcclauss/openlibrary

branch : pyup-update-pytest-4.6.9-to-6.1.0

created branch time in 8 hours

push eventcclauss/openlibrary

pyup-bot

commit sha b325c71aa1fd338278043b3147ae0574074a066f

Update dbutils from 1.3 to 2.0

view details

push time in 8 hours

create barnchcclauss/openlibrary

branch : pyup-update-dbutils-1.3-to-2.0

created branch time in 8 hours

Pull request review commentTheAlgorithms/Python

Test using random input

 def bubble_sort(collection):   if __name__ == "__main__":+    import doctest     import time +    doctest.testmod()+     user_input = input("Enter numbers separated by a comma:").strip()     unsorted = [int(item) for item in user_input.split(",")]-    start = time.process_time()+    start = time.time()

I think that the original author used time.process_time() for a reason. And "I like a different function" is not enough of a reason to change the author's intention.

shellhub

comment created time in 11 hours

PullRequestReviewEvent

Pull request review commentTheAlgorithms/Python

Test using random input

 def bubble_sort(collection):   if __name__ == "__main__":+    import doctest     import time +    doctest.testmod()+     user_input = input("Enter numbers separated by a comma:").strip()     unsorted = [int(item) for item in user_input.split(",")]-    start = time.process_time()+    start = time.time()

Why make this change?

shellhub

comment created time in 11 hours

PullRequestReviewEvent
PullRequestReviewEvent

Pull request review commentTheAlgorithms/Python

Create vector3_for_2d_rendering.py

+"""+renders 3d point for 2d surfaces
Render 3d points on 2d surfaces.
xcodz-dot

comment created time in 12 hours

Pull request review commentTheAlgorithms/Python

Create vector3_for_2d_rendering.py

+"""+renders 3d point for 2d surfaces+"""++import math, copy++__version__ = "2020.9.26"+__author__ = "xcodz-dot"++AXIS_X = "x"+AXIS_Y = "y"+AXIS_Z = "z"+++def convert_to_2d(x: int, y: int, z: int, scale: int, distance: int) -> tuple:+    """+    Converts 3d point to a 2d drawable point++    >>> convert_to_2d(1, 2, 3, 10, 10)+    (7, 15)++    """+    if type(x) is not int:+        raise TypeError("x must be int")+    if type(y) is not int:+        raise TypeError("y must be int")+    if type(z) is not int:+        raise TypeError("z must be int")+    if type(scale) is not int:+        raise TypeError("scale must be int")+    if type(distance) is not int:+        raise TypeError("distance must be int")+    projectedY = int(((y * distance) / (z + distance)) * scale)+    projectedX = int(((x * distance) / (z + distance)) * scale)+    return projectedX, projectedY+++def rotate(x: int, y: int, z: int, axis: str, angle: int):+    """+    rotate a point around a certain axis with a certain angle+    angler can be any integer between 1, 360++    >>> rotate(1, 2, 3, 'y', 90)+    (3.130524675073759, 2, 0.4470070007889556)+    """+    if angle > 360 or angle < 0:+        raise ValueError("Angle is supposed to be in between 0, 360")+    if type(x) is not int:+        raise TypeError("x must be int")+    if type(y) is not int:+        raise TypeError("y must be int")+    if type(z) is not int:+        raise TypeError("z must be int")+    angle = angle / 450 * 180 / math.pi+    if axis == 'z':+        newX = x * math.cos(angle) - y * math.sin(angle)+        newY = y * math.cos(angle) + x * math.sin(angle)+        newZ = z+    elif axis == 'x':+        newY = y * math.cos(angle) - z * math.sin(angle)+        newZ = z * math.cos(angle) + y * math.sin(angle)+        newX = x+    elif axis == 'y':+        newX = x * math.cos(angle) - z * math.sin(angle)+        newZ = z * math.cos(angle) + x * math.sin(angle)+        newY = y+    else:+        raise ValueError('not a valid axis')+    nx = newX+    ny = newY+    nz = newZ+    return nx, ny, nz
    return new_x, new_y, new_z
xcodz-dot

comment created time in 12 hours

Pull request review commentTheAlgorithms/Python

Create vector3_for_2d_rendering.py

+"""+renders 3d point for 2d surfaces+"""++import math, copy++__version__ = "2020.9.26"+__author__ = "xcodz-dot"++AXIS_X = "x"+AXIS_Y = "y"+AXIS_Z = "z"+++def convert_to_2d(x: int, y: int, z: int, scale: int, distance: int) -> tuple:

Could x be a float instead of an int? Please add a doctest for that.

The return type should be tuple[float, float] or tuple[int, int].

xcodz-dot

comment created time in 12 hours

Pull request review commentTheAlgorithms/Python

Create vector3_for_2d_rendering.py

+"""+renders 3d point for 2d surfaces+"""++import math, copy++__version__ = "2020.9.26"+__author__ = "xcodz-dot"++AXIS_X = "x"+AXIS_Y = "y"+AXIS_Z = "z"+++def convert_to_2d(x: int, y: int, z: int, scale: int, distance: int) -> tuple:+    """+    Converts 3d point to a 2d drawable point++    >>> convert_to_2d(1, 2, 3, 10, 10)+    (7, 15)++    """+    if type(x) is not int:+        raise TypeError("x must be int")+    if type(y) is not int:+        raise TypeError("y must be int")+    if type(z) is not int:+        raise TypeError("z must be int")+    if type(scale) is not int:+        raise TypeError("scale must be int")+    if type(distance) is not int:+        raise TypeError("distance must be int")+    projectedY = int(((y * distance) / (z + distance)) * scale)+    projectedX = int(((x * distance) / (z + distance)) * scale)+    return projectedX, projectedY
    projected_x = int(((x * distance) / (z + distance)) * scale)
    projected_y = int(((y * distance) / (z + distance)) * scale)
    return projected_x, projected_y

As discussed in CONTRIBUTING.md, Python variable names should be in snake_case (all lowercase with underscores in between words).

xcodz-dot

comment created time in 12 hours

Pull request review commentTheAlgorithms/Python

Create vector3_for_2d_rendering.py

+"""+renders 3d point for 2d surfaces+"""++import math, copy++__version__ = "2020.9.26"+__author__ = "xcodz-dot"++AXIS_X = "x"+AXIS_Y = "y"+AXIS_Z = "z"

Please remove unused variables.

xcodz-dot

comment created time in 12 hours

Pull request review commentTheAlgorithms/Python

Create vector3_for_2d_rendering.py

+"""+renders 3d point for 2d surfaces+"""++import math, copy++__version__ = "2020.9.26"+__author__ = "xcodz-dot"++AXIS_X = "x"+AXIS_Y = "y"+AXIS_Z = "z"+++def convert_to_2d(x: int, y: int, z: int, scale: int, distance: int) -> tuple:+    """+    Converts 3d point to a 2d drawable point++    >>> convert_to_2d(1, 2, 3, 10, 10)+    (7, 15)++    """+    if type(x) is not int:

See PEP8 on why directly comparing types is not the recommended approach. Also, this should raise a ValueError, not TypeError.

xcodz-dot

comment created time in 12 hours

PullRequestReviewEvent
PullRequestReviewEvent

push eventTheAlgorithms/Python

Christian Clauss

commit sha 7533c82e09142f331bfd483fe10d77cab49effe1

Update .travis.yml

view details

push time in 12 hours

push eventTheAlgorithms/Python

Christian Clauss

commit sha fb85c03003b7680bd724e4d43c361975d7a8c606

Update requirements.txt

view details

push time in 12 hours

push eventTheAlgorithms/Python

Christian Clauss

commit sha fe7a4e9aeed216caab74163d40248774a2a822c5

Update requirements.txt

view details

push time in 13 hours

pull request commentxcodz-dot/denver

GitHub Action to lint Python code

I fixed line 10 so it passes the flake8 test.

cclauss

comment created time in 13 hours

push eventcclauss/denver

Christian Clauss

commit sha 38608b13c57276749cb8ea5b2f198df2306b1b72

Add Python type hints to flatten()

view details

push time in 13 hours

pull request commentxcodz-dot/denver

GitHub Action to lint Python code

./denver/graphics3d.py:10:43: F821 undefined name 'x'

def flatten(x, y, z, scale, distance) -> ("x", "y"):
                                          ^

x needs to be a datatype (int, float, list, dict, ...) not a variable name.

cclauss

comment created time in 13 hours

pull request commentxcodz-dot/denver

GitHub Action to lint Python code

Let's get this CI to pass before submitting to TheAlgorithms/Python.

cclauss

comment created time in 13 hours

PR opened xcodz-dot/denver

GitHub Action to lint Python code
+30 -0

0 comment

1 changed file

pr created time in 13 hours

push eventcclauss/denver

Christian Clauss

commit sha 01d891b3ff93dfe7201f9513828f527d028070d9

GitHub Action to lint Python code

view details

push time in 13 hours

fork cclauss/denver

Denver API for Python

fork in 13 hours

issue commentTheAlgorithms/Python

Unable to be create branches

Add file... Create new file... Screenshot 2020-09-26 at 19 20 14

xcodz-dot

comment created time in 13 hours

push eventTheAlgorithms/Python

Christian Clauss

commit sha b5d5ba0d755fc5eb3f3f00feb5c18cb919937963

Update .travis.yml

view details

push time in 13 hours

issue commentTheAlgorithms/Python

Unable to be create branches

Are you using git on the command-line or the GitHub web UI?

xcodz-dot

comment created time in 13 hours

push eventTheAlgorithms/Python

Christian Clauss

commit sha b32837f204ad7f13e5d58672d022ad9d0f22eb92

Update .travis.yml

view details

push time in 13 hours

pull request commentTheAlgorithms/Python

Create Job_scheduling.py

problem is that it isn't running anymore

Yes... I do not understand the algorithm so you will have to make it work again with the Jobs class and the function signatures that I provided.

Mohitkumar6122

comment created time in 14 hours

push eventTheAlgorithms/Python

Christian Clauss

commit sha 24fc5a655954a4a1bf70212a13dff9b083c5b23f

Update .travis.yml

view details

push time in 14 hours

push eventTheAlgorithms/Python

Christian Clauss

commit sha 50c518fbbcff8c396b53a886b38d030402fab3be

Update .travis.yml

view details

push time in 14 hours

push eventTheAlgorithms/Python

Christian Clauss

commit sha f7bba1f39d10e8bc0ccb49636739c19f4073e868

Update .travis.yml

view details

push time in 14 hours

delete branch cclauss/pythonista-module-versions

delete branch : pyup-update-beautifulsoup4-4.4.1-to-4.9.1

delete time in 14 hours

push eventcclauss/pythonista-module-versions

pyup-bot

commit sha 9e811ae68a7f1b22b33a5c95043a1fd6c0a5e108

Update beautifulsoup4 from 4.4.1 to 4.9.2

view details

push time in 14 hours

delete branch cclauss/openlibrary

delete branch : pyup-update-beautifulsoup4-4.6.3-to-4.9.1

delete time in 14 hours

create barnchcclauss/openlibrary

branch : pyup-update-beautifulsoup4-4.6.3-to-4.9.2

created branch time in 14 hours

push eventcclauss/openlibrary

pyup-bot

commit sha d9ec4b8238ec579fbdefe70c33641fbf72dd3a4d

Update beautifulsoup4 from 4.6.3 to 4.9.2

view details

push time in 14 hours

push eventTheAlgorithms/Python

Christian Clauss

commit sha 48158efd84e16f4c90a00264846240f9178c1c0f

tensorflow; python_version <= '3.8'

view details

push time in 14 hours

PR opened TheAlgorithms/Python

Travis CI: Test on Python 3.9 release candidate 2

Describe your change:

  • [ ] Add an algorithm?
  • [ ] Fix a bug or typo in an existing algorithm?
  • [ ] Documentation change?

Checklist:

  • [ ] I have read CONTRIBUTING.md.
  • [ ] This pull request is all my own work -- I have not plagiarized.
  • [ ] I know that pull requests will not be merged if they fail the automated tests.
  • [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • [ ] All new Python files are placed inside an existing directory.
  • [ ] All filenames are in all lowercase characters with no spaces or dashes.
  • [ ] All functions and variable names follow Python naming conventions.
  • [ ] All function parameters and return values are annotated with Python type hints.
  • [ ] All functions have doctests that pass the automated testing.
  • [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.
  • [ ] If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.
+1 -1

0 comment

1 changed file

pr created time in 15 hours

create barnchTheAlgorithms/Python

branch : Python-3.9-rc2

created branch time in 15 hours

PR closed TheAlgorithms/Python

Travis CI: Test on Python 3.9 release candidate 2

Python 3.9 is now on its release candidate 2 and is scheduled to be released two weeks so let's start testing to see if we are compatible with our future...

Fixes: #2279

Describe your change:

  • [ ] Add an algorithm?
  • [ ] Fix a bug or typo in an existing algorithm?
  • [ ] Documentation change?

Checklist:

  • [ ] I have read CONTRIBUTING.md.
  • [ ] This pull request is all my own work -- I have not plagiarized.
  • [ ] I know that pull requests will not be merged if they fail the automated tests.
  • [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • [ ] All new Python files are placed inside an existing directory.
  • [ ] All filenames are in all lowercase characters with no spaces or dashes.
  • [ ] All functions and variable names follow Python naming conventions.
  • [ ] All function parameters and return values are annotated with Python type hints.
  • [ ] All functions have doctests that pass the automated testing.
  • [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.
  • [ ] If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.
+13 -3

3 comments

3 changed files

cclauss

pr closed time in 15 hours

push eventTheAlgorithms/Python

Abdoulaye Balde

commit sha 7446e695716eaf0f75f51a1c4805f8d8d698e653

Gradient Boosting Regressor (#2298) * Stock market prediction using greadient boosting * To reverse a string using stack * To reverse string using stack * Predict Stock Prices Python & Machine Learning * Gradient boosting regressor on boston dataset * Gradient boosting regressor implementation * Gradient boosting regressor * Gradient boosting regressor * Gradient boosting regressor * Removing files * GradientBoostingRegressor example * Demo Gradient Boosting * Demo Gradient boosting * demo of gradient boosting * gradient boosting demo * Fix spelling mistake * Fix formatting Co-authored-by: John Law <johnlaw.po@gmail.com>

view details

push time in 15 hours

PR merged TheAlgorithms/Python

Gradient Boosting Regressor

Describe your change:

Adding a Gradient boosting regressor algorithm to predict the Boston house price.

+70 -0

15 comments

1 changed file

abdoulayegk

pr closed time in 15 hours

PullRequestReviewEvent
PullRequestReviewEvent

push eventTheAlgorithms/Python

Christian Clauss

commit sha db0db01d87868cb1d15628d772b13ed56df5adce

Use self-documenting option instead of cryptic option (#2487) * Use self-documenting option instead of cryptic option @mateuszz0000 Your review, please. Pretend that you do not know what `-L` stands for. How many keystrokes and clicks does it take to confirm the purpose of this option? * updating DIRECTORY.md Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>

view details

push time in 15 hours

PR merged TheAlgorithms/Python

Use self-documenting option instead of cryptic option

@mateuszz0000 Your review, please. Pretend that you do not know what -L stands for. How many keystrokes and clicks does it take to confirm the purpose of this option?

Describe your change:

  • [x] Fix a bug
+3 -1

2 comments

2 changed files

cclauss

pr closed time in 15 hours

pull request commentTheAlgorithms/Python

Use self-documenting option instead of cryptic option

@mateuszz0000 Please review and approve the change so that I have the ability merge.

cclauss

comment created time in 16 hours

Pull request review commentTheAlgorithms/Python

Updated circular_linked_list

   class Node:-    """-    Class to represent a single node.--    Each node has following attributes-    * data-    * next_ptr-    """-     def __init__(self, data: Any):         self.data = data-        self.next_ptr = None+        self.next = None   class CircularLinkedList:-    """-    Class to represent the CircularLinkedList.--    CircularLinkedList has following attributes.-    * head-    * length-    """-     def __init__(self):         self.head = None-        self.length = 0+        self.tail = None -    def __len__(self) -> int:-        """-        Dunder method to return length of the CircularLinkedList-        >>> cll = CircularLinkedList()-        >>> len(cll)-        0-        >>> cll.append(1)-        >>> len(cll)-        1-        >>> cll.prepend(0)-        >>> len(cll)-        2-        >>> cll.delete_front()-        >>> len(cll)-        1-        >>> cll.delete_rear()-        >>> len(cll)-        0-        """-        return self.length--    def __str__(self) -> str:-        """-        Dunder method to represent the string representation of the CircularLinkedList-        >>> cll = CircularLinkedList()-        >>> print(cll)-        Empty linked list-        >>> cll.append(1)-        >>> cll.append(2)-        >>> print(cll)-        <Node data=1> => <Node data=2>-        """-        current_node = self.head-        if not current_node:-            return "Empty linked list"--        results = [current_node.data]-        current_node = current_node.next_ptr--        while current_node != self.head:-            results.append(current_node.data)-            current_node = current_node.next_ptr--        return " => ".join(f"<Node data={result}>" for result in results)--    def append(self, data: Any) -> None:-        """-        Adds a node with given data to the end of the CircularLinkedList-        >>> cll = CircularLinkedList()-        >>> cll.append(1)-        >>> print(f"{len(cll)}: {cll}")-        1: <Node data=1>-        >>> cll.append(2)-        >>> print(f"{len(cll)}: {cll}")-        2: <Node data=1> => <Node data=2>-        """-        current_node = self.head+    def __iter__(self):+        node = self.head+        while self.head:+            yield node.data+            node = node.next+            if node == self.head:+                break -        new_node = Node(data)-        new_node.next_ptr = new_node--        if current_node:-            while current_node.next_ptr != self.head:-                current_node = current_node.next_ptr+    def __len__(self) -> int:+        return len(tuple(iter(self))) -            current_node.next_ptr = new_node-            new_node.next_ptr = self.head-        else:-            self.head = new_node+    def __repr__(self):+        return "->".join(str(item) for item in iter(self)) -        self.length += 1+    def insert_tail(self, data: Any) -> None:+        self.insert_nth(len(self), data) -    def prepend(self, data: Any) -> None:-        """-        Adds a node with given data to the front of the CircularLinkedList-        >>> cll = CircularLinkedList()-        >>> cll.prepend(1)-        >>> cll.prepend(2)-        >>> print(f"{len(cll)}: {cll}")-        2: <Node data=2> => <Node data=1>-        """-        current_node = self.head+    def insert_head(self, data: Any) -> None:+        self.insert_nth(0, data) +    def insert_nth(self, index: int, data: Any) -> None:+        if index < 0 or index > len(self):+            raise IndexError("list index out of range.")         new_node = Node(data)-        new_node.next_ptr = new_node--        if current_node:-            while current_node.next_ptr != self.head:-                current_node = current_node.next_ptr--            current_node.next_ptr = new_node-            new_node.next_ptr = self.head--        self.head = new_node-        self.length += 1--    def delete_front(self) -> None:-        """-        Removes the 1st node from the CircularLinkedList-        >>> cll = CircularLinkedList()-        >>> cll.delete_front()-        Traceback (most recent call last):-        ...-        IndexError: Deleting from an empty list-        >>> cll.append(1)-        >>> cll.append(2)-        >>> print(f"{len(cll)}: {cll}")-        2: <Node data=1> => <Node data=2>-        >>> cll.delete_front()-        >>> print(f"{len(cll)}: {cll}")-        1: <Node data=2>-        >>> cll.delete_front()-        >>> print(f"{len(cll)}: {cll}")-        0: Empty linked list-        """-        if not self.head:-            raise IndexError("Deleting from an empty list")--        current_node = self.head--        if current_node.next_ptr == current_node:-            self.head = None+        if self.head is None:+            new_node.next = new_node  # first node points itself+            self.tail = self.head = new_node+        elif index == 0:  # insert at head+            new_node.next = self.head+            self.head = self.tail.next = new_node         else:-            while current_node.next_ptr != self.head:-                current_node = current_node.next_ptr--            current_node.next_ptr = self.head.next_ptr-            self.head = self.head.next_ptr--        self.length -= 1-        if not self.head:-            assert self.length == 0--    def delete_rear(self) -> None:-        """-        Removes the last node from the CircularLinkedList-        >>> cll = CircularLinkedList()-        >>> cll.delete_rear()-        Traceback (most recent call last):-        ...-        IndexError: Deleting from an empty list-        >>> cll.append(1)-        >>> cll.append(2)-        >>> print(f"{len(cll)}: {cll}")-        2: <Node data=1> => <Node data=2>-        >>> cll.delete_rear()-        >>> print(f"{len(cll)}: {cll}")-        1: <Node data=1>-        >>> cll.delete_rear()-        >>> print(f"{len(cll)}: {cll}")-        0: Empty linked list-        """-        if not self.head:-            raise IndexError("Deleting from an empty list")--        temp_node, current_node = self.head, self.head--        if current_node.next_ptr == current_node:-            self.head = None+            temp = self.head+            for _ in range(index - 1):+                temp = temp.next+            new_node.next = temp.next+            temp.next = new_node+            if index == len(self) - 1:  # insert at tail+                self.tail = new_node++    def delete_front(self):+        return self.delete_nth(0)++    def delete_tail(self) -> None:+        return self.delete_nth(len(self) - 1)++    def delete_nth(self, index: int = 0):+        if not 0 <= index < len(self):+            raise IndexError("list index out of range.")+        delete_node = self.head+        if self.head == self.tail:  # just one node+            self.head = self.tail = None+        elif index == 0:  # delete head node+            self.tail.next = self.tail.next.next+            self.head = self.head.next         else:-            while current_node.next_ptr != self.head:-                temp_node = current_node-                current_node = current_node.next_ptr+            temp = self.head+            for _ in range(index - 1):+                temp = temp.next+            delete_node = temp.next+            temp.next = temp.next.next+            if index == len(self) - 1:  # delete at tail+                self.tail = temp+        return delete_node.data -            temp_node.next_ptr = current_node.next_ptr+    def print_list(self) -> None:+        print(self) -        self.length -= 1-        if not self.head:-            assert self.length == 0+    def is_empty(self):+        return len(self) == 0+++def test_circular_linked_list() -> None:+    """+    >>> test_circular_linked_list()+    """+    circular_linked_list = CircularLinkedList()+    assert len(circular_linked_list) == 0+    assert circular_linked_list.is_empty() is True+    assert str(circular_linked_list) == ""++    try:+        circular_linked_list.delete_front()+        assert False  # This should not happen+    except IndexError:+        assert True  # This should happen++    try:+        circular_linked_list.delete_tail()+        assert False  # This should not happen+    except IndexError:+        assert True  # This should happen++    try:+        circular_linked_list.delete_nth(-1)+        assert False+    except IndexError:+        assert True++    try:+        circular_linked_list.delete_nth(0)+        assert False+    except IndexError:+        assert True++    for i in range(5):

No. We are looking for a test where .is_empty() returns False. We already have one that returns True.

shellhub

comment created time in 17 hours

PullRequestReviewEvent

pull request commentTheAlgorithms/Python

Updated circular_linked_list

Please delete .print_list() as it is completely redundant.

shellhub

comment created time in 17 hours

Pull request review commentTheAlgorithms/Python

Updated circular_linked_list

   class Node:-    """-    Class to represent a single node.--    Each node has following attributes-    * data-    * next_ptr-    """-     def __init__(self, data: Any):         self.data = data-        self.next_ptr = None+        self.next = None   class CircularLinkedList:-    """-    Class to represent the CircularLinkedList.--    CircularLinkedList has following attributes.-    * head-    * length-    """-     def __init__(self):         self.head = None-        self.length = 0+        self.tail = None -    def __len__(self) -> int:-        """-        Dunder method to return length of the CircularLinkedList-        >>> cll = CircularLinkedList()-        >>> len(cll)-        0-        >>> cll.append(1)-        >>> len(cll)-        1-        >>> cll.prepend(0)-        >>> len(cll)-        2-        >>> cll.delete_front()-        >>> len(cll)-        1-        >>> cll.delete_rear()-        >>> len(cll)-        0-        """-        return self.length--    def __str__(self) -> str:-        """-        Dunder method to represent the string representation of the CircularLinkedList-        >>> cll = CircularLinkedList()-        >>> print(cll)-        Empty linked list-        >>> cll.append(1)-        >>> cll.append(2)-        >>> print(cll)-        <Node data=1> => <Node data=2>-        """-        current_node = self.head-        if not current_node:-            return "Empty linked list"--        results = [current_node.data]-        current_node = current_node.next_ptr--        while current_node != self.head:-            results.append(current_node.data)-            current_node = current_node.next_ptr--        return " => ".join(f"<Node data={result}>" for result in results)--    def append(self, data: Any) -> None:-        """-        Adds a node with given data to the end of the CircularLinkedList-        >>> cll = CircularLinkedList()-        >>> cll.append(1)-        >>> print(f"{len(cll)}: {cll}")-        1: <Node data=1>-        >>> cll.append(2)-        >>> print(f"{len(cll)}: {cll}")-        2: <Node data=1> => <Node data=2>-        """-        current_node = self.head+    def __iter__(self):+        node = self.head+        while self.head:+            yield node.data+            node = node.next+            if node == self.head:+                break -        new_node = Node(data)-        new_node.next_ptr = new_node--        if current_node:-            while current_node.next_ptr != self.head:-                current_node = current_node.next_ptr+    def __len__(self) -> int:+        return len(tuple(iter(self))) -            current_node.next_ptr = new_node-            new_node.next_ptr = self.head-        else:-            self.head = new_node+    def __repr__(self):+        return "->".join(str(item) for item in iter(self)) -        self.length += 1+    def insert_tail(self, data: Any) -> None:+        self.insert_nth(len(self), data) -    def prepend(self, data: Any) -> None:-        """-        Adds a node with given data to the front of the CircularLinkedList-        >>> cll = CircularLinkedList()-        >>> cll.prepend(1)-        >>> cll.prepend(2)-        >>> print(f"{len(cll)}: {cll}")-        2: <Node data=2> => <Node data=1>-        """-        current_node = self.head+    def insert_head(self, data: Any) -> None:+        self.insert_nth(0, data) +    def insert_nth(self, index: int, data: Any) -> None:+        if index < 0 or index > len(self):+            raise IndexError("list index out of range.")         new_node = Node(data)-        new_node.next_ptr = new_node--        if current_node:-            while current_node.next_ptr != self.head:-                current_node = current_node.next_ptr--            current_node.next_ptr = new_node-            new_node.next_ptr = self.head--        self.head = new_node-        self.length += 1--    def delete_front(self) -> None:-        """-        Removes the 1st node from the CircularLinkedList-        >>> cll = CircularLinkedList()-        >>> cll.delete_front()-        Traceback (most recent call last):-        ...-        IndexError: Deleting from an empty list-        >>> cll.append(1)-        >>> cll.append(2)-        >>> print(f"{len(cll)}: {cll}")-        2: <Node data=1> => <Node data=2>-        >>> cll.delete_front()-        >>> print(f"{len(cll)}: {cll}")-        1: <Node data=2>-        >>> cll.delete_front()-        >>> print(f"{len(cll)}: {cll}")-        0: Empty linked list-        """-        if not self.head:-            raise IndexError("Deleting from an empty list")--        current_node = self.head--        if current_node.next_ptr == current_node:-            self.head = None+        if self.head is None:+            new_node.next = new_node  # first node points itself+            self.tail = self.head = new_node+        elif index == 0:  # insert at head+            new_node.next = self.head+            self.head = self.tail.next = new_node         else:-            while current_node.next_ptr != self.head:-                current_node = current_node.next_ptr--            current_node.next_ptr = self.head.next_ptr-            self.head = self.head.next_ptr--        self.length -= 1-        if not self.head:-            assert self.length == 0--    def delete_rear(self) -> None:-        """-        Removes the last node from the CircularLinkedList-        >>> cll = CircularLinkedList()-        >>> cll.delete_rear()-        Traceback (most recent call last):-        ...-        IndexError: Deleting from an empty list-        >>> cll.append(1)-        >>> cll.append(2)-        >>> print(f"{len(cll)}: {cll}")-        2: <Node data=1> => <Node data=2>-        >>> cll.delete_rear()-        >>> print(f"{len(cll)}: {cll}")-        1: <Node data=1>-        >>> cll.delete_rear()-        >>> print(f"{len(cll)}: {cll}")-        0: Empty linked list-        """-        if not self.head:-            raise IndexError("Deleting from an empty list")--        temp_node, current_node = self.head, self.head--        if current_node.next_ptr == current_node:-            self.head = None+            temp = self.head+            for _ in range(index - 1):+                temp = temp.next+            new_node.next = temp.next+            temp.next = new_node+            if index == len(self) - 1:  # insert at tail+                self.tail = new_node++    def delete_front(self):+        return self.delete_nth(0)++    def delete_tail(self) -> None:+        return self.delete_nth(len(self) - 1)++    def delete_nth(self, index: int = 0):+        if not 0 <= index < len(self):+            raise IndexError("list index out of range.")+        delete_node = self.head+        if self.head == self.tail:  # just one node+            self.head = self.tail = None+        elif index == 0:  # delete head node+            self.tail.next = self.tail.next.next+            self.head = self.head.next         else:-            while current_node.next_ptr != self.head:-                temp_node = current_node-                current_node = current_node.next_ptr+            temp = self.head+            for _ in range(index - 1):+                temp = temp.next+            delete_node = temp.next+            temp.next = temp.next.next+            if index == len(self) - 1:  # delete at tail+                self.tail = temp+        return delete_node.data -            temp_node.next_ptr = current_node.next_ptr+    def print_list(self) -> None:+        print(self) -        self.length -= 1-        if not self.head:-            assert self.length == 0+    def is_empty(self):+        return len(self) == 0+++def test_circular_linked_list() -> None:+    """+    >>> test_circular_linked_list()+    """+    circular_linked_list = CircularLinkedList()+    assert len(circular_linked_list) == 0+    assert circular_linked_list.is_empty() is True+    assert str(circular_linked_list) == ""++    try:+        circular_linked_list.delete_front()+        assert False  # This should not happen+    except IndexError:+        assert True  # This should happen++    try:+        circular_linked_list.delete_tail()+        assert False  # This should not happen+    except IndexError:+        assert True  # This should happen++    try:+        circular_linked_list.delete_nth(-1)+        assert False+    except IndexError:+        assert True++    try:+        circular_linked_list.delete_nth(0)+        assert False+    except IndexError:+        assert True++    for i in range(5):+        assert len(circular_linked_list) == i+        circular_linked_list.insert_nth(i, i + 1)

Please add another is_empty() test.

shellhub

comment created time in 17 hours

PullRequestReviewEvent

create barnchTheAlgorithms/Python

branch : codespell_--ignore-words-list

created branch time in 17 hours

PR opened TheAlgorithms/Python

Use self-documenting option instead of cryptic option

@mateuszz0000 Your review, please. Pretend that you do not know what -L stands for. How many keystrokes and clicks does it take to confirm the purpose of this option?

Describe your change:

  • [x] Fix a bug
+1 -1

0 comment

1 changed file

pr created time in 17 hours

Pull request review commentTheAlgorithms/Python

Create min_stack.py

 class MinStack:+    """ Designing a Stack that can return Minimum element in Constant time"""+     def __init__(self):         """ Creating stack minStack and size Variable"""         self.stack = []         self.minStack = []         self.size = 0

Please see https://github.com/TheAlgorithms/Python/pull/2477#discussion_r494864246 and implement .__iter__() and .__len__() methods for this class. .__iter__() should return values in min-to-max order.

mavenzer

comment created time in 18 hours

PullRequestReviewEvent

pull request commentTheAlgorithms/Python

Web programming contribution

https://docs.travis-ci.com/user/environment-variables/#default-environment-variables

niranjanhegde144

comment created time in 19 hours

push eventniranjanhegde144/Python-1

Christian Clauss

commit sha ea45c82875b797a69a4d4c8e4195d52e0397669d

TESTING = os.getenv("CONTINUOUS_INTEGRATION", False)

view details

push time in 19 hours

pull request commentTheAlgorithms/Python

Create Job_scheduling.py

Create a Job class

I hope these changes help to clarify...

I have rearranged the code in a way that will BREAK THE TESTS. I make this clearer, we will have a Job class and will remove the Schedule class and replace it with functions. Let's keep the Job class super simple. Its only goal is to carry around the deadline and profit for each Job so we do not move around separate list of ints.

With these changes, each of our three main functions takes in a list of jobs. We should keep things flexible so that we could create test_jobs_two and run it thru all functions and get different results.

Mohitkumar6122

comment created time in 21 hours

push eventMohitkumar6122/Python

Christian Clauss

commit sha 37c4b69bf050b27499d9ce6aad2d23e6c3a5c987

Create a Job class I hope these changes help to clarify... I have rearranged the code in a way that will BREAK THE TESTS. I make this clearer, we will have a Job class and will remove the Schedule class and replace it with functions. Let's keep the Job class super simple. Its only goal is to carry around the deadline and profit for each Job so we do not move around separate list of ints. With these changes, each of our three main functions takes in a list of jobs. We should keep things flexible so that we could create `test_jobs_two` and run it thru all functions and get different results.

view details

push time in 21 hours

push eventMohitkumar6122/Python

Christian Clauss

commit sha 809d834a57f7dc75004d2e3f604430ba85f35e57

Update job_scheduling.py

view details

push time in 21 hours

pull request commentTheAlgorithms/Python

Add algorithm for testing Project Euler solutions

OK... Let's force default args so that solution() can always be called with no args.

On eulertest.py#L21, my modification would be:

  • actualans = module.compute() --> actualans = str(module.compute()) This allows modules to return whatever datatype they want but actualans is always str.

If it would help, send me an email so we can do a videoconf.

dhruvmanila

comment created time in a day

pull request commentTheAlgorithms/Python

Updated circular_linked_list

What parts of this code have no tests?

shellhub

comment created time in a day

PullRequestReviewEvent

Pull request review commentTheAlgorithms/Python

Initial commit of conjugate gradient method

+import numpy as np+++def _is_matrix_spd(A: np.array) -> bool:++    """+    Returns True if input matrix A is symmetric positive definite.+    Returns False otherwise.++    For a matrix to be SPD, all eigenvalues must be positive.++    >>> import numpy as np+    >>> A = np.array([+    ... [4.12401784, -5.01453636, -0.63865857],+    ... [-5.01453636, 12.33347422, -3.40493586],+    ... [-0.63865857, -3.40493586,  5.78591885]])+    >>> _is_matrix_spd(A)+    True+    >>> A = np.array([+    ... [0.34634879,  1.96165514,  2.18277744],+    ... [0.74074469, -1.19648894, -1.34223498],+    ... [-0.7687067 ,  0.06018373, -1.16315631]])+    >>> _is_matrix_spd(A)+    False+    """+    # Ensure matrix is square.+    assert np.shape(A)[0] == np.shape(A)[1]++    # Get eigenvalues and eignevectors for a symmetric matrix.+    eigen_values, _ = np.linalg.eigh(A)++    # Check sign of all eigenvalues.+    if np.all(eigen_values > 0):+        return True+    else:+        return False+++def _create_spd_matrix(N: np.int64) -> np.array:+    """+    Returns a symmetric positive definite matrix given a dimension.++    Input:+    N is an integer.

This line is redundant now that we have type hints so let's instead give N a more self-documenting variable name so that this comment is no longer required or make this comment document the what & why, not the datatype.

zakademic

comment created time in a day

Pull request review commentTheAlgorithms/Python

Initial commit of conjugate gradient method

+import numpy as np

Please add a URL that can help the reader learn about the problems that your algorithm is trying to solve... https://en.wikipedia.org/wiki/Conjugate_gradient_method https://en.wikipedia.org/wiki/Definite_symmetric_matrix

zakademic

comment created time in a day

Pull request review commentTheAlgorithms/Python

Initial commit of conjugate gradient method

+import numpy as np+++def _is_matrix_spd(A: np.array) -> bool:++    """+    Returns True if input matrix A is symmetric positive definite.+    Returns False otherwise.++    For a matrix to be SPD, all eigenvalues must be positive.++    >>> import numpy as np+    >>> A = np.array([+    ... [4.12401784, -5.01453636, -0.63865857],+    ... [-5.01453636, 12.33347422, -3.40493586],+    ... [-0.63865857, -3.40493586,  5.78591885]])+    >>> _is_matrix_spd(A)+    True+    >>> A = np.array([+    ... [0.34634879,  1.96165514,  2.18277744],+    ... [0.74074469, -1.19648894, -1.34223498],+    ... [-0.7687067 ,  0.06018373, -1.16315631]])+    >>> _is_matrix_spd(A)+    False+    """+    # Ensure matrix is square.+    assert np.shape(A)[0] == np.shape(A)[1]++    # Get eigenvalues and eignevectors for a symmetric matrix.+    eigen_values, _ = np.linalg.eigh(A)++    # Check sign of all eigenvalues.+    if np.all(eigen_values > 0):+        return True+    else:+        return False
    return np.all(eigen_values > 0)
zakademic

comment created time in a day

Pull request review commentTheAlgorithms/Python

Initial commit of conjugate gradient method

+import numpy as np+++def _is_matrix_spd(A: np.array) -> bool:++    """+    Returns True if input matrix A is symmetric positive definite.+    Returns False otherwise.++    For a matrix to be SPD, all eigenvalues must be positive.++    >>> import numpy as np+    >>> A = np.array([+    ... [4.12401784, -5.01453636, -0.63865857],+    ... [-5.01453636, 12.33347422, -3.40493586],+    ... [-0.63865857, -3.40493586,  5.78591885]])+    >>> _is_matrix_spd(A)+    True+    >>> A = np.array([+    ... [0.34634879,  1.96165514,  2.18277744],+    ... [0.74074469, -1.19648894, -1.34223498],+    ... [-0.7687067 ,  0.06018373, -1.16315631]])+    >>> _is_matrix_spd(A)+    False+    """+    # Ensure matrix is square.+    assert np.shape(A)[0] == np.shape(A)[1]++    # Get eigenvalues and eignevectors for a symmetric matrix.+    eigen_values, _ = np.linalg.eigh(A)++    # Check sign of all eigenvalues.+    if np.all(eigen_values > 0):+        return True+    else:+        return False+++def _create_spd_matrix(N: np.int64) -> np.array:+    """+    Returns a symmetric positive definite matrix given a dimension.++    Input:+    N is an integer.++    Output:+    A is an NxN symmetric positive definite (SPD) matrix.++    >>> import numpy as np+    >>> N = 3+    >>> A = _create_spd_matrix(N)+    >>> _is_matrix_spd(A)+    True+    """++    A = np.random.randn(N, N)+    A = np.dot(A, A.T)++    assert _is_matrix_spd(A) is True
    assert _is_matrix_spd(A)
zakademic

comment created time in a day

PullRequestReviewEvent
PullRequestReviewEvent

issue commentTheAlgorithms/Python

Python

Understood. No problems. But was there a website or a blog or some other place that suggested the idea to you? We get a ton of these empty issues and I am wondering if there is some common source to them.

eksam03

comment created time in a day

issue commentTheAlgorithms/Python

Python

@wjoe1995 Where did you get the idea to open an empty issue with no content?

wjoe1995

comment created time in a day

issue commentTheAlgorithms/Python

Python

@eksam03 Where did you get the idea to open an empty issue with no content?

eksam03

comment created time in a day

issue closedTheAlgorithms/Python

Python

#2484

closed time in a day

eksam03

issue commentTheAlgorithms/Python

Python

#1901

eksam03

comment created time in a day

issue closedTheAlgorithms/Python

Python

#2485

closed time in a day

wjoe1995

issue commentTheAlgorithms/Python

Python

#1901

wjoe1995

comment created time in a day

push eventSonic0588/Python

Christian Clauss

commit sha 511b270015e16f161cd465215c9f6a80a1cd2842

Update strings/min_cost_string_conversion.py

view details

push time in a day

push eventcclauss/ocrd_ocropy

Christian Clauss

commit sha 52e4a5f51d6d4da6c0c5046ce903e791dea7f56d

Travis CI: Lint Python for syntax errors, undefined names

view details

push time in a day

fork cclauss/ocrd_ocropy

OCRD CLI to ocropy

fork in a day

Pull request review commentaboSamoor/polyglot

Travis CI: Test current Python versions on focal

 # Config file for automatic testing at travis-ci.org-dist: trusty+dist: focal  language: python  python:+  - "3.9-dev"+  - "3.8"+  - "3.7"   - "3.6"   - "3.5"-  - "3.4"   - "2.7"-#  - "pypy"+# - "pypy3"++jobs:+  allow_failures:+    - python: "3.9-dev"

No further changes. Thanks.

cclauss

comment created time in a day

PullRequestReviewEvent
more