microsoft / vscode-jupyter

VS Code Jupyter extension
https://marketplace.visualstudio.com/items?itemName=ms-toolsai.jupyter
MIT License
1.3k stars 293 forks source link

Variables View becomes empty during loading of variables #13387

Closed phillies closed 1 year ago

phillies commented 1 year ago

Applies To

What happened?

After opening the variables view and running some code in a jupyter cell, the variables are shown as loading in the variables view, then the view gets completely empty. Even the table headlines disappear.

https://user-images.githubusercontent.com/1006347/234009411-38bd83f0-85a7-4c6d-9f07-5b2a5850aef8.mp4

VS Code Version

Version: 1.77.3 (user setup) Commit: 704ed70d4fd1c6bd6342c436f1ede30d1cff4710 Date: 2023-04-12T09:16:02.548Z Electron: 19.1.11 Chromium: 102.0.5005.196 Node.js: 16.14.2 V8: 10.2.154.26-electron.0 OS: Windows_NT x64 10.0.19045 Sandboxed: Yes

Jupyter Extension Version

v2023.3.1201040234

Jupyter logs

Visual Studio Code (1.77.3, undefined, desktop)
Jupyter Extension Version: 2023.3.1201040234.
Python Extension Version: 2023.6.1.
Workspace folder c:\Users\xxxxxx\AppData\Local\projects\xxxxxx
User belongs to experiment group 'jupyterEnhancedDataViewer'
User belongs to experiment group 'jupyterTest'
info 15:15:42.325: LSP Notebooks experiment is enabled
info 15:15:49.419: Starting Jupyter Session startUsingPythonInterpreter, .jvsc74a57bd036997203cb54efebaebb04eb6bef1133d33786fdfa4d240e847adfae69ad1d73.c:\Users\xxxxxx\AppData\Local\miniconda3\envs\xxxx\python.exe.c:\Users\xxxxx\AppData\Local\miniconda3\envs\xxxxx\python.exe.-m#ipykernel_launcher (Python Path: c:\Users\xxxxx\AppData\Local\miniconda3\envs\xxxxx, EnvType: Conda, EnvName: 'xxxxx', Version: 3.8.16 | packaged by conda-forge | (default, Feb  1 2023, 15:53:35) [MSC v.1929 64 bit (AMD64)]) for 'c:\Users\xxxxx\AppData\Local\projects\xxxxx\test2.ipynb' (disableUI=true)
info 15:16:19.908: Process Execution: > ~\AppData\Local\miniconda3\envs\xxxxx\python.exe -c "import ipykernel; print(ipykernel.__version__); print("5dc3a68c-e34e-4080-9c3e-2a532b2ccb4d"); print(ipykernel.__file__)"
> ~\AppData\Local\miniconda3\envs\xxxxx\python.exe -c "import ipykernel; print(ipykernel.__version__); print("5dc3a68c-e34e-4080-9c3e-2a532b2ccb4d"); print(ipykernel.__file__)"
info 15:16:20.192: Process Execution: > ~\AppData\Local\miniconda3\envs\xxxxx\python.exe -m pip list
> ~\AppData\Local\miniconda3\envs\xxxxx\python.exe -m pip list
info 15:16:20.491: Process Execution: > ~\AppData\Local\miniconda3\envs\xxxxx\python.exe ~\.vscode\extensions\ms-toolsai.jupyter-2023.3.1201040234\pythonFiles\vscode_datascience_helpers\kernel_interrupt_daemon.py --ppid 30100
> ~\AppData\Local\miniconda3\envs\xxxxx\python.exe ~\.vscode\extensions\ms-toolsai.jupyter-2023.3.1201040234\pythonFiles\vscode_datascience_helpers\kernel_interrupt_daemon.py --ppid 30100
info 15:16:20.491: Process Execution: cwd: ~\.vscode\extensions\ms-toolsai.jupyter-2023.3.1201040234\pythonFiles\vscode_datascience_helpers
cwd: ~\.vscode\extensions\ms-toolsai.jupyter-2023.3.1201040234\pythonFiles\vscode_datascience_helpers
info 15:16:21.248: Process Execution: > ~\AppData\Local\miniconda3\envs\xxxxx\python.exe -m ipykernel_launcher --ip=127.0.0.1 --stdin=9003 --control=9001 --hb=9000 --Session.signature_scheme="hmac-sha256" --Session.key=b"d7561307-7906-4367-a6cc-3949544cb6a2" --shell=9002 --transport="tcp" --iopub=9004 --f=c:\Users\xxxxx\AppData\Roaming\jupyter\runtime\kernel-v2-30100UuAUdxf7u72Y.json
> ~\AppData\Local\miniconda3\envs\xxxxx\python.exe -m ipykernel_launcher --ip=127.0.0.1 --stdin=9003 --control=9001 --hb=9000 --Session.signature_scheme="hmac-sha256" --Session.key=b"d7561307-7906-4367-a6cc-3949544cb6a2" --shell=9002 --transport="tcp" --iopub=9004 --f=c:\Users\xxxxx\AppData\Roaming\jupyter\runtime\kernel-v2-30100UuAUdxf7u72Y.json
info 15:16:21.248: Process Execution: cwd: ~\AppData\Local\projects\xxxxx
cwd: ~\AppData\Local\projects\xxxxx
info 15:16:22.011: ipykernel version & path 6.19.2, ~\AppData\Local\miniconda3\envs\xxxxx\lib\site-packages\ipykernel\__init__.py for c:\Users\xxxxx\AppData\Local\miniconda3\envs\xxxxx\python.exe
info 15:16:28.092: Started Kernel xxxxx (Python 3.8.16) (pid: 24780)
info 15:16:28.290: Process Execution: > ~\AppData\Local\miniconda3\envs\xxxxx\python.exe ~\.vscode\extensions\ms-toolsai.jupyter-2023.3.1201040234\pythonFiles\printJupyterDataDir.py
> ~\AppData\Local\miniconda3\envs\xxxxx\python.exe ~\.vscode\extensions\ms-toolsai.jupyter-2023.3.1201040234\pythonFiles\printJupyterDataDir.py
warn 15:16:28.701: Got a non-existent Jupyer Data Dir file:///c%3A/Users/xxxxx/AppData/Roaming/Python/share/jupyter
info 15:16:34.302: Loading webview. View is notset
info 15:16:34.306: Loading web view...
info 15:16:34.308: Webview panel created.
info 15:16:35.065: Web view react rendered

