igraph / python-igraph

Python interface for igraph
GNU General Public License v2.0
1.31k stars 249 forks source link

Add C argument prefixattr to Python interface of write_graphml #759

Closed carissableker closed 9 months ago

carissableker commented 9 months ago

Description

The C library function to write graphml files has an argument to prevent igraph adding the prefixes v_, e_ etc to the attributes. https://github.com/igraph/igraph/blob/df356b9641db0278a5dbfd21741066608f17a957/src/io/graphml.c#L1744

This argument is missing in the Python interface write_graphml, and would be useful to be added.

Use cases for the feature

I am using igraph to read/write graphml files, but I also expect files to come from other sources (i.e. not written by igraph). This means that the attribute naming when loading files is inconsistent between software.

My use case: an argument to my function is the name of an edge attribute of interest. If the user passes the attribute (e.g. edge weight) as they see it written in the graphml file, they may see "weight" or "e_weight", depending on whether or not it was written by igraph. Igraph will load "eweight" as "weight", and the argument that the user passed may be then incorrect. In my code, I have to test if <user argument> or `re.findall(r"e\(.*)", )[0]` is present, and make a judgement on what to use.

Perhaps ideally Read_graphML has an argument to not remove the prefixes, so that what is in the file is consistent with what is loaded, but since prefixattr is already implemented in the C write function, I can add instructions to my users when writing files, and what is present in the file is consistent with how it is loaded.

ntamas commented 9 months ago

Thanks, the missing argument has now been added to the C core and it will be released in version 0.11.5.

How urgent is this for you? You just missed the release of igraph 0.11.4, which came out yesterday, but as there was no announcement yet, I can make a 0.11.5 soon(ish) if this is important for you.

carissableker commented 9 months ago

Thanks! That was very fast :+1:

There's no urgency, the next planned release is perfect.