Skip to content

Conversation

@anna-charlotte
Copy link
Contributor

@anna-charlotte anna-charlotte commented Jan 19, 2023

Goals:

  • Add .summary() to for Document and DocumentArray.
  • Add pretty print for Document as well as DocumentArray.

Pretty prints:
image

For Document:

  • doc.summary() to display the Document instance
    • key, value (including type and shape)
    • maybe display shorter id: 2184b5 ... instead of 2184b53f977f566d72f72a6e706edb00
    • if eg. list of 200 elements is part of the Document, don't show all 200 elements, keep max size of such display manageable.
      Example:

image

  • doc.schema_summary() to display the Document's schema

For DocumentArray:

  • schema and length
  • redundant fields for v2:
    • Homogenous Documents
    • Common Attributes, instead show the schema
    • Multimodal dataclass

image

@samsja
Copy link
Member

samsja commented Jan 20, 2023

@anna-charlotte I believe we should tackle pretty printing in this PR as well.

at the moment pritting a document array will lool like this <docarray.array.abstract_array.DocumentArray[Document][MyDoc] at 0x7fb93800b5e0> which is not very informative. Same apply to document

@anna-charlotte
Copy link
Contributor Author

Wrt pretty prints: this PR only includes the pretty print for DocumentArray but not for Document, since for the latter I encountered the following problem:

rich provides a nice pretty print for pydantic models, which we would like to use as the Documents __repr__().

class MyDoc(pydantic.BaseModel):
    title: str

mydoc = MyDoc(title='my title')
rich.print(mydoc)

output:

MyDoc(
    title='my title'
)

But for the Documents .summary() we overwrite the __rich_console__() function to the tabular print wanted for the summary such as:

mydoc.summary()
-----------------------------------------
| Attribute            | Value          |
-----------------------------------------
| title                | 'my title'     |
-----------------------------------------

This __rich_console__() is also being called in the rich.print(mydoc), which results in a tabular summary display for the pretty print instead of the pydantic pretty print.

I opened a question in their discussion to see if there is a nice way to solve this.

Therefore for now only pretty print for DocumenArray.

@anna-charlotte anna-charlotte marked this pull request as ready for review January 24, 2023 13:43
@JohannesMessner
Copy link
Member

@anna-charlotte could you please link this PR/Issue to the dev roadmap and tick it off once merged?

Copy link
Member

@JohannesMessner JohannesMessner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly I am lost in all of this rich stuff, but the screenshots look pretty, so that's a thumbs up from me ^^

anna-charlotte added 24 commits January 25, 2023 14:06
Signed-off-by: anna-charlotte <[email protected]>
Signed-off-by: anna-charlotte <[email protected]>
Signed-off-by: anna-charlotte <[email protected]>
Signed-off-by: anna-charlotte <[email protected]>
Signed-off-by: anna-charlotte <[email protected]>
Signed-off-by: anna-charlotte <[email protected]>
Signed-off-by: anna-charlotte <[email protected]>
Signed-off-by: anna-charlotte <[email protected]>
Signed-off-by: anna-charlotte <[email protected]>
Signed-off-by: anna-charlotte <[email protected]>
Signed-off-by: anna-charlotte <[email protected]>
@github-actions
Copy link

📝 Docs are deployed on https://ft-feat-rich-display--jina-docs.netlify.app 🎉

@samsja samsja merged commit ac28cf3 into feat-rewrite-v2 Jan 25, 2023
@samsja samsja deleted the feat-rich-display branch January 25, 2023 13:22
JoanFM pushed a commit that referenced this pull request Jan 26, 2023
* feat: add rich display for doc and da

Signed-off-by: anna-charlotte <[email protected]>

* fix: wip plot

Signed-off-by: anna-charlotte <[email protected]>

* fix: wip plot

Signed-off-by: anna-charlotte <[email protected]>

* fix: wip plot

Signed-off-by: anna-charlotte <[email protected]>

* feat: add math package and minmax normalize

