xeus-python icon indicating copy to clipboard operation
xeus-python copied to clipboard

XPython Raw repr html fails for `pandas.DataFrame`

Open krassowski opened this issue 4 years ago • 3 comments

Just heads up from testing a PR on JupyterLab with "XPython Raw", which fails on representation of pandas.DataFrame class (instances work, classes fail with):

TypeError: _repr_html_() missing 1 required positional argument: 'self'

Observed:

Screenshot from 2021-10-23 17-10-34

Expected (in both IPython and normal XPython):

Screenshot from 2021-10-23 17-11-09

Sorry about the noise if you already fixed that in the master!

krassowski avatar Oct 23 '21 16:10 krassowski

Thank you for reporting. I don't think we noticed this one before.

SylvainCorlay avatar Oct 23 '21 16:10 SylvainCorlay

The fix should be for xeus-python-raw to do the same thing as IPython's get_real_method to get the repr method instead of simply checking with has_attr.

SylvainCorlay avatar Dec 25 '21 11:12 SylvainCorlay

Make a pybind11 version of

def get_real_method(obj, name):
    """Like getattr, but with a few extra sanity checks:

    - If obj is a class, ignore everything except class methods
    - Check if obj is a proxy that claims to have all attributes
    - Catch attribute access failing with any exception
    - Check that the attribute is a callable object

    Returns the method or None.
    """
    try:
        canary = getattr(obj, '_ipython_canary_method_should_not_exist_', None)
    except Exception:
        return None

    if canary is not None:
        # It claimed to have an attribute it should never have
        return None

    try:
        m = getattr(obj, name, None)
    except Exception:
        return None

    if inspect.isclass(obj) and not isinstance(m, types.MethodType):
        return None

    if callable(m):
        return m

    return None

SylvainCorlay avatar Dec 25 '21 11:12 SylvainCorlay