You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Sep 9, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Sep 9, 2026. It is now read-only.
Hi. I can take it up if a fix for this has not already been merged. I went through the library and looked at the BaseDoc class and had a couple of questions
Would I be documenting the behaviour of this class method inside BaseDoc
From what I can understand, if dict(doc) is called on a BaseDoc object it should return the attributes set and calling doc.dict() would return model created as shown in the issue description.
Can you guide me on what the appropriate documentation would be?
@punndcoder28 I suggest you start by writing the a small documentation example in this issue. Something with code snippets to explain the behavior. Then I will point you where you should add it in the documentation
Sure @samsja will do that. I want to know if I have understood the working of both the methods as mentioned earlier in this comment. If that is confirmed will work on writing a draft changes here along with the code changes for your reviews.
The stark difference I see between the two dict methods is doc.dict() would print the attribute details even when there is nesting but dict(doc) prints the attributes on the same level as the object but when there is nesting it will only print the type of the attribute which has the nesting, like how it has done for 'l': <DocList[InnerDoc] (length=2)>. Have I understood it correctly?
It is also worth noting that when there are attributes with types such as List, Dict, Tuple, DocList or other types which can have nested objects, then the output of this method will only specify the type of the object. Consider the below example
from docarray import BaseDoc, DocList
class ParentDoc(BaseDoc):
parent_attribute: str
class MyDoc(BaseDoc):
my_attribute: DocList[ParentDoc]
doc_object = MyDoc(my_attribute=[ParentDoc(parent_attribute='first'), ParentDoc(parent_attribute='second')])
print(f'{dict(doc_object)=}')
doc.dict(): The dict() method when called on an object of type BaseDoc or it's inherited classes will print out the fields and the contained values even when there is nesting. Let us consider the below example
from docarray import BaseDoc, DocList
class ParentDoc(BaseDoc):
parent_attribute: str
class MyDoc(BaseDoc):
my_attribute: DocList[ParentDoc]
doc_object = MyDoc(my_attribute=[ParentDoc(parent_attribute='first'), ParentDoc(parent_attribute='second')])
print(f'{doc_object.dict()=}')
The output of the print(f'{doc_object.dict()=}') will print the values contained within the my_attribute class attribute
Activity
athleticcoder21 commentedon May 23, 2023
Hi, can I take this issue up? I would like to contribute
JoanFM commentedon May 23, 2023
Hey @shivance ,
For sure, I will assign it to you.
punndcoder28 commentedon Jun 3, 2023
Hi. I can take it up if a fix for this has not already been merged. I went through the library and looked at the
BaseDocclass and had a couple of questionsBaseDocdict(doc)is called on aBaseDocobject it should return the attributes set and callingdoc.dict()would return model created as shown in the issue description.athleticcoder21 commentedon Jun 3, 2023
@punndcoder28 You could take this up ! Sorry, I've got a bit busy lately, it would be delayed at my end.
samsja commentedon Jun 6, 2023
@punndcoder28 I suggest you start by writing the a small documentation example in this issue. Something with code snippets to explain the behavior. Then I will point you where you should add it in the documentation
punndcoder28 commentedon Jun 6, 2023
Sure @samsja will do that. I want to know if I have understood the working of both the methods as mentioned earlier in this comment. If that is confirmed will work on writing a draft changes here along with the code changes for your reviews.
samsja commentedon Jun 6, 2023
I am not sure what you mean in this sentence
punndcoder28 commentedon Jun 6, 2023
Sorry, should have worded it better. The below example should help. Suppose I have a class
MyClasslike belowand when I initialise the object
class_ob = MyClass('name', 20)and printprint(dict(class_obj))it will printWould that be the same for when
dict(doc)is called from the issue descriptionsamsja commentedon Jun 6, 2023
I suggest you to run the example in description and look at the difference between calling:
In your example it will be the same, there will be a real difference only if there is a nested doc
punndcoder28 commentedon Jun 6, 2023
Ok. Will run the code and check the difference out. But shouldn't it not print the attributes of the inherited classes as well?
samsja commentedon Jun 6, 2023
yes it should
punndcoder28 commentedon Jun 7, 2023
Ran the code from the issue description and got the below output
The stark difference I see between the two
dictmethods isdoc.dict()would print the attribute details even when there is nesting butdict(doc)prints the attributes on the same level as the object but when there is nesting it will only print the type of the attribute which has the nesting, like how it has done for'l': <DocList[InnerDoc] (length=2)>. Have I understood it correctly?punndcoder28 commentedon Jun 9, 2023
Please review the initial draft of the doc changes I want to propose
dict(doc): Thedict()method when called with the argument of typeBaseDocreturns the class attribute values set. Let us consider the below exampleThe above code example prints the following
It is also worth noting that when there are attributes with types such as
List,Dict,Tuple,DocListor other types which can have nested objects, then the output of this method will only specify the type of the object. Consider the below examplewhich will output
doc.dict(): Thedict()method when called on an object of typeBaseDocor it's inherited classes will print out the fields and the contained values even when there is nesting. Let us consider the below exampleThe output of the
print(f'{doc_object.dict()=}')will print the values contained within themy_attributeclass attribute@samsja Would be awesome if you can take a look at the initial draft and suggest changes. Thanks!
samsja commentedon Jun 12, 2023
hey @punndcoder28 this looks nice, could you open a PR so that I can suggest you edit directly there ?
Thanks for you contribution 🚀
punndcoder28 commentedon Jun 12, 2023
Thanks @samsja ! I have opened #1643 which adds more docs as discussed on this thread. Would love if you can review the pull request