NCOL reader adds edge weights, even if they are not present in the file
Bug #572850 reported by
Gábor Csárdi
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.
Changed in igraph: | |
assignee: | nobody → Tamás Nepusz (ntamas) |
status: | Confirmed → In Progress |
Changed in igraph: | |
status: | Fix Committed → Fix Released |
To post a comment you must log in.
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.