-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
ENH: [typing] NDarray[plt.Axes]
not possible - Type argument of "NDArray" must be a subtype of "generic"
#24738
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
Comments
In type hinting Matplotlib, I stopped short of specifying the type in In most cases adding that specificity was just too much to do all at once so I left it for follow up. I don't specifically recall trying to specify here, but it is possible I did and ran into this then. |
It's a feature on the wish list, but yeah this will in all likelihood be the most feasible and sensible approach here. I do foresee one limitation though that I sincerely doubt we'd be to handle satisfactory: type promotions between arrays with different object dtypes (e.g. an object array wrapping |
Is there any workaround for this atm? I also run in this problem when trying to do |
Note that The first type parameter of See #16544 for an in-depth discussion on array shape typing. FYI, the |
Summary: visualize_image_attr_multiple can return a List[Axes], adds proper annotations to satisfy mypy Why casting is necessary: numpy/numpy#24738 https://github.com/matplotlib/matplotlib/blob/v3.9.2/lib/matplotlib/pyplot.py#L1583C41-L1584C1 Differential Revision: D64998799
Summary: visualize_image_attr_multiple can return a List[Axes], adds proper annotations to satisfy mypy Why casting is necessary: numpy/numpy#24738 https://github.com/matplotlib/matplotlib/blob/v3.9.2/lib/matplotlib/pyplot.py#L1583C41-L1584C1 Differential Revision: D64998799
Summary: visualize_image_attr_multiple can return a List[Axes], adds proper annotations to satisfy mypy Why casting is necessary: numpy/numpy#24738 https://github.com/matplotlib/matplotlib/blob/v3.9.2/lib/matplotlib/pyplot.py#L1583C41-L1584C1 Differential Revision: D64998799
Summary: visualize_image_attr_multiple can return a List[Axes], adds proper annotations to satisfy mypy Why casting is necessary: numpy/numpy#24738 https://github.com/matplotlib/matplotlib/blob/v3.9.2/lib/matplotlib/pyplot.py#L1583C41-L1584C1 Differential Revision: D64998799
Summary: visualize_image_attr_multiple can return a List[Axes], adds proper annotations to satisfy mypy Why casting is necessary: numpy/numpy#24738 https://github.com/matplotlib/matplotlib/blob/v3.9.2/lib/matplotlib/pyplot.py#L1583C41-L1584C1 Differential Revision: D64998799
Summary: visualize_image_attr_multiple can return a List[Axes], adds proper annotations to satisfy mypy Why casting is necessary: numpy/numpy#24738 https://github.com/matplotlib/matplotlib/blob/v3.9.2/lib/matplotlib/pyplot.py#L1583C41-L1584C1 Differential Revision: D64998799
Summary: visualize_image_attr_multiple can return a List[Axes], adds proper annotations to satisfy mypy Why casting is necessary: numpy/numpy#24738 https://github.com/matplotlib/matplotlib/blob/v3.9.2/lib/matplotlib/pyplot.py#L1583C41-L1584C1 Differential Revision: D64998799
Summary: visualize_image_attr_multiple can return a List[Axes], adds proper annotations to satisfy mypy Why casting is necessary: numpy/numpy#24738 https://github.com/matplotlib/matplotlib/blob/v3.9.2/lib/matplotlib/pyplot.py#L1583C41-L1584C1 Differential Revision: D64998799
Summary: visualize_image_attr_multiple can return a List[Axes], adds proper annotations to satisfy mypy Why casting is necessary: numpy/numpy#24738 https://github.com/matplotlib/matplotlib/blob/v3.9.2/lib/matplotlib/pyplot.py#L1583C41-L1584C1 Differential Revision: D64998799
Summary: visualize_image_attr_multiple can return a List[Axes], adds proper annotations to satisfy mypy Why casting is necessary: numpy/numpy#24738 https://github.com/matplotlib/matplotlib/blob/v3.9.2/lib/matplotlib/pyplot.py#L1583C41-L1584C1 Differential Revision: D64998799
Summary: visualize_image_attr_multiple can return a List[Axes], adds proper annotations to satisfy mypy Why casting is necessary: numpy/numpy#24738 https://github.com/matplotlib/matplotlib/blob/v3.9.2/lib/matplotlib/pyplot.py#L1583C41-L1584C1 Differential Revision: D64998799
Summary: visualize_image_attr_multiple can return a List[Axes], adds proper annotations to satisfy mypy Why casting is necessary: numpy/numpy#24738 https://github.com/matplotlib/matplotlib/blob/v3.9.2/lib/matplotlib/pyplot.py#L1583C41-L1584C1 Differential Revision: D64998799
Summary: visualize_image_attr_multiple can return a List[Axes], adds proper annotations to satisfy mypy Why casting is necessary: numpy/numpy#24738 https://github.com/matplotlib/matplotlib/blob/v3.9.2/lib/matplotlib/pyplot.py#L1583C41-L1584C1 Differential Revision: D64998799
Summary: visualize_image_attr_multiple can return a List[Axes], adds proper annotations to satisfy mypy Why casting is necessary: numpy/numpy#24738 https://github.com/matplotlib/matplotlib/blob/v3.9.2/lib/matplotlib/pyplot.py#L1583C41-L1584C1 Differential Revision: D64998799
Summary: visualize_image_attr_multiple can return a List[Axes], adds proper annotations to satisfy mypy Why casting is necessary: numpy/numpy#24738 https://github.com/matplotlib/matplotlib/blob/v3.9.2/lib/matplotlib/pyplot.py#L1583C41-L1584C1 Differential Revision: D64998799
Summary: visualize_image_attr_multiple can return a List[Axes], adds proper annotations to satisfy mypy Why casting is necessary: numpy/numpy#24738 https://github.com/matplotlib/matplotlib/blob/v3.9.2/lib/matplotlib/pyplot.py#L1583C41-L1584C1 Differential Revision: D64998799
Summary: visualize_image_attr_multiple can return a List[Axes], adds proper annotations to satisfy mypy Why casting is necessary: numpy/numpy#24738 https://github.com/matplotlib/matplotlib/blob/v3.9.2/lib/matplotlib/pyplot.py#L1583C41-L1584C1 Differential Revision: D64998799
Summary: visualize_image_attr_multiple can return a List[Axes], adds proper annotations to satisfy mypy Why casting is necessary: numpy/numpy#24738 https://github.com/matplotlib/matplotlib/blob/v3.9.2/lib/matplotlib/pyplot.py#L1583C41-L1584C1 Differential Revision: D64998799
Summary: Pull Request resolved: #1416 visualize_image_attr_multiple can return a List[Axes], adds proper annotations to satisfy mypy Why casting is necessary: numpy/numpy#24738 https://github.com/matplotlib/matplotlib/blob/v3.9.2/lib/matplotlib/pyplot.py#L1583C41-L1584C1 Reviewed By: cyrjano Differential Revision: D64998799 fbshipit-source-id: 7b2249654f5eb784f6c0686160f78f1be61bf7a2
Proposed new feature or change:
For
numpy.typing.NDArray
, the argument needs to be a subtype ofnumpy.generic
. However, this leads to problem since we can no longer specify concrete types forobject
-arrays, for example,mypy
raises[type-var]
for this code:For
NDArray
of dtypenp.object_
, it should somehow wrap the given type. One approach could be to makenp.object_
generic and change methods overloads so that for object-type, it generally returns the wrapped type.The text was updated successfully, but these errors were encountered: