Skip to content

Allow easier array UDTs, such as "INT64[3, 3]" #300

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

Merged
merged 1 commit into from
Oct 26, 2022

Conversation

eriknw
Copy link
Member

@eriknw eriknw commented Oct 22, 2022

This matches the "nicer" repr we have for array UDTs that we already have, so it should be natural to use.

I'm always a little skeptical when extending what numpy does, but I think this is so much easier and more readable.

Quick: can you create a valid numpy array dtype from memory?

@eriknw eriknw requested a review from jim22k October 22, 2022 03:50
@eriknw eriknw added the enhancement Improve existing functionality or make things work better label Oct 22, 2022
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.008%) to 98.668% when pulling 19a087d on eriknw:easier_array_udt into d0c41f2 on python-graphblas:main.

@eriknw
Copy link
Member Author

eriknw commented Oct 22, 2022

It should be noted that record dtypes in numpy can be indexed. For example:

>>> udt = gb.dtypes.lookup_dtype({"x": int, "y": float})
>>> udt
{'x': INT64, 'y': FP64}
>>> udt.np_type
dtype([('x', '<i8'), ('y', '<f8')])
>>> udt.np_type["x"]
dtype('int64')
>>> udt.np_type[0]
dtype('float64')

Array dtypes cannot be indexed:

>>> udt = gb.dtypes.lookup_dtype("INT64[3]")
>>> udt
INT64[3]
>>> udt.np_type
dtype(('<i8', (3,)))
>>> udt.np_type[0]
KeyError: "There are no fields in dtype ('<i8', (3,))."

Might we want to index our dtypes someday, and, if so, does this change our mind about approving this PR?

@eriknw eriknw merged commit 20f3dfb into python-graphblas:main Oct 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improve existing functionality or make things work better
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants