summaryrefslogtreecommitdiff
path: root/networkx/convert_matrix.py
Commit message (Collapse)AuthorAgeFilesLines
* Lint using Ruff (#6371)danieleades2023-02-191-1/+1
| | | | | | | | | | | | | | | * 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>
* Use scipy.sparse array datastructure (#6037)Jarrod Millman2022-10-121-7/+6
| | | | | | | | | | | | | | * Use scipy.sparse array datastructure * Add reminder to rm wrapper when scipy adds creation fns. * Rm mention of np matrix from code comment. * Update networkx/algorithms/bipartite/matrix.py Co-authored-by: Stefan van der Walt <sjvdwalt@gmail.com> Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> Co-authored-by: Stefan van der Walt <sjvdwalt@gmail.com>
* remove to/from_scipy_sparse_matrix (#5779)Matt Schwennesen2022-07-011-183/+0
| | | | | | | | * remove to/from_scipy_sparse_matrix * skip geospatial example build Co-authored-by: Mridul Seth <seth.mridul@gmail.com> Co-authored-by: Mridul Seth <mail@mriduls.com>
* Remove deprecated function nx.info (#5759)Mridul Seth2022-06-211-1/+1
| | | | | | | | | | * Remove deprecated function nx.info * remove functions from TOC * replace print(nx.info(G)) with print(G) in example Co-authored-by: Dan Schult <dschult@colgate.edu> Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
* Remove unused deprecated argument from to_pandas_edgelist (#5778)Mridul Seth2022-06-161-7/+0
|
* Remove to_numpy_matrix & from_numpy_matrix (#5746)Dilara Tekinoglu2022-06-151-212/+0
| | | | | Rm to_numpy_matrix and from_numpy_matrix and related tests Co-authored-by: dtuncturk <dilaramemis@sabanciuniv.edu>
* Rm `to_numpy_recarray` (#5737)Ross Barnowski2022-06-151-109/+1
| | | | | | | * Rm reminder from 3.0 deprecations list. * Rm to_numpy_recarray filter warning from conftest. * Deprecate to_numpy_recarray.
* Use isort with pre-commit to enforce import guidelines (#5659)Mridul Seth2022-06-021-1/+3
| | | | | * Add isort to pre-commit * Run isort on all python files (except __init__.py ones)
* Adding more examples for to_numpy_array method's usage (#5451)Dilara Tekinoglu2022-04-041-0/+27
| | | | | | | | | | | | | * Adding more examples of to_numpy_array method's usage * Run black for auto-formatting * Fixing a minor typo in the example * Fixing a minor typo in the example * Converting nonedge value to float in the example * Changed nonedge to -1. & update example to match PEP 8
* Use np.random.default_rng in example + other updates. (#5356)Ross Barnowski2022-02-221-7/+10
|
* Deprecate `to_numpy_recarray` (#5330)Ross Barnowski2022-02-181-0/+17
| | | | | * Deprecate to_numpy_recarray. * Add release note.
* Add structured dtypes to `to_numpy_array` (#5324)Ross Barnowski2022-02-181-3/+68
| | | | | | | | | | | | | | | | | | | | | | | | | * Add basic test for supporting multi-attr adjacency. * WIP: sloppy implementation of multiattr adjacency in to_numpy_array. Conditionals could be improved. * Reorg conditionals. * Test to_numpy_array raises with structured dtype for multigraphs. * Fix default value handling for structured types. * Add tests for dtypes with single field. * Parametrize field tests for directed/undirected inputs. * Handle ambiguous case: structured dtype + specified weight. * Add test for multiple fields that may/not have corresponding edge attrs. * Updated docstring. * Add tests with nonedge values + structured dtypes.
* Document default dtype in to_numpy_recarray docstring. (#5315)Ross Barnowski2022-02-101-1/+1
|
* Refactor `to_numpy_array` with advanced indexing (#5250)Ross Barnowski2022-01-271-83/+46
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * WIP: try approach based on advanced indexing. * WIP: Fix some tests and support multigraphs. * Rm test for limiting reductions to nanfunctions. * Catch edgeless graph cornercase. * Cleanups. * Update networkx/convert_matrix.py Comments from review Co-authored-by: Dan Schult <dschult@colgate.edu> * Only subgraph if necessary and copy if so, for performance reasons Co-authored-by: Dan Schult <dschult@colgate.edu> * Split multigraph and graph cases for performance. * Add tests for to_numpy_array with complex dtype. Co-authored-by: Andras Deak <deak.andris@gmail.com> * Add test for object weights. * Add test for more multiweight reduction functions. Include arbitrary functions beyond the original set of nanmin, nanmax, and nansum. * Update docstring. Co-authored-by: Dan Schult <dschult@colgate.edu> Co-authored-by: Andras Deak <deak.andris@gmail.com>
* Deprecate scipy sparse matrix conversion functions (#5262)Ross Barnowski2022-01-261-0/+16
| | | | | | | * Switch to DeprecationWarning. * Add tests and docs for scipy_sparse_matrix deps. * Update release notes.
* Use scipy.sparse array datastructure (#5139)Ross Barnowski2022-01-181-18/+185
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Step 1: use sparse arrays in nx.to_scipy_sparse_matrix. Seems like a reasonable place to start. nx.to_scipy_sparse_matrix is one of the primary interfaces to scipy.sparse from within NetworkX. * 1: Use np.outer instead of mult col/row vectors Fix two instances in modularitymatrix where a new 2D array was being created via an outer product of two \"vectors\". In the matrix case, this was a row vector \* a column vector. In the array case this can be disambiguated by being explicit with np.outer. * Update _transition_matrix in laplacianmatrix module - A few instances of matrix multiplication operator - Add np.newaxis + transpose to get shape right for broadcasting - Explicitly convert e.g. sp.sparse.spdiags to a csr_array. * Update directed_combinitorial_laplacian w/ sparse array. - Wrap spdiags in csr_array and update matmul operators. * Rm matrix-specific code from lgc and hmn modules - Replace .A call with appropriate array semantics - wrap sparse.diags in csr_array. * Change hits to use sparse array semantics. - Replace * with @ - Remove superfluous calls to flatten. * Update sparse matrix usage in layout module. - Simplify lil.getrowview call - Wrap spdiags in csr_array. * lil_matrix -> lil_array in graphmatrix.py. * WIP: Start working on algebraic connectivity module. * Incorporate auth mat varname feedback. * Revert 1D slice and comment for 1D sparse future. * Add TODOs: rm csr_array wrapper around spdiags etc. * WIP: cleanup algebraicconn: tracemin_fiedler. * Typo. * Finish reviewing algebraicconnectivity. * Convert bethe_hessian matrix to use sparse arrays. * WIP: update laplacian. Update undirected laplacian functions. * WIP: laplacian - add comment about _transition_matrix return types. * Finish laplacianmatrix review. * Update attrmatrix. * Switch to official laplacian function. * Update pagerank to use sparse array. * Switch bipartite matrix to sparse arrays. * Check from_scipy_sparse_matrix works with arrays. Modifies test suite. * Apply changes from review. * Fix failing docstring tests. * Fix missing axis for in-place multiplication. * Use scipy==1.8rc2 * Use matrix multiplication * Fix PyPy CI * [MRG] Create plot_subgraphs.py example (#5165) * Create plot_subgraphs.py https://github.com/networkx/networkx/issues/4220 * Update plot_subgraphs.py black * Update plot_subgraphs.py lint plus font_size * Update plot_subgraphs.py added more plots * Update plot_subgraphs.py removed plots from the unit test and added comments * Update plot_subgraphs.py lint * Update plot_subgraphs.py typos fixed * Update plot_subgraphs.py added nodes to the plot of the edges removed that was commented out for whatever reason * Update plot_subgraphs.py revert the latest commit - the line was commented out for a reason - it's broken * Update plot_subgraphs.py fixed node color issue * Update plot_subgraphs.py format fix * Update plot_subgraphs.py forgot to draw the nodes... now fixed * Fix sphinx warnings about heading length. * Update examples/algorithms/plot_subgraphs.py * Update examples/algorithms/plot_subgraphs.py Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> Co-authored-by: Dan Schult <dschult@colgate.edu> * Add traveling salesman problem to example gallery (#4874) Adds an example of the using Christofides to solve the TSP problem to the example galery. Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> * Fixed inconsistent documentation for nbunch parameter in DiGraph.edges() (#5037) * Fixed inconsistent documentation for nbunch parameter in DiGraph.edges() * Resolved Requested Changes * Revert changes to degree docstrings. * Update comments in example. * Apply wording to edges method in all graph classes. Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> * Compatibility updates from testing with numpy/scipy/pytest rc's (#5226) * Rm deprecated scipy subpkg access. * Use recwarn fixture in place of deprecated pytest pattern. * Rm unnecessary try/except from tests. * Replace internal `close` fn with `math.isclose`. (#5224) * Replace internal close fn with math.isclose. * Fix lines in docstring examples. * Fix Python 3.10 deprecation warning w/ int div. (#5231) * Touchups and suggestions for subgraph gallery example (#5225) * Simplify construction of G with edges rm'd * Rm unused graph attribute. * Shorten categorization by node type. * Simplify node coloring. * Simplify isomorphism check. * Rm unit test. * Rm redundant plotting of each subgraph. * Use new package name (#5234) * Allowing None edges in weight function of bidirectional Dijkstra (#5232) * added following feature also to bidirectional dijkstra: The weight function can be used to hide edges by returning None. * changed syntax for better readability and code duplicate avoidance Co-authored-by: Hohmann, Nikolas <nikolas.hohmann@tu-darmstadt.de> * Add an FAQ about assigning issues. (#5182) * Add FAQ about assigning issues. * Add note about linking issues from new PRs. * Update dev deps (#5243) * Update minor doc issues with tex notation (#5244) * Add FutureWarnings to fns that return sparse matrices - biadjacency_matrix. - bethe_hessian_matrix. - incidence_matrix. - laplacian functions. - modularity_matrix functions. - adjacency_matrix. * Add to_scipy_sparse_array and use it everywhere. Add a new conversion function to preserve array semantics internally while not altering behavior for users. Also adds FutureWarning to to_scipy_sparse_matrix. * Add from_scipy_sparse_array. Supercedes from_scipy_sparse_matrix. * Handle deprecations in separate PR. * Fix docstring examples. Co-authored-by: Mridul Seth <mail@mriduls.com> Co-authored-by: Jarrod Millman <jarrod.millman@gmail.com> Co-authored-by: Andrew Knyazev <andrew.knyazev@ucdenver.edu> Co-authored-by: Dan Schult <dschult@colgate.edu> Co-authored-by: eskountis <56514439+eskountis@users.noreply.github.com> Co-authored-by: Anutosh Bhat <87052487+anutosh491@users.noreply.github.com> Co-authored-by: NikHoh <nikhoh@web.de> Co-authored-by: Hohmann, Nikolas <nikolas.hohmann@tu-darmstadt.de> Co-authored-by: Sultan Orazbayev <contact@econpoint.com> Co-authored-by: Mridul Seth <mail@mriduls.com>
* Remove check/comment for scipy 1.1 behavior. (#5191)Ross Barnowski2021-11-221-3/+1
|
* 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>
* Change exception varname e to err (#5130)Dan Schult2021-10-151-12/+12
| | | | A more descriptive variable name for exceptions. This reduces local var naming conflicts when \`e\` is used e.g. to represent edges as a loop variable.
* Standard imports (#4401)Jarrod Millman2020-12-071-4/+5
| | | | | | | | | | | | | | | | | | | | | | | | | * Standardize pytest imports * Standardize numpy/scipy imports * Document import style * Fix * More * Fix matplotlib imports * Revert changes to tests * Motivate import policy Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> * Fix missed imports * Standard np.testing use Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
* Safer repr format of variables (#4413)Miroslav Šedivý2020-12-061-3/+3
| | | Use `!r` to trigger string repr with auto quote handling
* Update docstring for to_pandas_edgelist and add edgekey parameter (#4384)Dan Schult2020-11-241-9/+43
| | | | | | | | | | | | | | | | * Update docstring for from_pandas_edgelist Fixes #4106 Add edge_key parameter to to_pandas_edgelist, add docs and tests Add the deprecation cruft to change args of to_pandas_edgelist add back parameter "order" add line to deprecations.html to remind to remove. add line in deprecations to remind to change keyword args to * syntax add line explaining 2-release cycle for deprecations order columns for pytest * address comments
* MAINT: Deprecate numpy matrix conversion functions (#4238)Ross Barnowski2020-10-071-85/+97
| | | | | | | | | | | | | | * DEP: Deprecate to/from_numpy_matrix. Move implementation of from_numpy_matrix to from_numpy_array. * TST: Add tests and warnings filters for deprecations. * DOC: Add deprecation notes. * STY: fix autofmt'd lines in conftest. * MAINT: apply suggestions from code review.
* Format w/ black==20.8b1Jarrod Millman2020-10-061-4/+1
|
* MAINT: Update nx.info (#4193)Andrew Eckart2020-10-011-6/+1
| | | | | Report name, number of nodes, and number of edges of a graph. Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
* to_numpy/scipy array functions should not allow non-nodes in nodelist (#4216)Dan Schult2020-09-251-29/+43
| | | | | | | | | * handle nodelist better in convert_numpy and convert_scipy * allow to_numpy_array to handle graphs with no nodes * improve nodelist handling * Add description to release_dev.rst
* Format python in docstrings (#4168)Jarrod Millman2020-08-191-37/+52
| | | | | | | | | | | | | | | | | | | * Format code w/ black * Format docstrings w/ black * Manual cleanup * Tell pytest to ignore planned deprecations * Don't call plt.show during testing * Another known deprecation * DOC: rm duplicate line from docstring example * Minor cleanup Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
* Update docstring for from_pandas_edgelist (#4108)Dan Schult2020-07-261-8/+13
| | | Fixes #4106
* MAINT: rm to/from_numpy_matrix internallyRoss Barnowski2020-07-211-1/+1
| | | | | Refactors algorithms that had used to_numpy_matrix in their implementation to use to_numpy_array instead.
* DOC: Rewording re: numpy.matrixRoss Barnowski2020-07-211-14/+14
| | | | | | | | | | | | | | | * Replace references of numpy.matrix with array. * Several docstrings in convert_matrix incorrectly referred to NumPy matrices. Adds appropriate description of return types * "matrix" -> "adjacency matrix" in some docstring Notes sections to prevent confusion with the NumPy matrix object. * References to to_numpy_matrix in docstrings replaced with to_numpy_array. * rm see also ref to from_numpy_matrix
* Allow custom keys for multiedges in from_pandas_edgelist (#4076)Daniel-Davies2020-07-211-14/+55
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | * enabled feature presented in #4065, to customise key of a multigraph when using from_pandas_edgelist. Also found small doc issue in multigraph that i corrected * refactored * added unit tests * refactor * PEP8 linting corrections * added back docstring making build fail * inlined code and added docstring example * added docstring correction * added line continuation to docstring test * added AtlasView to docstring output * added AtlasView to docstring output * final clearup * make one-line error message (seems ok for black) Co-authored-by: Dan Schult <dschult@colgate.edu>
* fix bug for to_scipy_sparse_matrix function (#3985)haochenucr2020-07-101-1/+1
| | | | | | | * fix bug for to_scipy_sparse_matrix function * Add test of selfloops in convert_scipy Co-authored-by: Dan Schult <dschult@colgate.edu>
* Format w/ blackJarrod Millman2020-07-101-17/+28
|
* Fix exception causes and messages all over the codebase (#4015)Ram Rachum2020-07-051-10/+10
|
* Fix for #3930 (source & target columns not overwritten when converting to ↵Isaac Boates2020-05-191-34/+31
| | | | | | | | | | | | | | | | | | pd.DataFrame) (#3935) * Added exception raise if source or target column name already exists as edge attributes when converting to pandas edgelist * Added exception raise if source or target column name already exists as edge attributes when converting to pandas edgelist * Fixed tests not asserting properly * Separate test for default and custom case, shortened exception text, made graph creation in test more efficient * Take the chance to update some other PEP8 issues in these modules. * tweak comment line Co-authored-by: iboates <isaac.boates@eifer.uni-karlsruhe.de> Co-authored-by: Dan Schult <dschult@colgate.edu>
* Fixed nx.Digraph to nx.DiGraph (#3909)Bastian David2020-04-131-4/+4
| | | Fixes #3867
* Fix scipy deprecation warningsJarrod Millman2020-01-031-68/+132
|
* Update string formatJarrod Millman2020-01-011-4/+4
| | | | | | | | | find -name "*py" | xargs grep -n '" % ' find -name "*py" | xargs grep -n '"\.format(' find -name "*py" | xargs grep -n "' %" find -name "*py" | xargs grep -n 'msg % ' find -name "*py" | xargs grep -n ' %d ' find -name "*py" | xargs grep -n '\.format('
* Convert %-format to fstringJarrod Millman2020-01-011-7/+5
|
* Remove boiler plate from top of modulesJarrod Millman2019-11-111-6/+0
| | | | | | | | | The copyright and author stuff is not necessary, out-of-date, and inconsistent. It takes up visual space and is a pain to police everyone doing the same thing on the top of the module. Git handles authorship in a comprehensive and authoritative way. The LICENSE.txt file applies to all project code.
* Skip doctests when missing dependenciesJarrod Millman2019-10-211-8/+0
|
* PEP8 fixes to testsJarrod Millman2019-10-181-2/+2
|
* Remove old Python 2 codeJarrod Millman2019-10-181-5/+1
|
* Use pytest for doctestJarrod Millman2019-10-121-14/+1
|
* Remove nose from generatorsJarrod Millman2019-10-121-1/+1
|
* More doctest correctionsDan Schult2019-10-121-1/+1
|
* Changes to convert_matrix and others that depend on np.matrixDan Schult2019-10-121-6/+5
|
* convert_matrix demo of one way to get doctests to workDan Schult2019-10-121-23/+28
|
* Handle edgeattr in from_pandas_edgelist when no columns match request (#3634)Dan Schult2019-10-041-10/+12
| | | Fixes #3562
* Replaced is with == and minor pycodestyle fixes (#3608)Aditya Pal2019-09-281-8/+9
| | | | | | | | | | Fixes #3605 * Replaced is with == and minor pycodestyle fixes * Changed exception style as per feedback * Implementing code feedback