Skip to content

_repr_html_ broken for m @ m.T #416

Description

@jim22k

This works fine: gb.op.plus_times(m @ m.T) and a nice view of the expression shows up in the notebook.

But without inclusion in the semiring, m @ m.T gets into a state where it knows it is a MatrixExpression, but the formatter gives it an invalid keyword argument.

>>> m @ m.T
TypeError                                 Traceback (most recent call last)
File ~/miniconda3/envs/graphblas-local/lib/python3.9/site-packages/IPython/core/formatters.py:343, in BaseFormatter.__call__(self, obj)
    341     method = get_real_method(obj, self.print_method)
    342     if method is not None:
--> 343         return method()
    344     return None
    345 else:

File ~/Projects/graphblas/python-graphblas/graphblas/core/expr.py:525, in InfixExprBase._repr_html_(self)
    523     return formatting.format_vector_infix_expression_html(self)
    524 if self.output_type.__name__ == "MatrixExpression":
--> 525     return formatting.format_matrix_infix_expression_html(self)
    526 return formatting.format_scalar_infix_expression_html(self)

File ~/Projects/graphblas/python-graphblas/graphblas/core/formatting.py:828, in format_matrix_infix_expression_html(expr)
    822 expr_html = expr._format_expr_html()
    823 header = create_header_html(
    824     expr_html,
    825     ["nrows", "ncols", "right_dtype", "left_dtype"],
    826     [expr._nrows, expr._ncols, expr.left.dtype, expr.right.dtype],
    827 )
--> 828 return _format_infix_expression(expr, header, expr_html)

File ~/Projects/graphblas/python-graphblas/graphblas/core/formatting.py:714, in _format_infix_expression(expr, header, expr_name)
    708 computed = ""
    709 if config.get("autocompute") and (
    710     expr.method_name not in {"ewise_add", "ewise_mult"}
    711     or expr.left.dtype == BOOL
    712     and expr.right.dtype == BOOL
    713 ):
--> 714     computed = get_expr_result(expr, html=True)
    715     if "__EXPR__" in computed:
    716         return computed.replace("<tt>__EXPR__</tt>", topline)

File ~/Projects/graphblas/python-graphblas/graphblas/core/formatting.py:516, in get_expr_result(expr, html)
    514 val.name = "Result"
    515 if html:
--> 516     arg_string = f"{val._repr_html_(expr=expr)}"
    517 else:
    518     arg_string = val.__repr__(expr=expr)

TypeError: _repr_html_() got an unexpected keyword argument 'expr'

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething is broken

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions