Skip to content

Improve truncated printing for list-like objects #26

Description

@keviny2

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

https://github.com/BiocPy/BiocUtils/blob/e4d9f8bb4b89e709ea62daa119ceddd6b395334f/src/biocutils/print_truncated.py#L26-L29

Current behavior

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

importnumpyasnpfrombiocframeimportBiocFramebframe=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,

elifisinstance(x, (list, np.ndarray)):
returnprint_truncated_list(
list(x), truncated_to=truncated_to, full_threshold=full_threshold
)

Question

Should we handle other list-like objects?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions