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

Read/write/generate a basic graph using UCINET DL format #2052

Closed
wants to merge 9 commits into from

Conversation

Temigo
Copy link

@Temigo Temigo commented Mar 30, 2016

Functions and tests for UCINET DL format.
(Currently supports only 'fullmatrix' format for data. There are many variants for UCINET DL format, this implementation only covers the basic one for now.)

This is related to issue #2051. Thanks !

Functions and tests for UCINET DL format.
Currently supports only 'fullmatrix' format for data.
@jfinkels
Copy link
Contributor

There are already some functions for reading and writing e.g. adjacency matrices, perhaps those can be used so you don't need to reimplement an adjacency matrix reader/writer?

@dschult
Copy link
Member

dschult commented Mar 30, 2016

The test errors all seem to relate to a print statement left in place.
Could you also add line breaks to keep the code below 80 chars per line?

How likely are people to want the "variant" forms of the UCINET DL format? What is the best way to handle that? Are there easy converters from one variant to another?

Remove print statements, shorten lines under 80 characters per line.
@Temigo
Copy link
Author

Temigo commented Mar 31, 2016

Sorry, I cleaned the code and I hope the test will pass now.

I was thinking of two kind of "variants" :

  • variants in the way options are given (for example labels can be specified before the data or directly with the data, the latter isn't handled yet).
  • variants in the way of formatting data (fullmatrix is the adjacency matrix, upper half is only half of the symmetric matrix, etc)
    However until now I have only encountered data formatted in fullmatrix. I will have a look at functions for adjacency matrices, thanks.

I plan to implement all of these variants in a near future. Maybe you would prefer to wait for the whole and complete implementation ?

@hagberg
Copy link
Member

hagberg commented Apr 1, 2016

@jfinkels has a good idea here to use existing readers to help make writing this easier.

I looked at the formats for UCINET DL

They all are basic text files with a header and then data. Perhaps the simplest approach is to write a function that will parse the header and dispatch based on that.

e.g. for

DL n=5
format = edgelist1
labels:
george, sally, jim, billy, jane
data:
1 2
1 3
2 3
3 1
4 3

The steps would be

  • Parse the lines before "data" - e.g. create label mapping made {1: george, 2:sally, ...}
  • Call parse_edgelist() on the rest of the file
  • Relabel nodes with the mapping

In that case we already have an edgelist reader.

For matrix formats we could fairly simply use either one of

For writing data a similar approach could be used.

To parse data, use functions already existing in Numpy and Networkx
such as genfromtxt and from_numpy_matrix.
Add `nodelist1` and `nodelist1b` data format support.
Also adds support for embedded labels.
Use `to_numpy_matrix` in `generate_ucinet`
Update tests of `generate_ucinet`
Fix bugs occurring with Python3 (bytes string for genfromtxt)
@Temigo
Copy link
Author

Temigo commented Apr 2, 2016

Thank you for your advices. I committed some changes according to this. However the checks failed because of Numpy's import : how should I import it ?

@dschult
Copy link
Member

dschult commented Apr 2, 2016

Since the pypy standard build doesn't include numpy, you'll have to make the tests skip your module when numpy is not available. Any module that uses numpy should have the code to skip tests at the bottom, for example the bottom of graphmatrix.py

Add support for `edgelist1` format
+ fixture for Numpy import
Fixture Nose with NumPy and fix reading irregular matrices (in genfromtxt).
@hagberg hagberg added this to the networkx-future milestone Apr 11, 2016
Base automatically changed from master to main March 4, 2021 18:20
@MridulS
Copy link
Member

MridulS commented Nov 8, 2023

Thanks for your work on this @Temigo!

Unfortunately we haven't reviewed this in a long time, sorry about that! A lot of things have changed in networkx in the last 7 years so we would need to put in some effort to make this PR mergeable.

I think we also need to be a bit conservative in adding new I/O formats in networkx, so the code can be maintainable. I have added this to #7099 that tracks future wishlist/good ideas/maybes and once we have a decision we can move forward with the implementation bits. Thanks again!

@MridulS MridulS closed this Nov 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

5 participants