NCOL reader adds edge weights, even if they are not present in the file

Bug #572850 reported by Gábor Csárdi
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
igraph
Fix Released
Medium
Tamás Nepusz

Bug Description

See the files to reproduce it at bug #572543.

Tamás Nepusz (ntamas)
Changed in igraph:
assignee: nobody → Tamás Nepusz (ntamas)
status: Confirmed → In Progress
Revision history for this message
Tamás Nepusz (ntamas) wrote :

For the record, this also holds for the LGL reader.

Now, from the point of view of the C core, the current behaviour is correct. When calling the function from the C interface, one must explicitly specify whether they are interested in edge weights and vertex names or not. If a true value is passed to the weights parameter in C, a "weight" attribute will be created no matter what. Since both the R and the Python interface pass a true value automatically, the same behaviour appears in R and Python. The problem is that users are not aware of this and they assume that the resulting graph would have edge weights if there are edge weights in the original file and would not have edge weights if the original file didn't have any. So, from the user's point of view, they think that the R and Python interface behaves as if neither true nor false would have been passed to the underlying C function, they expect something like an "AUTO" constant which resolves to true if necessary but stays false otherwise.

We have two possibilities here:

1. Modify the C core so that no weight attribute is created if the user passed weights=true but the file does not include any weights.

2. Modify the C core so that an error code is returned if the user passed weights=true but the file does not include any weights.

3. Modify the C core to accept a, say, igraph_tristate_t instead of an igraph_bool_t for the weights argument. An igraph_tristate_t could be an enum with values FALSE, TRUE and AUTO, resolving to 0, 1 and 2, respectively. With weights=FALSE, the resulting graph would never have weights. With weights=TRUE, see point 2 above. With weights=AUTO, the resulting graph would have a weight attribute iff there were weights in the file. The R and Python interfaces would then pass weights=AUTO instead of weights=TRUE.

Revision history for this message
Gábor Csárdi (gabor.csardi) wrote :

#3 is fine with me, possibly with an enum, called igraph_add_weights_t, and three possible values IGRAPH_ADD_WEIGHTS_YES, IGRAPH_ADD_WEIGHTS_NO and IGRAPH_ADD_WEIGHTS_IFPRESENT. This is quite reable in the code.

Revision history for this message
Tamás Nepusz (ntamas) wrote :

Fixed in trunk, #1900-#1901 (Python interface updated in #1903, R interface has to be done yet).

Changed in igraph:
status: In Progress → Fix Committed
Tamás Nepusz (ntamas)
Changed in igraph:
status: Fix Committed → Fix Released
Revision history for this message
Gábor Csárdi (gabor.csardi) wrote : Continue on github

The development of igraph has moved to github, so please do not comment on this bug here. You are of course welcome to comment on github, here:
https://github.com/igraph/igraph/issues/188

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.