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

Improved Graph Implementations #8730

Merged
merged 12 commits into from
May 31, 2023
Merged

Improved Graph Implementations #8730

merged 12 commits into from
May 31, 2023

Conversation

nith2001
Copy link
Contributor

@nith2001 nith2001 commented May 14, 2023

Describe your change:

The graph implementations using the adjacency list and adjacency matrix were not very comprehensive and lacked supporting functions. I wanted to improve them and also write tests to prove they worked. This also solved Issue #8709, which I brought up. To run my tests, do python3 <testfile>.py under the graphs/tests folder.

  • 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.
    ^^ it changes two, but they're both about the same thing, which is graph implementation. Let me know if that's not okay.
  • 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 include at least one URL that points to Wikipedia or another similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

Provides new implementation for graph_list.py and graph_matrix.py along with pytest suites for each. Fixes TheAlgorithms#8709
@nith2001
Copy link
Contributor Author

nith2001 commented May 14, 2023

I'll clear up the failed code quality test soon. First-time contributor so I didn't read the Contributor.md as closely as I should've regarding testing and quality.

@algorithms-keeper algorithms-keeper bot added the tests are failing Do not merge until tests pass label May 14, 2023
graphs/graph_list.py Outdated Show resolved Hide resolved
@nith2001
Copy link
Contributor Author

nith2001 commented May 15, 2023

I wrote a bunch of unit tests using the unittest framework rather than doctest because I didn't want to make my code super unnecessarily long. Is that okay?

@algorithms-keeper algorithms-keeper bot removed the tests are failing Do not merge until tests pass label May 15, 2023
@nith2001
Copy link
Contributor Author

Not yet, gonna push some comments and docs describing the implementation

@algorithms-keeper algorithms-keeper bot added the awaiting reviews This PR is ready to be reviewed label May 15, 2023
@nith2001
Copy link
Contributor Author

nith2001 commented May 15, 2023

Alright, all done. I wanted to store my tests in the graphs/tests folder but I couldn't find a way to import my graph classes without violated some type of black linter code quality. I wanted to do sys.path.append("..") and then import the class but black and ruff wouldn't let me I think. Otherwise, let me know what I can fix!

@nith2001 nith2001 requested a review from cclauss May 15, 2023 20:59
@nith2001
Copy link
Contributor Author

Are y'all backlogged with work? Just checking in.

graphs/graph_list.py Outdated Show resolved Hide resolved
graphs/graph_list.py Outdated Show resolved Hide resolved
graphs/graph_adj_list.py Outdated Show resolved Hide resolved
graphs/graph_adj_list.py Outdated Show resolved Hide resolved
graphs/graph_adj_list.py Outdated Show resolved Hide resolved
graphs/graph_adj_list.py Outdated Show resolved Hide resolved
graphs/graph_adj_list.py Outdated Show resolved Hide resolved
@nith2001 nith2001 changed the title Improved Graph Implementations #8709 Improved Graph Implementations May 25, 2023
@nith2001
Copy link
Contributor Author

Ready for another review!

@algorithms-keeper algorithms-keeper bot added the require type hints https://docs.python.org/3/library/typing.html label May 30, 2023
Copy link

@algorithms-keeper algorithms-keeper bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Click here to look at the relevant links ⬇️

🔗 Relevant Links

Repository:

Python:

Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.

algorithms-keeper commands and options

algorithms-keeper actions can be triggered by commenting on this PR:

  • @algorithms-keeper review to trigger the checks for only added pull request files
  • @algorithms-keeper review-all to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.

NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.

graphs/graph_adjacency_list.py Show resolved Hide resolved
graphs/graph_adjacency_list.py Show resolved Hide resolved
graphs/graph_adjacency_list.py Show resolved Hide resolved
graphs/graph_adjacency_list.py Show resolved Hide resolved
graphs/graph_adjacency_list.py Outdated Show resolved Hide resolved
graphs/graph_adjacency_matrix.py Outdated Show resolved Hide resolved
graphs/graph_adjacency_matrix.py Outdated Show resolved Hide resolved
graphs/graph_adjacency_matrix.py Outdated Show resolved Hide resolved
graphs/graph_adjacency_matrix.py Outdated Show resolved Hide resolved
graphs/graph_adjacency_matrix.py Outdated Show resolved Hide resolved
@algorithms-keeper algorithms-keeper bot added the tests are failing Do not merge until tests pass label May 30, 2023
Copy link