Signed-off-by: anna-charlotte <[email protected]>

* fix: summary for document

Signed-off-by: anna-charlotte <[email protected]>

* chore: update poetry lock after rebase

Signed-off-by: anna-charlotte <[email protected]>

* fix: move all from plotmixin to base document

Signed-off-by: anna-charlotte <[email protected]>

* feat: add docs schema summary

Signed-off-by: anna-charlotte <[email protected]>

* feat: add document array summary

Signed-off-by: anna-charlotte <[email protected]>

* fix: display doc within doc

Signed-off-by: anna-charlotte <[email protected]>

* fix: in notebook print docs summary

Signed-off-by: anna-charlotte <[email protected]>

* fix: move summary from da to abstract da

Signed-off-by: anna-charlotte <[email protected]>

* fix: get schema for doc

Signed-off-by: anna-charlotte <[email protected]>

* fix: wip doc summary

Signed-off-by: anna-charlotte <[email protected]>

* fix: wip clean up

Signed-off-by: anna-charlotte <[email protected]>

* test: add test for da pretty print

Signed-off-by: anna-charlotte <[email protected]>

* docs: update note

Signed-off-by: anna-charlotte <[email protected]>

* docs: add some documentation

Signed-off-by: anna-charlotte <[email protected]>

* fix: apply samis suggestion

Signed-off-by: anna-charlotte <[email protected]>

* fix: mypy checks

Signed-off-by: anna-charlotte <[email protected]>

* fix: move to plot mixin

Signed-off-by: anna-charlotte <[email protected]>

* fix: remove redundant line

Signed-off-by: anna-charlotte <[email protected]>

* fix: remove comments

Signed-off-by: anna-charlotte <[email protected]>

* feat: add schema highlighter

Signed-off-by: anna-charlotte <[email protected]>

* fix: add plotmixin to mixin init

Signed-off-by: anna-charlotte <[email protected]>

* fix: adjust da summary

Signed-off-by: anna-charlotte <[email protected]>

* fix: move minmaxnormalize to comp backend

Signed-off-by: anna-charlotte <[email protected]>

* fix: remove redundant lines

Signed-off-by: anna-charlotte <[email protected]>

* fix: add squeeze and detach to comp backend

Signed-off-by: anna-charlotte <[email protected]>

* fix: apply suggestion from code review

Signed-off-by: anna-charlotte <[email protected]>

* refactor: rename iterable attrs

Signed-off-by: anna-charlotte <[email protected]>

* fix: clean up

Signed-off-by: anna-charlotte <[email protected]>

* fix: import

Signed-off-by: anna-charlotte <[email protected]>

* fix: iterate over fields instead of annotations

Signed-off-by: anna-charlotte <[email protected]>

* fix: remove math package since moved to comp backends

Signed-off-by: anna-charlotte <[email protected]>

* refactor: use single quotes

Signed-off-by: anna-charlotte <[email protected]>

* fix: apply suggestions from code review

Signed-off-by: anna-charlotte <[email protected]>

* fix: extract summary to doc summary class

Signed-off-by: anna-charlotte <[email protected]>

* fix: add pretty print for base document

Signed-off-by: anna-charlotte <[email protected]>

* fix: use rich capture instead of string io

Signed-off-by: anna-charlotte <[email protected]>

* fix: add colors for optional and union and use only single quotes

Signed-off-by: anna-charlotte <[email protected]>

* fix: extract display classes to display package

Signed-off-by: anna-charlotte <[email protected]>

* fix: make da not optional in da summary

Signed-off-by: anna-charlotte <[email protected]>

* fix: set _console instead of initializing new one everytime in __str__

Signed-off-by: anna-charlotte <[email protected]>

* fix: put console at module level

Signed-off-by: anna-charlotte <[email protected]>

Signed-off-by: anna-charlotte <[email protected]>
Signed-off-by: Joan Fontanals Martinez <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

V2: rich display of Document and DocumentArray

4 participants