Skip to content

Console doesn't respect numpy.set_printoptions linewidth #1044

@andrewwillowen

Description

@andrewwillowen

Description

When using bpython console, output of print(sum_numpy_array) is truncated to a line width of ~70 characters, regardless of the value set by numpy.set_printoptions(linewidth=<n_chars>). (Probably truncating to 75 characters, per the default value)

Reproduction

import numpy as np
my_array = np.random.rand(10,10)
print(my_array)  # Default width
np.set_printoptions(linewidth=500)  # Significantly increase width
print(my_array)  # See if width has changed

Output using bpython console

Launching the console with

bpython

and running the above commands, the final output stays the same width, e.g.,

[[0.16879042 0.3686932  0.11583333 0.71321688 0.13670377 0.25383321
  0.92788538 0.85056165 0.95871566 0.45657286]
 [0.49414317 0.88604218 0.49922465 0.55992626 0.42089223 0.13897627
  0.67980652 0.88978922 0.43246291 0.90526356]
 [0.33860567 0.52356898 0.75102455 0.33301567 0.7098871  0.21842158
  0.46992689 0.76128979 0.88457363 0.78181751]
 [0.81131105 0.78620507 0.42323958 0.67422569 0.55118114 0.70407957
  0.09016517 0.74287572 0.64249138 0.32268192]
 [0.73698842 0.69307092 0.53539859 0.28499058 0.21822006 0.04206897
  0.49433916 0.09354207 0.43103985 0.93385655]
 [0.57097254 0.14512517 0.2543967  0.09382002 0.45794077 0.35054257
  0.10442983 0.91845382 0.55508597 0.43811922]
 [0.11549397 0.21101277 0.33120293 0.02861319 0.68274748 0.65524105
  0.85512808 0.24291806 0.50740652 0.55194984]
 [0.75793193 0.37992667 0.9271967  0.40700423 0.87117636 0.82544539
  0.6475613  0.375711   0.10660802 0.80992348]
 [0.10731481 0.63415828 0.29611222 0.6099451  0.55459819 0.26587325
  0.02677911 0.56104341 0.11235509 0.21292126]
 [0.0105919  0.77393485 0.94602175 0.93723815 0.26395324 0.60083277
  0.9612396  0.01070631 0.28442629 0.54188245]]

Output using python3 console

Launching the console with

python3

and running the above commands, the final output changes truncation, as expected, e.g.,

[[0.46753165 0.01686997 0.70437271 0.24879456 0.02556759 0.83650928 0.43286804 0.9451887  0.46181752 0.61630296]
 [0.14566225 0.30565914 0.77176535 0.95703763 0.90894262 0.27614148 0.81659766 0.34812769 0.56174244 0.11549844]
 [0.32356831 0.25946131 0.0412169  0.75370806 0.33468114 0.20393067 0.55025587 0.44584574 0.58217767 0.0194622 ]
 [0.04457736 0.44181464 0.57638118 0.85024418 0.39383885 0.7514973  0.82326232 0.78800379 0.32851216 0.73534777]
 [0.83012166 0.02666477 0.55707597 0.57091802 0.65053171 0.38345246 0.93166186 0.35886066 0.98315683 0.29832238]
 [0.0459551  0.87111509 0.96831739 0.57373146 0.00515242 0.64619749 0.29837364 0.96973241 0.87579246 0.8223942 ]
 [0.50320441 0.80214551 0.27265131 0.43892873 0.28584371 0.17528833 0.10920415 0.18958378 0.52295676 0.24579679]
 [0.13021351 0.80121593 0.60686516 0.37569768 0.69666459 0.12626204 0.01553835 0.80746448 0.48018188 0.58879389]
 [0.02042933 0.10991487 0.50438164 0.41571544 0.37653485 0.08231128 0.36678203 0.29661942 0.8794024  0.82026911]
 [0.72970859 0.89390088 0.0175212  0.96947842 0.49559425 0.37974255 0.32831178 0.86434193 0.63606216 0.46084129]]

Details

Stumbled across this issue using the following environment (installed by uv via a hatch environment), running on Ubuntu 22.04.3 LTS via Windows Subsystem for Linux.

$ python3 -m pip freeze
attrs==25.3.0
black==25.1.0
blessed==1.21.0
bpython==0.25
certifi==2025.8.3
cfgv==3.4.0
charset-normalizer==3.4.3
click==8.2.1
coverage==7.10.6
curtsies==0.4.3
cwcwidth==0.1.10
distlib==0.4.0
filelock==3.19.1
greenlet==3.2.4
hypothesis==6.138.15
identify==2.6.14
idna==3.10
iniconfig==2.1.0
mypy_extensions==1.1.0
nodeenv==1.9.1
numpy==2.3.3
packaging==25.0
pathspec==0.12.1
platformdirs==4.4.0
pluggy==1.6.0
pre_commit==4.3.0
Pygments==2.19.2
pytest==8.4.2
pytest-cov==7.0.0
pyxdg==0.28
PyYAML==6.0.2
requests==2.32.5
scipy==1.16.2
sortedcontainers==2.4.0
urllib3==2.5.0
virtualenv==20.34.0
wcwidth==0.2.13

Additional context

This seems specific to the numpy set_printoptions function.
If I print a long string in the bpython console, it does not truncate at ~70 characters like the numpy array:

>>> print('x'*100)
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions