microsoft / vscode-data-wrangler

Other
388 stars 13 forks source link

Feature: open data viewer from debug variables view #131

Closed amunger closed 1 month ago

amunger commented 5 months ago

There is a new proposed API that would enable the data wrangler extension to contribute its data visualizer for specific variables listed in the debug variables view: https://github.com/microsoft/vscode/blob/b62def4ceb2fe7c0a31908e98e76586d4a191285/src/vscode-dts/vscode.proposed.debugVisualization.d.ts#L1

With a sample implementation here: https://github.com/microsoft/vscode-extension-samples/tree/connor4312/debug-viz-demo/proposed-api-sample

If that API wouldn't work for some reason, I'm sure @connor4312 would be happy to have your feedback.

pwang347 commented 5 months ago

Hi @connor4312, it would be great to have this integrated for Data Wrangler.

I wanted to check with you: is the runtime environment exposed for the debugging context or do visualizers only have access to the serialized values?

Data Wrangler works primarily with Pandas DataFrame objects so if it is the latter we would at least need a full representation (e.g. pickled format) to be able to parse it properly. Not too sure if that would be feasible yet for perf reasons. Of course, we would ideally like access to the full runtime environment (ie. a REPL where we can run Python code) but from what I'm seeing that doesn't seem to be available.

Thanks!

connor4312 commented 5 months ago

is the runtime environment exposed for the debugging context or do visualizers only have access to the serialized values?

You can see more of a description here https://github.com/microsoft/vscode/issues/197287#issuecomment-1899409209

pwang347 commented 5 months ago

Got it, thanks for the details. I will need to play around with it some more, but tentatively it seems like we can evaluate arbitrary expressions with setExpression which is something. We will also need to think more on our side how we want the user experience for this to be.

pwang347 commented 5 months ago

related: https://github.com/microsoft/vscode-data-wrangler/issues/49

amunger commented 5 months ago

After looking into this area more, I don't think the new proposed API is required and you should be able to just contribute to the debug context menu:

"debug/variables/context": [
      {
          "command": "extension.showDataViewer",
          "group": "1_view",
          "when": "DebugSessionSupportsDataViewer"
      }
  ],

Where DebugSessionSupportsDataViewer is a context key that you would update by watching vscode.debug.onActiveDebugSessionChanged, and checking if that debug session is compatible.

The new API is more targeted towards extensions that want to provide a way to display the variable value within the variable view itself.

gkocjan commented 2 months ago

Is there a chance we can implement this feature? Right now, many people are using DataViewer in debug mode from the Jupyter Extension, but it just said that this feature is deprecated in favour of Data Wrangler.

pwang347 commented 2 months ago

Hi @gkocjan, note that it is possible already to use Data Wrangler while debugging in both the stable and pre-release versions (any of the following entrypoints should work): image

However, specifically for this button in the debug panel

image

... it's something that still needs to be hooked up. You can track the progress on it here: https://github.com/microsoft/vscode-jupyter/issues/15680

Thanks!

juanbretti commented 2 months ago

Hello @pwang347 . What you are proposing, is while using iPython (interactive Python), Jupyter Notebook or interactive Window.

Standard Python Script

When executing a standard Python Script (.py), this option is not available. For example, when debugging this file using this feature:

image

I get:

image

There is only this option:

image

And no other variables inspector.

Using interactive Python

When using interactive Python interpreter, there is the option:

image

Here is the action when clicking the "Show variable snapshot in data view":

image

What is missing

What is missing is the ability to use the Data Wrangler when debugging a Python Script, while using the standard compiler. What do you think?

Code used:

# %%
import pandas as pd

# Creating a dictionary with sample data
data = {
    'Name': ['John', 'Anna', 'Peter', 'Linda', 'Mark'],
    'Age': [25, 30, 35, 28, 40],
    'City': ['New York', 'Paris', 'London', 'Tokyo', 'Sydney'],
    'Salary': [50000, 60000, 70000, 55000, 65000]
}

# Creating DataFrame
df = pd.DataFrame(data)

# %%
print(df)

# %%
pwang347 commented 2 months ago

Hi @juanbretti, thank you for sharing more about your use case!

Just to confirm, I found that the "View Value in Data Viewer" button only appears if you have the Jupyter extension installed but it isn't present otherwise (e.g. if you disable the Jupyter extension). Let me know if my steps below are the same as yours:

