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

custom attribute composition in graphml #3248

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

gabri94
Copy link

@gabri94 gabri94 commented Nov 17, 2018

Hi, i realized that is not possible to write graph with custom object as attribute.
I was replacing them by their str representation just before saving, but I think this could be a cleaner and more general solution for the problem.
I already had open an issue #3237.

I'm not sure whether should be use str or repr. As a first try i used str, because it was much cleaner and linear than redefining make_str()
But I'm here for your feedback.

@gabri94 gabri94 changed the title custom object composition in graphml custom attribute composition in graphml Nov 17, 2018
@dschult
Copy link
Member

dschult commented Nov 19, 2018

It looks like you have change the keyid to be "string" for unknown data types, but don't you have to change the code that generates the string? It's been a long time since I looked at this code -- and I am traveling so am short on time to investigate further right now.

Please also include a test in tests/test_graphml.py that writes a graph that has a custom object as a data attribute. Then read it back in and check that the result gives what you expect. The doc_string for the function will also need to be updated.

Thanks!

@gabri94
Copy link
Author

gabri94 commented Nov 25, 2018

There's a function called make_str() that is called on the value of all the attributes. For this reason i don't need to transform the Object to a string. The only thing preventing this is the check on the datatype of the attribute. So changing it to string when it's unrecognized is enough to have it converted.
My question is: make_str() takes the str of the object. Is that ok or the repr of the object shoud be used instead?

@dschult
Copy link
Member

dschult commented Nov 26, 2018

I actually don't know which would cause fewer surprises -- str or repr?
What would be best in your use-case?

@gabri94
Copy link
Author

gabri94 commented Dec 4, 2018

In my use case it would be the same since I made my custom object myself. Idk in a more general way what should be the difference

@dschult
Copy link
Member

dschult commented Dec 4, 2018

There are some discussions about the difference between repr and str. My understanding is that typically: str is a readable description of the object. repr is some text that unambiguously describes the object -- best case: repr shows python code that could regenerate the object.

In many cases they are the same. One that isn't is:
str("3")==str(3)=='3' but
repr("3")=="'3'" has an extra set of quotes, so it is the code that would create "3".

In the end it probably doesn't matter much, but if the goal is to be able to recreate the object perhaps repr would be better. If the goal is to make it readable, the str is better.

Base automatically changed from master to main March 4, 2021 18:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants