Skip to content

Conversation

xgdgsc
Copy link

@xgdgsc xgdgsc commented Feb 28, 2025

fix #361

截屏2025-03-01 09 55 01

@xgdgsc
Copy link
Author

xgdgsc commented May 23, 2025

@cjdoris any interest on reviewing?

@cjdoris
Copy link
Collaborator

cjdoris commented Sep 17, 2025

Hiya, sorry to not pick this up for a while. I actually read through this a while ago and had some reservations but forgot to reply!

It certainly seems reasonable to want to add more information to the first line, so it shows up nicely in the vscode inline viewer, but doing this in all cases where we print multiline makes the output quite noisy. For example here's how Py(rand(2,3)) is displayed currently:

Python:
Julia:
2×3 Matrix{Float64}:
 0.594056  0.325227  0.30104
 0.407524  0.754468  0.220894

versus if I add a bit of type information:

Python juliacall.ArrayValue:
Julia Matrix{Float64}:
2×3 Matrix{Float64}:
 0.594056  0.325227  0.30104
 0.407524  0.754468  0.220894

we end up with the word "Array" or "Matrix" 3 times, and "Julia" 2 times and overall it's quite a lot to take in. The old behaviour just falls back to how Julia displays the thing, plus the words "Python" and "Julia" which minimally show how the value is wrapped.

So maybe we could do this but only if we can tell it's being called to be displayed in the VSCode inline viewer. I don't know how we could reasonably do this. The only arg to show we can go off is the io which is a IOContext{Main.VSCodeServer.LimitIO{...}} when in the inline viewer, so we could switch based on the type of io but this seems brittle. I don't know if there is a better way. The context args in the IOContext don't seem to provide any useful hints:

io.dict = Base.ImmutableDict{Symbol, Any}(:displaysize => (30, 64), :color => false, :limit => true)

@xgdgsc
Copy link
Author

xgdgsc commented Sep 21, 2025

Type information might not be important to users. I' m just proposing to add size and dtype info. Is the example generated with my proposed code?

@cjdoris
Copy link
Collaborator

cjdoris commented Sep 21, 2025

Yep the example was using your branch, but I made some modifications playing around with it to see what worked.

I think what actually might be a nice simple generic thing would be to have it show like

Py: array([[ 0,  1,  2,  3,  4], ...

This would only need two very small changes:

  1. Don't insert a newline in the prefix when in compact mode (which is the right thing to do since compact is supposed to output a single line).
  2. Change the VS Code extension to print this bit with compact=true (which makes sense anyway because it wants a single line anyway).

Thoughts?

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.

Better show for numpy array
2 participants