Coding Language and Runtime Version

python v3.8.16

Language Extension Version (if applicable)

No response

Anaconda Version (if applicable)

No response

Running Jupyter locally or remotely?

Local

phillies commented 1 year ago

Example code from the bug video:

from typing import Optional
import numpy as np
import pandas as pd
from sqlmodel import SQLModel
from pandera import SchemaModel
from pandera.engines.pandas_engine import PydanticModel
from pandera.typing import DataFrame

df_new = pd.read_csv(
    'testdata.csv',
    encoding="utf-8",
    quotechar="'",
    keep_default_na=False,
    na_values=set([""]),
)
display(df_new)
display(df_new.dtypes)

class DemoModel(SQLModel):
    name: str
    value: Optional[int]
    value2: int

class PanderaModel(SchemaModel):
    class Config:
        dtype = PydanticModel(DemoModel)
        coerce = True
amunger commented 1 year ago

I can't get this to repro, but I suspect it is something in the csv file being read. How large is that file? would you be able to attach it here?

phillies commented 1 year ago

That's a tiny test file:

name,value
'A',1
'B',

(last value is intentionally omitted to read a NaN)

amunger commented 1 year ago

huh, still no repro for me, but we could just take a look at that code.

tamasfe commented 1 year ago

The following code reliably reproduces the issue for me:

from pydantic import BaseModel

def to_camel(string: str) -> str:
    pascal = "".join(word.capitalize() for word in string.split("_"))

    if len(pascal) == 0:
        return pascal

    return pascal[0].lower() + pascal[1:]

class MyModel(BaseModel):
    model_config = dict(alias_generator=to_camel, use_enum_values=True)

It happens when MyModel is a subclass of BaseModel, if you remove BaseModel from MyModel, it works for whatever reason. It seems simply importing pydantic breaks the variable viewer.

pydantic version is 2.0a3

roblourens commented 1 year ago

I still can't repro the exact same issue. But I noticed a couple things

So I fixed both of those and I'm hoping that helps