-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[Bug/TYP]: misc type errors #26858
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
These should be |
Thank you - that might be my copy&past mistakes. The main point is that it doesn't work with an np.ndarray that contains the appropriate type. (Sorry, not familiar with matplotlib and how pandas uses matplotlib) edit: updated the examples |
This is documented as I'd suspect the same thing holds for The natural thing is to provide |
class SupportsStr(Protocol):
def __str__(self) -> str: ... (the stdlib typing module provides similar protocols for Which effectively reduces to I will note that in the case of
|
There does not seem to be another good ABC to use between I know numpy is trying to reduce the number of methods rather than increase it, but perhaps there is a compelling case to be made for these... though not fully sure |
@twoertwein Can you help me to run the type checks against pandas locally? I had tried quite a bit earlier in the process running against Even now, if I do I also tried Edit: after writing this, I noticed the Double edit: I think I got there, turns out |
The pandas mypy/pyright checks do not use pandas-stubs. It is best to follow the instructions here to set the development environment up. After that you can simply call mypy. Thank you for spending much time on this summary. Sorry, I didn't intend to consume your time by debugging the issues over at pandas - I'm happy to cc you for targeted questions though :) edit: also feel free to ping me if you like me to test the impact of important/big matplotlib type changes on internal pandas code. |
Thank you very much for the quick and active response! I will work on pandas PRs to get the internal pandas code (more) compliant with the matplotlib annotations (might take a bit). Sorry, I'm not sure how actionable this issue is on the matplotlib side (obviously many todos on the pandas side). Feel free to close it. |
About ndarray and Sequence: Sequence is a concrete class, not a protocol. Unless ndarray inherits from it, it will never match it. |
I mean, Sequence is very much an Abstract class, but you are correct that it does require inheritance to be considered (well, runtime you can |
I recall some discussions about changing this way back in the past, though nothing has come for it. If you do really want to express from typing import Protocol, TypeVar
_T_co = TypeVar("_T_co", covariant=True)
class _PySequence(Protocol[_T_co]):
def __len__(self) -> int: ...
def __getitem__(self, __key: int) -> _T_co: ... |
There is also a Sequence-like protocol that disallows strings hauntsaninja/useful_types#14 It could probably be adjusted to also fit ndarray. (Pandas has the same issue: Index and Series are incompatible with Sequence.) |
Bug summary
Pandas uses mypy/pyright to check its internal code. We currently pin matplotlib <3.8 to avoid many type errors pandas-dev/pandas#55210 Many of these errors are definitely on pandas's side :) but a few might be bugs in matplotlib.
Code for reproduction
Actual outcome
the above type errors
Expected outcome
Fewer errors, but still some errors - some of the pandas code is definitely to be blamed!
Additional information
No response
Operating system
No response
Matplotlib Version
3.8
Matplotlib Backend
No response
Python version
No response
Jupyter version
No response
Installation
None
The text was updated successfully, but these errors were encountered: