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

Avoid printing empty tables and panels #64

Open
pederhan opened this issue Apr 12, 2023 · 0 comments
Open

Avoid printing empty tables and panels #64

pederhan opened this issue Apr 12, 2023 · 0 comments
Labels
Cosmetic Cosmetic modifications

Comments

@pederhan
Copy link
Member

pederhan commented Apr 12, 2023

In order to avoid printing empty panels and tables, we should have a utility function that checks if a renderable is empty, and if so print a message like "No data..." or something similar.

In the case of tables, we could simply check the Table.row_count attribute to check if the table has any rows. For Panels, we would have to check every renderable inside the panel, probably recursively in case the panel contains another panel or group.

Something like:

def is_empty(renderable: RenderableType) -> bool:
    """Check if a renderable is empty."""
    if isinstance(renderable, Table):
        return renderable.row_count <= 0
    elif isinstance(renderable, Panel):
        return is_empty(renderable.renderable)
    elif isinstance(renderable, Group):
        for child in renderable.children:
            if not is_empty(child):
                return False
    else:
        return False
    return True

Although it would probably turn out to be quite a bit more complex than this in practice.

@pederhan pederhan added the documentation Improvements or additions to documentation label Apr 12, 2023
@pederhan pederhan added this to Harbor Apr 12, 2023
@pederhan pederhan added Cosmetic Cosmetic modifications and removed documentation Improvements or additions to documentation labels Apr 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Cosmetic Cosmetic modifications
Projects
None yet
Development

No branches or pull requests

1 participant