Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XPython Raw repr html fails for pandas.DataFrame #511

Open
krassowski opened this issue Oct 23, 2021 · 3 comments
Open

XPython Raw repr html fails for pandas.DataFrame #511

krassowski opened this issue Oct 23, 2021 · 3 comments

Comments

@krassowski
Copy link
Contributor

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!

@SylvainCorlay
Copy link
Member

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

@SylvainCorlay
Copy link
Member

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
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants