Skip to content

Conversation

cjdoris
Copy link
Collaborator

@cjdoris cjdoris commented Oct 8, 2025

In an IO context with compact=true, force the output to be a single line by replacing newlines with spaces.

If also limit=true, then truncate to one screen-width of output (i.e. one line) instead of one screen-full.

This makes printing of complex Python objects inside Julia arrays much nicer, such as:

julia> [np.random.rand(3,4) for _ in 1:3, _ in 1:3]
3×3 Matrix{Py}:
 array([[0.79715113, 0.83654893, 0.3008 ... 0.93258346, 0.62550964, 0.26787152]])  …  array([[0.73059587, 0.40056331, 0.0894 ... 0.94392892, 0.46400378, 0.13055773]])
 array([[0.92264918, 0.72076772, 0.6071 ... 0.05808218, 0.83883545, 0.23057753]])     array([[0.45971939, 0.81343033, 0.1869 ... 0.70010399, 0.53587046, 0.76999567]])
 array([[0.7933009 , 0.31953895, 0.7579 ... 0.47164865, 0.29715604, 0.5934403 ]])     array([[0.20724639, 0.76885944, 0.2058 ... 0.52625401, 0.71134752, 0.29692726]])

instead of this mess:

julia> [np.random.rand(3,4) for _ in 1:3, _ in 1:3]
3×3 Matrix{Py}:
 array([[0.54419557, 0.39819626, 0.23586015, 0.53822676],
       [0.6720559 , 0.82561704, 0.47703638, 0.90532732],
       [0.72706845, 0.14721132, 0.3037623 , 0.9163008 ]])  …  array([[0.08410984, 0.82419775, 0.89974616, 0.26844754],
       [0.87755284, 0.85069728, 0.79350635, 0.99253124],
       [0.63162664, 0.94685745, 0.45472159, 0.31408651]])
 array([[0.39378457, 0.1088128 , 0.42487836, 0.62327642],
       [0.6925987 , 0.30756797, 0.47317789, 0.98626029],
       [0.25974422, 0.62635918, 0.02137454, 0.17354563]])     array([[0.28815445, 0.91965669, 0.22342196, 0.43744798],
       [0.21790796, 0.96728322, 0.07411956, 0.88815802],
       [0.70591267, 0.24503941, 0.35849102, 0.19174126]])
 array([[0.15277849, 0.4535507 , 0.36206123, 0.67342048],
       [0.74135781, 0.05503536, 0.49546308, 0.03800956],
       [0.50645603, 0.06412445, 0.44264083, 0.23803791]])     array([[0.59485512, 0.94669031, 0.48734943, 0.67408912],
       [0.20983381, 0.18483092, 0.67507395, 0.27513866],
       [0.51489021, 0.11395934, 0.19776963, 0.71910407]])

Alternative to #595. Partial fix for #361.

@cjdoris cjdoris merged commit e358a52 into main Oct 9, 2025
15 of 16 checks passed
@cjdoris cjdoris deleted the compact branch October 9, 2025 20:00
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

Successfully merging this pull request may close these issues.

1 participant