summaryrefslogtreecommitdiff
path: root/networkx/utils
Commit message (Collapse)AuthorAgeFilesLines
* Lint using Ruff (#6371)danieleades2023-02-195-10/+8
| | | | | | | | | | | | | | | * lint and fix using ruff * add flake8-pie lints * remove useless import alias * bump version * bump deps --------- Co-authored-by: daniel.eades <daniel.eades@hotmail.com>
* Update pytest (#6165)Jarrod Millman2022-11-011-1/+1
|
* Fix defect and update docs for MappedQueue, related to gh-5681 (#5939)Kevin Brown2022-10-042-12/+78
| | | | | | | | - Update exception message for MappedQueue when queue elements are not comparable. - Adds tests for MappedQueue elements - Adds MappedQueue to the refguide and improve documentation, esp. examples. Co-authored-by: Dan Schult <dschult@colgate.edu> Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
* Update linters (#6006)Jarrod Millman2022-09-301-1/+1
|
* make lazy_import private and remove its internal use (#5878)Dan Schult2022-07-171-2/+12
| | | | | * make lazy_import private and remove its internal use * add back the non-lazy imports of numpy to utils.misc
* Speed up unionfind a bit by not adding root node in the path (#5844)Mridul Seth2022-07-151-4/+5
| | | | | | | speed up unionfind a bit Co-authored-by: Dan Schult <dschult@colgate.edu> Co-authored-by: Dan Schult <dschult@colgate.edu>
* Remove generate_unique_node (#5780)Jarrod Millman2022-06-161-12/+0
| | | | | | | | * Remove generate_unique_node * [skip ci] rm from refguide. Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> Co-authored-by: Mridul Seth <seth.mridul@gmail.com>
* Remove deprecated function iterable (#5742)Mridul Seth2022-06-162-38/+0
| | | | Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> Co-authored-by: Jarrod Millman <jarrod.millman@gmail.com>
* Remove deprecated function utils.default_opener (#5747)Mridul Seth2022-06-161-33/+0
| | | Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
* Remove deprecated functions dict_to_numpy_array2 and dict_to_numpy_array1 ↵Mridul Seth2022-06-162-46/+0
| | | | | (#5756) Co-authored-by: Jarrod Millman <jarrod.millman@gmail.com>
* Remove decorator random_state (#5770)Dan Schult2022-06-152-23/+0
| | | Co-authored-by: Jarrod Millman <jarrod.millman@gmail.com>
* Remove deprecated function is_list_of_ints (#5743)Mridul Seth2022-06-151-20/+0
| | | Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
* Remove deprecated decorator preserve_random_state (#5768)Dan Schult2022-06-152-69/+0
|
* Remove deprecated function utils.to_tuple (#5755)Mridul Seth2022-06-152-44/+0
|
* Remove deprecated context managers (#5752)Mridul Seth2022-06-153-66/+0
|
* Remove deprecated function utils.empty_generator (#5748)Mridul Seth2022-06-151-12/+0
| | | | | | | * Remove deprecated function utils.empty_generator * Update conftest.py Co-authored-by: Jarrod Millman <jarrod.millman@gmail.com>
* Remove deprecated function utils.consume (#5745)Mridul Seth2022-06-151-17/+0
|
* Remove deprecated function is_iterator (#5740)Mridul Seth2022-06-151-16/+0
|
* Remove deprecated function make_str (#5739)Mridul Seth2022-06-152-27/+0
| | | | | | | * Remove deprecated function make_str * [skip ci] rm from reference guide. Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
* Remove deprecated function is_string_like (#5738)Mridul Seth2022-06-152-22/+0
|
* Remove unused file from utils.test (#5687)Mridul Seth2022-06-021-1/+0
|
* Use isort with pre-commit to enforce import guidelines (#5659)Mridul Seth2022-06-0212-23/+31
| | | | | * Add isort to pre-commit * Run isort on all python files (except __init__.py ones)
* Remove redundant py2 numeric conversions (#5661)Mridul Seth2022-05-311-1/+1
| | | | | | | | | * Remove redundant float conversion * Remove redundant int conversion * Use integer division Co-authored-by: Miroslav Šedivý <6774676+eumiro@users.noreply.github.com>
* Adjust the usage of nodes_or_number decorator (#5599)Dan Schult2022-05-121-2/+1
| | | | | | | | | | | | | | | | | | | | | * recorrect typo in decorators.py * Update tests to show troubles in current code * fix troubles with usage of nodes_or_number * fix typo * remove nodes_or_number where that makes sense * Reinclude nodes_or_numbers and add some tests for nonstandard usage * fix typowq * hopefully final tweaks (no behavior changes * Update test_classic.py Co-authored-by: Jarrod Millman <jarrod.millman@gmail.com>
* Fix issue probably-meant-fstring found at https://codereview.doctor (#5574)code-review-doctor2022-04-241-1/+1
|
* De-Regression: eagerly evaluate not_implemented_for in decorated generators ↵Kelly Boothby2022-04-172-35/+80
| | | | | | | | | | | (#5537) * fix for #5520 * added docs for eager_mapping; forced eager_mapping decorators to the top of generators * removed prints from tests * redo fix for #5520, forbidding try-finally argmaps from decorating generators (retain history of alternative solution)
* Update black (#5438)Mridul Seth2022-03-292-3/+3
| | | | | | | * CI: sync up black dev requirements version with precommit * Run black Co-authored-by: Jarrod Millman <jarrod.millman@gmail.com>
* Deprecate `to_tuple` (#5430)Ross Barnowski2022-03-281-0/+10
| | | | | | | | | * Add _to_tuple private fn to node_link.py. * Deprecate utils.misc.to_tuple. * Add deprecation note. * Add release note.
* Deprecate dict to numpy helpers (#5427)Ross Barnowski2022-03-262-15/+55
| | | | | | | | | | | | | * Convert to private fns and add deprecated public wrappers. * Modify existing tests to use private fns. * Add test that dep warnings are raised. * Add dep note. * Add release note. * Add importorskip(numpy).
* Minor improvements from general code readthrough (#5414)Ross Barnowski2022-03-251-0/+5
| | | | | | | | | | | | | * Add deprecated directive to reversed docstring. * Add missing dep directives to shpfiles. * Remove defn of INF sentinel. * typo. * str -> comment in forloop. * STY: appropriate casing for var name.
* Rm _inherit_doc - default behavior as of Python 3.5. (#5416)Ross Barnowski2022-03-251-18/+0
|
* Add Generator support to create_py_random_state. (#5380)Ross Barnowski2022-03-102-3/+7
| | | | | * Add Generator support to create_py_random_state. * Add explicit Generator to create_py_randomstate tests.
* Add support for `numpy.random.Generator` (#5336)Ross Barnowski2022-02-182-10/+54
| | | | | | | * Add numpy.random.Generator to create_random_state. * Modify PythonRandomInterface to support Generator + testing. * Fix failing test.
* Initial setup of lazy_import functions. (#4909)Dan Schult2022-01-251-6/+3
| | | | | | | | | | | | | | | | | | | | | | * Initial setup of lazy_import functions. Still needs: - way to handle pytest.importorskip --> soln is not to load delayed modules into sys.modules - Loader class instead of monkey patch on SourceFileLoader - Way to identify a lazily-loaded-not-yet-used module --> now create an instance of the Delayed Module class. * fix importorskip with new module class * Remove lazy_importorskip. Don't add Delayed reporting module to sys.modules * make tests work for pypy * refactor to include changes from skimage.lazy * fix test handling of types.ModuleType * Change name from nx.lazy_imports.load to nx.lazy_import * fix tests to use new name. keep `attach` name as is.
* Add Mypy type checking infrastructure (#5127)Ross Barnowski2021-11-171-4/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Add minimal mypy configuration file. * Add mypy workflow to GH. * Properly import sentinels from traversal.edgedfs. * mypy doesn't like variables named \"e\". * Rm annotations from single function. * Fix name collisions in test suite. Make sure all tests have unique names. * Rm unused random seed in test setup. * Rm redundant __all__ specification. * Silence mypy error from sum(). Mypy bug? * Fix tsp test instantiation nit. * \"type: ignore\" to suppress conditional fn sigature errors. * Remaining \"type: ignore\" to appease mypy. * Configure mypy to ignore inheritance issues. * Update exclude conf for CI. - Add yaml - Reformat regex containing reportviews * Rm partial annotations from lukes.py. Fixes mypy errors due to unannotated code. * Reorg defaultdict to reduce type: ignore cruft. * Homogenize signatures for fns defined in conditionals. * err as varname only in exception catching. * Fix name collision in Bellman-Ford test suite.
* Drop Py37 (#5143)Jarrod Millman2021-10-231-1/+1
| | | | | | | | | | | | | | | | | | | * Drop Py37 * XML serialization issue * Use math.comb Co-authored-by: Simone Gasperini <simone.gasperini2@studio.unibo.it> * Run pyupgrade --py38-plus * Run black * More documentation * Deprecate euclidean Co-authored-by: Simone Gasperini <simone.gasperini2@studio.unibo.it>
* Fix message of raised exception in decorators. (#5136)Hnatiuk Vladyslav2021-10-191-1/+1
|
* Deprecate `random_state` decorator (#5055)Ross Barnowski2021-09-122-23/+24
| | | | | | | | | | | | | | | | | * Reorganize aliases and deprecate random_state. * Rm internal uses of random_state. * Update tests. Rm tests or rename to use np_random_state. * Update reference guide. * Update deprecations.rst. * Remove preserve_random_state from refguide. * Add deprecation to release notes.
* Allow greedy_modularity_communities to use floating point weights or ↵Dan Schult2021-09-072-125/+286
| | | | | | | | | | | | | | | | | | | resolution (#5065) * revise mapped_queue to separate priority from element * update max_modularity to use new mapped_queue * change attribute names h, d to heap, position in MappedQueue * clean up initialization of data structures and handling of q0 * change i,j,k notation to u,v,w (no indexes since gh-5007) * Update networkx/utils/mapped_queue.py Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
* Fix automatic documenting of class methods via autosummary (#5021)Ross Barnowski2021-08-141-2/+4
| | | | | | | | | | | | | | | * WIP: Autogenerate stubs for class methods. Modify default autosummary/classes template to auto-generate method stubs. * WIP: preserve special-casing of __init__. __init__ method of classes is embedded in main class doc and thus should be ignored in method autosummary. * Suppress sphinx warnings. * Remove manual autosummary of ismags methods * Escape some rst characters in argmap.signature docstring.
* Style changes (#5022)Dan Schult2021-08-142-28/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Add greedy algorithm for solving TSP Many problems of Combinational Optimization can be represented as graphs. These problems have enormous significance in many aspects of science, but there are not any algorithms to solve some of them in polynomial time. However many, heuristic and metaheuristic algorithms have been published over the past years in order to solve / approximate the solutions to these problems. The purpose of this commit is to add implementation of such algorithms for solve one of the most famous problems of Combinational Optimizations, Travelling Salesman Problem (TSP). A greedy algorithm has been implemented at the moment for this reason. "applications" package has been created which include modules that represent a problem. Each module contains several algorithms for solving the specific problem. At this commit, tsp.py module is added which contains greedy_tsp() function; a implementation of a greedy algorithm. * Fix example error * Trivial changes List of changes: Removal of unnesecary _is_weighted() function Improvements on documentation * Add applications package to setup.py file * Change output of greedy algorithm Algorithm's output is a list of nodes now * Add simulated annealing algorithm Add a metaheuristic local search algorithm for solving TSP * Minor changes * Fix example doc errors * Compatible with python 3 * Move tsp module to algorithms package * Code improvements * Handle small graphs and fix doc examples * Documentation changes and rename variables * Adds Threshold Accepting algorithm for TSP * Implemented maximal matching of minimal weight and created test suite. * Removed useless print * Implemented Christofides. * Coding was missing * Add more general traveling_salesman_problem using christofides Also reconfigure import structure and remove min_weight_matching from module since it is now in matching.py * Add new functions to the docs and minor typos * pep8 fixes * fix pep8 and change .gitignore * Add tests of the approximation namespace update docs in approximation/__init__.py * Fix is_matching to check if edges in G. Other tweaks: doc changes and put not_implemented_for on find_matching functions * Improve is_matching selfloop handling and expand tests * Move tsp to approximation directory. Apply black. * Move tsp tests to approximation tests folder * Attempt to bring tsp up to current code. * commit pep8 that my black didnt change, but pep8speaks did find. ?? * tweak a few things and run black * combine #4083 and #3585 into traveling_salesman.py * Match chistofides output to other tsp functions and adjust calling syntax of tests tweak docs tweak see also section * Put big-O complexity in in-line math env. Prevents sphinx from trying to do variable substitution between pipes. * Minor touchups to christofides docstring. * RST touchups to tsp module docstring. * Rm extra string from tsp module. * Docstring touchups for traveling_salesman_problem. * rst fixups for greedy_tsp docstring. * rst formatting for simulated annealing docstring. * More math in-lining for simulated annealing docstring. * rst and minor grammatical fixes to TA docstring. * Fix path-finding and test all methods for tsp function * the refactoring was incomplete. Now maybe is - Add tests of TSP with all methods. - Refactor tests to match simulated_annealing tests and threshold tests. - Unify treatment of weight so unweighted edges use default weight 1. weight now defaults to "weight" with a default value of 1. - Rename tolerance to max_iterations (tolerance is used for error bound) - Rename iterations to N_inner (each iteration takes this many inner loops) - Introduce idioms like `pairwise` and `cycle.copy()` (over cycle[:]) - Allow passthrough of method kwargs for traveling_salesman_problem Still need to: - add test of case where path is more than one edge less that cycle (incomplete_graph) - require cycle input (maybe make default list(G)??) - consider the complexity claims in the doc_strings * More api changes to TSP functions - `chritofides` now allows (and ignores) selfloops - `move` can be a function as well as "1-1" and "1-0" - `method` for traveling_salesman_problem must have 2 arguments instead of passing kwargs. User must "curry" to set parameters - changed doc_string typos in matching.py * Add test to check that cycle=False can remove many edges * Change init_cycle api to require input from user The idea is to make the user specify the initial cycle to start from rather than relying on the programmers default of a greedy algorithm. To easy usage, I check for a string "greedy" as a shortcut. * Update docs with more correct complexity info. * Check for complete graph now more efficient and selfloops ignored * merge is_matching changes * New Networkx changes * Stub for Asadpour. Needed to create GSoC PR * Update to integrate changes from main * Added function stubs and draft docstrings for the Asadpour algorithm * Skeleton classes and methods for tree iterators * Attempting to set up basic tests for MST of a partition * testing * I'm not entirly sure how the commit hook works... * Moved iterators into the correct files to maintain proper codebase visibility * Including Black reformat * Revert "Merge branch 'networkx:main' into main" This reverts commit 0616a2331adfcc02976d305937aa52272ed48266, reversing changes made to 1ea769371f54c4c6f9a51f860caf4a60aef7d094. * Trying to merge again * Attempting to merge (4) * Now passes all tests except test_namespace_alias in /tests/test_import.py * Everything should FINALLY pass (I wipped my networkx dir and re-download from upstream) * reinstall the pre-commit hook * Grabbing black reformats * Working on debugging ascent method plus black reformats * Ascent method terminating, but at non-optimal solution * minor edits * Fixed termination condition, still given non-optimal result * Minor bugfix, still non-optimal result * Fixed subtle bug in find_epsilon() * Cleaned code and tried something which didn't work * Modified the ArborescenceIterator to accept init partition * Black formats * Branch and bound returning optimal solution * Working Ascent method, code needs cleaning * black formatting changes * Performance tweaks and testing fractional answers * Fixed test bug, I hope * Asadpour output for ascent method * Fixed numpy imports crashing pypi tests * Removed branch and bound method. One unit test misbehaving * Added asymmetric fractional test for the ascent method * Removed printn statements and tweaked final test to be more asymmetric * Draft of spanning_tree_distribution * Black changes * Changed HK to only report on the support of the answer * Fixed contraction bug by changing to MultiGraph. Problem with prob > 1 * Black reformats * Fixed pypi test error * Further testing of dist fix * Can sample spanning trees * Developing test for sampling spanning tree * Changed sample_spanning_tree test to Chi squared test * Tweaked signifiance level * Found true minimum sample size * fixed typo * untested implementation of asadpour_tsp * Fixed issue reading flow_dict * Fixed runtime errors in asadpour_tsp * black reformats * Adding test cases * documentation update * Fixed rounding error with tests * One new test and check * Documentation update for the iterators * Attempting to fix class documentation * Pull out the style changes into a separate branch * fix mixed history * more Co-authored-by: Thodoris Sotiropoulos <theosotr@windowslive.com> Co-authored-by: Luca Cappelletti <cappelletti.luca94@gmail.com> Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> Co-authored-by: mjschwenne <mjschwenne@gmail.com>
* Minor docstring cleanup to fix sphinx warning. (#5010)Ross Barnowski2021-08-071-3/+3
|
* Changes to rst files to make doctests pass (#4947)Dan Schult2021-07-071-9/+9
| | | | | | | | | | | | | | | | | | | * rst double colons for example code * add nx. prefix to doctest function calls * Remove one line from 1->2 migration rst file the line shows code that works for 1.x *and* 2.x. But it no longer works for all v2.x code. Readers should just use the next line of code, so no reason to keep this in the file. * capture output from subplot and rename DiGraph as DG in introduction.rst * skip running the entire test suite as an example in old_release_log.rst * doctest of examples * remove changes to nexp files
* Remove decorator dependency (#4739)Kelly Boothby2021-06-212-237/+1204
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * added argmap decorator * removed most dependency on decorator * removed last reference to decorator? * Made the compilation of argmap-decorated functions lazy to reduce import time. * black * reworked try_finally to make cleanup cleaner * first pass at documentation; general cleanup * incorporated dschult's comments * rest formatted docstrings * added unit tests and fixed a few bugs that cropped up * Apply suggestions from code review Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> Co-authored-by: Dan Schult <dschult@colgate.edu> * Exapnd docstrings for decorators.py * * refactored try_finally into a keyword-only argument * more tweaks to documentation re: @stefanv's comments * additional unit test for signature-clobbering decorators * spellcheck my txt and expand new test to help me grok it * rehash docstrings for sphinx * rewrite docs to provide some examples where argmap used without @argmap * doc tweak * last touches * documentation clarifications * run black * doc review * remove decorator module from github workflows and INSTALL.rst * add text to release_dev to describe highlights and improvements here Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> Co-authored-by: Dan Schult <dschult@colgate.edu>
* Refactor testing utilities (#4829)Jarrod Millman2021-05-261-0/+107
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Refactor testing utilities Change `assert_edges_equal`, `assert_graphs_equal`, and `assert_nodes_equal` to be more pytest-idiomatic. For example, `assert_edges_equal` becomes the Boolean function `edges_equal` and then the assert is done the testing file (i.e., `assert edges_equal(edges1, edges2)`). This also makes these utility functions useful in nontesting situations where you want to compare edges, but not raise an exception based on the result. * Move testing utility functions * Use new testing utilities * Deprecate assert_*_equal testing utilities * Document node, edge, and graph equality helper functions * text nits. * Update networkx/tests/test_convert_pandas.py Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> * Update networkx/readwrite/tests/test_sparse6.py Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> * Update networkx/readwrite/tests/test_graph6.py Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> * Update networkx/generators/tests/test_classic.py Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> * Update networkx/algorithms/tree/tests/test_operations.py Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> * Update networkx/algorithms/tree/tests/test_coding.py Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> * Update networkx/algorithms/tests/test_dag.py Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> * Update networkx/algorithms/minors/tests/test_contraction.py Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> * add short equality description to docstring * Suppress known warnings Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> Co-authored-by: Dan Schult <dschult@colgate.edu>
* Deprecate preserve_random_state (#4826)Jarrod Millman2021-05-201-0/+4
|
* Update black (#4814)Jarrod Millman2021-05-181-1/+1
|
* Add missing __all__'s to utils modules + test. (#4753)Ross Barnowski2021-04-253-0/+45
| | | | | Adds __all__ attrs to modules in utils and adds a test to ensure objects and aliases defined in utils modules are not unintentionally exposed in the utils namespace.
* Deprecate networkx.utils.empty_generator. (#4599)Ross Barnowski2021-02-131-2/+9
| | | | | | | | | | | | | * Deprecate networkx.utils.empty_generator. empty_generator was only used in all_simple_paths. * Add PR to release notes. * Modify empty_generator to warn on creation. Co-authored-by: Stefan van der Walt <stefanv@berkeley.edu> Co-authored-by: Stefan van der Walt <stefanv@berkeley.edu>
* Use Pillow for viewing AGraph output and deprecate default_opener (#4600)Ross Barnowski2021-02-081-0/+11
| | | | | | | * Replace utils.default_opener with Image.show(). * Deprecate nx.utils.misc.default_opener. * No PIL on pypy.