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

Improve truncated printing for list-like objects #26

Open
keviny2 opened this issue Feb 28, 2025 · 0 comments
Open

Improve truncated printing for list-like objects #26

keviny2 opened this issue Feb 28, 2025 · 0 comments

Comments

@keviny2
Copy link

keviny2 commented Feb 28, 2025

print_truncated() does not handle other list-like objects (e.g. numpy arrays), making for messy outputs for __repr__().

elif isinstance(x, list):
return print_truncated_list(
x, truncated_to=truncated_to, full_threshold=full_threshold
)

Current behavior

When executing in a jupyter notebook, the output is not truncated:

import numpy as np
from biocframe import BiocFrame

bframe = BiocFrame(
    {
        "x": np.random.normal(size=40),
        "y": np.random.normal(size=40)
    }
)
bframe

>>
BiocFrame(data={'x': array([ 0.30948609, -1.38289079, -0.43285149,  0.37465808,  0.47068355,
        0.72958816, -1.99939489,  0.22849544, -0.15900403,  0.1183286 ,
       -0.12025139, -0.31011542,  0.2261699 , -1.23073433, -0.98790469,
        0.37100134,  1.11801526,  1.89313668, -0.72167481,  1.21427698]), 'y': array([-0.96331348,  0.90240032,  0.45289567,  0.74154537,  0.09252068,
       -0.30991981,  0.81609081, -0.21092948,  0.17191497,  0.01036059,
        0.21667765, -0.35905261, -0.53184703, -0.64036229,  0.25275972,
       -0.31644878, -0.57082027, -0.39594529,  2.26653958, -0.31656108])}, number_of_rows=20, column_names=['x', 'y'])

Proposed solution

As a start,

elif isinstance(x, (list, np.ndarray)):
    return print_truncated_list(
        list(x), truncated_to=truncated_to, full_threshold=full_threshold
    )

Question

Should we handle other list-like objects?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant