Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Open
Labels
Description
Bug summary
Pandas uses mypy/pyright to check its internal code. We currently pin matplotlib <3.8 to avoid many type errorspandas-dev/pandas#55210 Many of these errors are definitely on pandas's side :) but a few might be bugs in matplotlib.
Code for reproduction
# Simplified examples from pandas that trigger type errorsdefformat_date_labels(ax:Axes,rot)->None:forlabelinax.get_xticklabels():label.set_ha("right")# error: "Text" has no attribute "set_ha" [attr-defined]deftest(cellText:np.ndarray):# error: Argument "cellText" to "table" has incompatible type "ndarray[Any, Any]"; expected "Sequence[Sequence[str]] | None" [arg-type]# maybe use a Protocol such as Iterable?matplotlib.table.table(ax,cellText=cellText**kwargs)defdecorate_axes(ax:Axes,freq,kwargs)->None:# The following might just be bad pandas code# error: "Axes" has no attribute "freq" [attr-defined]ax.freq=freqxaxis=ax.get_xaxis()xaxis.freq=freqifnothasattr(ax,"legendlabels"):ax.legendlabels= [kwargs.get("label",None)]else:ax.legendlabels.append(kwargs.get("label",None))# error: Argument 1 to "FixedLocator" has incompatible type "ndarray[Any, Any]"; expected "Sequence[float]" [arg-type]FixedLocator(ax.get_xticks())# same also for set_ylabel, maybe use a protocol for str-coercible types instead of requiring strdeftest(ax:Axes,label:Hashable):# Hashable might be too wide, but str seems to strictax.set_xlabel(label)deftest(ax:Axes):axes=np.array([ax])# error: Argument 1 to "set_ticks_props" has incompatible type "ndarray[Any, dtype[Any]]"; expected "Axes | Sequence[Axes]" [arg-type]set_ticks_props(axes,**kwargs)
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