GeezerVison is showing github.com — Consider MatRepr for `__repr__` instead of Pandas · Issue #494 · python-graphblas/python-graphblas
Consider MatRepr for __repr__ instead of Pandas #494DescriptionReacted by Sultan Orazbayev and Erik Welch Activityeriknw commented on Aug 25, 2023 I like it! I/we will definitely take a closer look. Thanks @alugowski
It definitely looks more like a matrix, and I was thinking just the other day that pandas is a rather heavy dependency that we only use for our repr.
How well does (or will or can) it handle more advanced numpy dtypes? For example:
np.dtype([("x", np.bool_), ("y", np.int64)], align=True)
- We currently render an element of this dtype as e.g.
(False, 2)
np.dtype("(3,)uint16")
- We currently render an element of this dtype as e.g.
[1, 2, 3]
alugowski commented on Aug 26, 2023 ContributorAuthor More actions
How well does (or will or can) it handle more advanced numpy dtypes? For example:
* `np.dtype([("x", np.bool_), ("y", np.int64)], align=True)`
* We currently render an element of this dtype as e.g. `(False, 2)`
* `np.dtype("(3,)uint16")`
* We currently render an element of this dtype as e.g. `[1, 2, 3]`
I had to do a small patch, but both those now render the same in all three output types (html, latex, string). It just calls str(), which I assume is what you do too. alugowski commented on Aug 26, 2023 ContributorAuthor More actions
* `np.dtype("(3,)uint16")`
* We currently render an element of this dtype as e.g. `[1, 2, 3]`
One question about this one.
Do you prefer it to be rendered like that string, or as a nested submatrix?
For reference, here is how I currently render some interesting values:

Row 3 is nested matrices of types matrepr supports (lists, lists of lists, scipy matrices. a graphblas matrix would look like that too).
I ask because I'm considering adding dense numpy arrays as a supported package. Since AFAIK objects of type np.dtype("(3,)uint16") appear just like any other numpy array, one option is to render it like a submatrix instead of str(). eriknw commented on Aug 26, 2023 Ooh, nested sub-matrix is pretty cool!
Right now we just do what is easiest (hence using pandas in the first place). For submatrix dtypes, the easiest is to turn them into lists, vals.tolist(), and let pandas render each entry as a Python list.
I'm happy to revisit how we render elements and to try what you think is nicest :) alugowski commented on Aug 28, 2023 ContributorAuthor More actions Sounds good!
I added ndarray support so numpy submatricies get rendered all pretty now, too:
Let me know how it looks on your datasets. Happy to make tweaks! alugowski commented on Aug 28, 2023 ContributorAuthor More actions BTW this is all that is required to use MatRepr with python-graphblas:
def _str_(mat):
from matrepr import to_str
from matrepr.adapters.graphblas_driver import GraphBLASDriver
# Enable terminal width detection
return to_str(GraphBLASDriver.adapt(mat), width_str=0, max_cols=9999)
graphblas.Matrix.__repr__ = _str_
graphblas.Vector.__repr__ = _str_Reacted by Sultan Orazbayev alugowski commented on Sep 7, 2023 ContributorAuthor More actions One newer feature is to support custom row/column labels. This is handy for something like an adjacency matrix where the matrix elements are edge weights and row/column labels are the vertex weights.
 Reacted by Sultan Orazbayev
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|