0

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
  • How about using composition over inheritance, so the custom class has an attribute that you can view in the Data Viewer? Commented Nov 27, 2023 at 17:20

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.