Starting the debugger

image

With extension

image

Without

image

If having the Jupyter extension installed is not a problem for you, then this issue should address your ask: https://github.com/microsoft/vscode-jupyter/issues/15680

Otherwise, if you want to support this functionality for pure Python without any IPython dependency it would be good to open a new GitHub issue and continue the discussion there. Thanks!

juanbretti commented 2 months ago

@pwang347 , thank you for your prompt response. I do have installed the extensions:

When I debug using:

image

I do see:

image

But this option, opens:

image

Which is not the "Data Wrangler" variable inspector.

Does it work the same way for you too?

pwang347 commented 2 months ago

Hi @juanbretti, yes that is the way it works for me as well. I meant to say that the viewer you see is coming from the Jupyter extension currently, so there is technically a dependency on IPython (to my understanding). If that is not an issue to you, the missing functionality you described should be resolved soon from the Jupyter side. Hope this helps!

Edit: to clarify, this will also require a change in the DW extension. I will let you know when both changes are available.

7Eric9 commented 2 months ago

can't wait to use this feature!!!

gkocjan commented 2 months ago

https://github.com/microsoft/vscode-data-wrangler/issues/131#issuecomment-2099977714 My point was that the Jupyter extension showed a message that DataViewer is deprecated in favour of DataWrangler, and there is the missing feature of debugging pure .py scripts that was really well shown by @juanbretti here: https://github.com/microsoft/vscode-data-wrangler/issues/131#issuecomment-2103109736

TLDR: it would be great to use Data Wrangler from a pure Python script debugging window because it gives many more features

pwang347 commented 1 month ago

Hi all! Support for the debug variables entrypoint (for both .py and .ipynb files) is now released in VS Code Insiders.

You can give it a try with the following extension versions:

Note that this feature will also be available in the Stable version around early June. Thanks again for using Data Wrangler and for contributing to the discussion!

7Eric9 commented 1 month ago

@pwang347 I didn't find the entry for a pure .py in pre-release 1.1.2, did I missed sth? like configuration etc...

image

Maybe I should switch my vsocde from stable to insider?

juanbretti commented 1 month ago

Maybe I should switch my vsocde from stable to insider?

Yes, as mentioned before by @pwang347 , you need to try Visual Studio Code Insiders.

pwang347 commented 1 month ago

Hi @7Eric9! Yes, that is correct. If you would like to try out the experience now, you will need to use VS Code Insiders (see link shared by @juanbretti).

For a bit of explanation, this is because the Jupyter prerelease version needed above (v2024.5.2024052401) depends on the latest VS Code Insiders version, which is not yet available in VS Code Stable (but will be in about a week).

edumoros commented 1 week ago

Hello @pwang347, do you know when this feature will be available in VS Code Stable? You mentioned that it should be in early June, but I haven't seen it in the last version

pwang347 commented 1 week ago

Hello @pwang347, do you know when this feature will be available in VS Code Stable? You mentioned that it should be in early June, but I haven't seen it in the last version

Hi @edumoros! It is working for me on the following latest stable versions:

Could you please double-check if the same configuration above works for you?

edumoros commented 1 week ago

Hi @pwang347! I have those same versions, but it's not working for me.

Screenshot 2024-07-08 at 20 38 31

pwang347 commented 1 week ago

@edumoros That's odd, could you please double check that the Data Wrangler extension is not disabled? For example, by checking the extension page here:

image image

If Data Wrangler is not disabled, I would recommend opening an issue here: https://github.com/microsoft/vscode-jupyter/issues

Since the Data Viewer is being routed by the Jupyter extension and you should not see the old one if you have Data Wrangler installed. Another thing that might be worth checking is whether you are able to open the Data Wrangler viewer from debugging a .ipynb file. Thanks!

Huanyu-Liu commented 1 week ago

i am using the same versions here, but it's very unstable. Sometimes it works, but most of the time it will direct to the data wrangle extension after clicking view value in data viewer. Neither the data viewer or data wrangler window opens now.

VS Code Stable: 1.91.0 Data Wrangler Extension: 1.4.1 Jupyter Extension: 2024.6.0

image

pwang347 commented 1 week ago

@Huanyu-Liu Hi! The launch delegation is currently happening on the Jupyter extension side, could you please open an issue in the Jupyter extension repository?

It would be great if you can provide short example code to reproduce the issue. Thanks!