@algorithms-keeper algorithms-keeper bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Click here to look at the relevant links ⬇️

🔗 Relevant Links

Repository:

Python:

Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.

algorithms-keeper commands and options

algorithms-keeper actions can be triggered by commenting on this PR:

  • @algorithms-keeper review to trigger the checks for only added pull request files
  • @algorithms-keeper review-all to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.

NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.

graphs/graph_adjacency_list.py Show resolved Hide resolved
graphs/graph_adjacency_list.py Show resolved Hide resolved
graphs/graph_adjacency_list.py Show resolved Hide resolved
graphs/graph_adjacency_list.py Show resolved Hide resolved
graphs/graph_adjacency_list.py Outdated Show resolved Hide resolved
graphs/graph_adjacency_matrix.py Outdated Show resolved Hide resolved
graphs/graph_adjacency_matrix.py Outdated Show resolved Hide resolved
graphs/graph_adjacency_matrix.py Outdated Show resolved Hide resolved
graphs/graph_adjacency_matrix.py Outdated Show resolved Hide resolved
graphs/graph_adjacency_matrix.py Outdated Show resolved Hide resolved
@algorithms-keeper algorithms-keeper bot removed the tests are failing Do not merge until tests pass label May 30, 2023
Copy link

@algorithms-keeper algorithms-keeper bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Click here to look at the relevant links ⬇️

🔗 Relevant Links

Repository:

Python:

Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.

algorithms-keeper commands and options

algorithms-keeper actions can be triggered by commenting on this PR:

  • @algorithms-keeper review to trigger the checks for only added pull request files
  • @algorithms-keeper review-all to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.

NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.

graphs/graph_adjacency_list.py Show resolved Hide resolved
graphs/graph_adjacency_list.py Show resolved Hide resolved
graphs/graph_adjacency_list.py Show resolved Hide resolved
graphs/graph_adjacency_list.py Show resolved Hide resolved
graphs/graph_adjacency_matrix.py Outdated Show resolved Hide resolved
graphs/graph_adjacency_matrix.py Show resolved Hide resolved
graphs/graph_adjacency_matrix.py Show resolved Hide resolved
graphs/graph_adjacency_matrix.py Show resolved Hide resolved
graphs/graph_adjacency_matrix.py Show resolved Hide resolved
Copy link

@algorithms-keeper algorithms-keeper bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Click here to look at the relevant links ⬇️

🔗 Relevant Links

Repository:

Python:

Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.

algorithms-keeper commands and options

algorithms-keeper actions can be triggered by commenting on this PR:

  • @algorithms-keeper review to trigger the checks for only added pull request files
  • @algorithms-keeper review-all to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.

NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.

graphs/graph_adjacency_list.py Show resolved Hide resolved
graphs/graph_adjacency_list.py Show resolved Hide resolved
graphs/graph_adjacency_list.py Show resolved Hide resolved
graphs/graph_adjacency_list.py Show resolved Hide resolved
@algorithms-keeper algorithms-keeper bot removed the require type hints https://docs.python.org/3/library/typing.html label May 30, 2023
@nith2001 nith2001 requested a review from cclauss May 30, 2023 21:53
@nith2001
Copy link
Contributor Author

nith2001 commented May 30, 2023

Took a few too many commits to resolve the type hints issue and a new ruff issue that popped up about f-strings in exceptions that didn't show up on the local ruff check. As always, appreciate the feedback!

Edit: Still ready for review, the commit below was just a minor fix I needed to make in my error messaging grammar.

@algorithms-keeper algorithms-keeper bot removed the awaiting reviews This PR is ready to be reviewed label May 31, 2023
@cclauss cclauss merged commit 4621b0b into TheAlgorithms:master May 31, 2023
@nith2001
Copy link
Contributor Author

Thanks!

sedatguzelsemme pushed a commit to sedatguzelsemme/Python that referenced this pull request Sep 15, 2024
* Improved Graph Implementations

Provides new implementation for graph_list.py and graph_matrix.py along with pytest suites for each. Fixes TheAlgorithms#8709

* Graph implementation style fixes, corrections, and refactored tests

* Helpful docs about graph implementation

* Refactored code to separate files and applied enumerate()

* Renamed files and refactored code to fail fast

* Error handling style fix

* Fixed f-string code quality issue

* Last f-string fix

* Added return types to test functions and more style fixes

* Added more function return types

* Added more function return types pt2

* Fixed error messages
@isidroas isidroas mentioned this pull request Jan 25, 2025
14 tasks
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