You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Consider MatRepr for __repr__ instead of Pandas #494
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.
* `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().
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 :)
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.
Activity
eriknw commentedon 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)(False, 2)np.dtype("(3,)uint16")[1, 2, 3]alugowski commentedon Aug 26, 2023
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 commentedon Aug 26, 2023
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 ofstr().eriknw commentedon 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 commentedon Aug 28, 2023
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 commentedon Aug 28, 2023
BTW this is all that is required to use MatRepr with python-graphblas:
alugowski commentedon Sep 7, 2023
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.