haochengxia / vscode-pydata-viewer

Display PyData files (.npz .npy .pkl .pth) in VSCode.
https://marketplace.visualstudio.com/items?itemName=Percy.vscode-pydata-viewer
MIT License
14 stars 8 forks source link

Add comma to numpy output #28

Closed fanzfan closed 1 month ago

fanzfan commented 1 month ago

Adding commas as the separator between per elements makes it easy to copy from numpy outputs.
I am glad to work on this.

# Before
Shape(10)
[1 2 3 4 5 6 7 8 9 10]
# If you copy the output, you cannot use it directly
arr = [1 2 3 4 5 6 7 8 9 10]    # illegal expression

# After
Shape(10)
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]    # legal, and easy to use
haochengxia commented 1 month ago

Sounds good! This feature would enhance the convenience of using this extension in a data science workflow.

fanzfan commented 1 month ago

Hi @haochengxia, I found a compatibility problem, in "pydataPreview.js line 159", python does not support " " space. We should use " ", the example is as follows:

# &ensp
arr = [1, 2, 3, 4, 5, 6, 7, 8]
# SyntaxError: invalid non-printable character U+2002

# &nbsp
arr = [1, 2, 3, 4, 5, 6, 7, 8]
# ok
haochengxia commented 1 month ago

Closed by Pull Request #29.