Skip to content

feat: better repr for DataType #10391

Closed
Closed
@NickCrews

Description

@NickCrews

Is your feature request related to a problem?

This is a just a small papercut. If I have a complex dtype, the repr is hard to read, all in one line:

import ibis

dt = ibis.dtype(
    "array<struct<line1: string, line2: string, city: string, state: string, zipcode: string>>"
)
dt
# Array(value_type='Struct([('line1', String(nullable=True)), ('line2', String(nullable=True)), ('city', String(nullable=True)), ('state', String(nullable=True)), ('zipcode', String(nullable=True))], nullable=False), nullable=False)

I think the most readable form would be a pretty-printed version of the string DSL (option A):

dtype("""!array<
    !struct<
        line1: string,
        line2: string,
        city: string,
        state: string,
        zipcode: string
    >
>""")

which is also able to be copy-pasted back into a REPL to recreate the original dtype.

Could also just do the string (option B):

!array<
    !struct<
        line1: string,
        line2: string,
        city: string,
        state: string,
        zipcode: string
    >
>

We should be clever, and only do newlines/pretty if the type is over some metric of complexity, perhaps just string length?

eg I would want array<string> and not

array<
    string
>

I am basing these ideas off of two needs: human readbility, and being able to repro the dtype in the REPL from the output. Are there other considerations I'm not thinking of?

What is the motivation behind your request?

No response

Describe the solution you'd like

see above

What version of ibis are you running?

main

What backend(s) are you using, if any?

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureFeatures or general enhancements

    Type

    No type

    Projects

    Status

    done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions