Support "View Value in Data Viewer" for custom class

85 views Asked by At

In the VSCode Python debugger, I can right-click on numpy array or pandas DataFrame and select "View Value in Data Viewer". Is it possible to support this for a self-implemented class?

I first tried to sublass collections.abc.Sequence, which does not work. I then tried to sublass np.ndarray, but that didn't work either. Is there some magic dust I can implement?

from collections.abc import Sequence
import numpy as np

class X(Sequence):
    _x: np.ndarray

    def __init__(self, x: np.ndarray):
        self._x = x

    def __getitem__(self, index):
        return self._x[index]

    def __len__(self):
        return len(self._x)

    def __contains__(self, value):
        return value in self._x

    def __iter__(self):
        return iter(self._x)

class Y(np.ndarray):
    pass

an_array = np.array([1, 2, 3])   # menu available
an_instance_of_X = X(an_array)   # not
an_instance_of_Y = Y(an_array)   # not

print("Break here")
1

There are 1 answers

0
MingJie-MSFT On

You can use Jupyter-Notebook.

It support you to check variables by clicking this button:

enter image description here

In your case, it'll show:

enter image description here