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

TypeError 'numpy._DTypeMeta' object is not subscriptable #2025

Open
lukegwoolley opened this issue Nov 4, 2024 · 5 comments
Open

TypeError 'numpy._DTypeMeta' object is not subscriptable #2025

lukegwoolley opened this issue Nov 4, 2024 · 5 comments
Assignees

Comments

@lukegwoolley
Copy link

Happens on both latest numpy version and numpy 1.21.5
highspy numpy error

Error sits in this line:
File /local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.10/site-packages/highspy/highs.py:21
19 # backwards typing support information for HighspyArray
20 if sys.version_info >= (3, 9):
---> 21 ndarray_object_type = np.ndarray[Any, np.dtype[np.object_]]

@jajhall
Copy link
Member

jajhall commented Nov 4, 2024

Any thoughts on how to fix this @mathgeekcoder ?

@mathgeekcoder
Copy link
Contributor

mathgeekcoder commented Nov 4, 2024

Oh interesting. Python typing support seems a little troublesome. Since I can't reproduce, @lukegwoolley, can you please try to modify your highs.py, and see if this works for you?

# backwards typing support information for HighspyArray
if sys.version_info >= (3, 9):
    from typing import TypeAlias
    obj_type: TypeAlias = 'np.dtype[np.object_]'
    ndarray_object_type = np.ndarray[Any, obj_type]
else:
    ndarray_object_type = np.ndarray

If that works, I can make a new PR with some relevant fixes.

BTW: You can import the TypeAlias with the imports at the top of highs.py instead, I included it in the code snippet for easier copy/paste.

@lukegwoolley
Copy link
Author

lukegwoolley commented Nov 5, 2024

Hi @mathgeekcoder

I had a play around with the code and I think the issue is the sys.version issue is wrong.

The below code works for me in python 3.10 and 3.12 but I wasnt able to test for 3.11.

# backwards typing support information for HighspyArray
if sys.version_info >= (3, 11):
    ndarray_object_type = np.ndarray[Any, np.dtype[np.object_]]
else:
    ndarray_object_type = np.ndarray

@mathgeekcoder
Copy link
Contributor

Thanks @lukegwoolley. Did you happen to test the code I sent? Can you confirm if it didn't work?

Updating that version check just disables the numpy typing for your python 3.10. According to the docs, this typing should be supported in 3.10.

Also, do you know if there's anything special about your environment? I'm wondering since this error wasn't picked up in our CI build - which also tests the python wheel on many different versions.

@lukegwoolley
Copy link
Author

image

It errors out here - it might be due to the numpy version then as unfortunately databricks is where I am running it and it uses a very old numpy and pandas version.

numpy is 1.21.5

The previous version of highspy 1.7.3 works completely fine btw

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

No branches or pull requests

4 participants