Repository navigation
Mypy errors with matplotlib 3.8 #7802
Copy link
Copy link
Closed
Labels
Description
Matplotlib has started to support typing in main (matplotlib/matplotlib#20504) and mypy is throwing a few errors:
Details
xarray/core/options.py:12: error: Cannot assign to a type [misc]
xarray/core/options.py:12: error: Incompatible types in assignment (expression has type "Type[str]", variable has type "Type[Colormap]") [assignment]
xarray/plot/utils.py:808: error: Argument 1 to "set_xticks" of "_AxesBase" has incompatible type "Union[_SupportsArray[dtype[Any]], _NestedSequence[_SupportsArray[dtype[Any]]], int, float, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]]"; expected "Iterable[float]" [arg-type]
xarray/plot/utils.py:810: error: Argument 1 to "set_yticks" of "_AxesBase" has incompatible type "Union[_SupportsArray[dtype[Any]], _NestedSequence[_SupportsArray[dtype[Any]]], int, float, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]]"; expected "Iterable[float]" [arg-type]
xarray/plot/utils.py:813: error: Argument 1 to "set_xlim" of "_AxesBase" has incompatible type "Union[_SupportsArray[dtype[Any]], _NestedSequence[_SupportsArray[dtype[Any]]], int, float, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]]"; expected "Union[float, Tuple[float, float], None]" [arg-type]
xarray/plot/utils.py:815: error: Argument 1 to "set_ylim" of "_AxesBase" has incompatible type "Union[_SupportsArray[dtype[Any]], _NestedSequence[_SupportsArray[dtype[Any]]], int, float, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]]"; expected "Union[float, Tuple[float, float], None]" [arg-type]
Generated Cobertura report: /home/runner/work/xarray/xarray/mypy_report/cobertura.xml
Installing missing stub packages:
/home/runner/micromamba-root/envs/xarray-tests/bin/python -m pip install types-Pillow types-PyYAML types-Pygments types-babel types-colorama types-paramiko types-psutil types-pytz types-pywin32 types-setuptools types-urllib3
Generated Cobertura report: /home/runner/work/xarray/xarray/mypy_report/cobertura.xml
Found 154 errors in 10 files (checked 138 source files)
xarray/plot/utils.py:1349: error: Unsupported operand types for * ("_SupportsArray[dtype[Any]]" and "float") [operator]
xarray/plot/utils.py:1349: error: Unsupported operand types for * ("_NestedSequence[_SupportsArray[dtype[Any]]]" and "float") [operator]
xarray/plot/utils.py:1349: error: Unsupported operand types for * ("_NestedSequence[Union[bool, int, float, complex, str, bytes]]" and "float") [operator]
xarray/plot/utils.py:1349: note: Left operand is of type "Union[_SupportsArray[dtype[Any]], _NestedSequence[_SupportsArray[dtype[Any]]], int, float, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]]"
xarray/plot/utils.py:1349: error: Unsupported operand types for * ("str" and "float") [operator]
xarray/plot/utils.py:1349: error: Unsupported operand types for * ("bytes" and "float") [operator]
xarray/plot/utils.py:1350: error: Item "_SupportsArray[dtype[Any]]" of "Union[_SupportsArray[dtype[Any]], _NestedSequence[_SupportsArray[dtype[Any]]], int, float, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]]" has no attribute "mask" [union-attr]
xarray/plot/utils.py:1350: error: Item "_NestedSequence[_SupportsArray[dtype[Any]]]" of "Union[_SupportsArray[dtype[Any]], _NestedSequence[_SupportsArray[dtype[Any]]], int, float, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]]" has no attribute "mask" [union-attr]
xarray/plot/utils.py:1350: error: Item "int" of "Union[_SupportsArray[dtype[Any]], _NestedSequence[_SupportsArray[dtype[Any]]], int, float, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]]" has no attribute "mask" [union-attr]
xarray/plot/utils.py:1350: error: Item "float" of "Union[_SupportsArray[dtype[Any]], _NestedSequence[_SupportsArray[dtype[Any]]], int, float, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]]" has no attribute "mask" [union-attr]
xarray/plot/utils.py:1350: error: Item "complex" of "Union[_SupportsArray[dtype[Any]], _NestedSequence[_SupportsArray[dtype[Any]]], int, float, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]]" has no attribute "mask" [union-attr]
xarray/plot/utils.py:1350: error: Item "str" of "Union[_SupportsArray[dtype[Any]], _NestedSequence[_SupportsArray[dtype[Any]]], int, float, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]]" has no attribute "mask" [union-attr]
xarray/plot/utils.py:1350: error: Item "bytes" of "Union[_SupportsArray[dtype[Any]], _NestedSequence[_SupportsArray[dtype[Any]]], int, float, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]]" has no attribute "mask" [union-attr]
xarray/plot/utils.py:1350: error: Item "_NestedSequence[Union[bool, int, float, complex, str, bytes]]" of "Union[_SupportsArray[dtype[Any]], _NestedSequence[_SupportsArray[dtype[Any]]], int, float, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]]" has no attribute "mask" [union-attr]
xarray/plot/utils.py:1351: error: Item "_SupportsArray[dtype[Any]]" of "Union[_SupportsArray[dtype[Any]], _NestedSequence[_SupportsArray[dtype[Any]]], int, float, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]]" has no attribute "mask" [union-attr]
xarray/plot/utils.py:1351: error: Item "_NestedSequence[_SupportsArray[dtype[Any]]]" of "Union[_SupportsArray[dtype[Any]], _NestedSequence[_SupportsArray[dtype[Any]]], int, float, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]]" has no attribute "mask" [union-attr]
xarray/plot/utils.py:1351: error: Item "int" of "Union[_SupportsArray[dtype[Any]], _NestedSequence[_SupportsArray[dtype[Any]]], int, float, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]]" has no attribute "mask" [union-attr]
xarray/plot/utils.py:1351: error: Item "float" of "Union[_SupportsArray[dtype[Any]], _NestedSequence[_SupportsArray[dtype[Any]]], int, float, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]]" has no attribute "mask" [union-attr]
xarray/plot/utils.py:1351: error: Item "complex" of "Union[_SupportsArray[dtype[Any]], _NestedSequence[_SupportsArray[dtype[Any]]], int, float, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]]" has no attribute "mask" [union-attr]
xarray/plot/utils.py:1351: error: Item "str" of "Union[_SupportsArray[dtype[Any]], _NestedSequence[_SupportsArray[dtype[Any]]], int, float, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]]" has no attribute "mask" [union-attr]
xarray/plot/utils.py:1351: error: Item "bytes" of "Union[_SupportsArray[dtype[Any]], _NestedSequence[_SupportsArray[dtype[Any]]], int, float, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]]" has no attribute "mask" [union-attr]
xarray/plot/utils.py:1351: error: Item "_NestedSequence[Union[bool, int, float, complex, str, bytes]]" of "Union[_SupportsArray[dtype[Any]], _NestedSequence[_SupportsArray[dtype[Any]]], int, float, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]]" has no attribute "mask" [union-attr]
xarray/plot/facetgrid.py:684: error: "FigureCanvasBase" has no attribute "get_renderer" [attr-defined]
xarray/plot/accessor.py:182: error: Overloaded function signatures 1 and 2 overlap with incompatible return types [misc]
xarray/plot/accessor.py:182: error: Overloaded function signatures 1 and 3 overlap with incompatible return types [misc]
xarray/plot/accessor.py:309: error: Overloaded function signatures 1 and 2 overlap with incompatible return types [misc]
xarray/plot/accessor.py:309: error: Overloaded function signatures 1 and 3 overlap with incompatible return types [misc]
xarray/plot/accessor.py:428: error: Overloaded function implementation cannot produce return type of signature 2 [misc]
xarray/plot/accessor.py:428: error: Overloaded function implementation cannot produce return type of signature 3 [misc]
xarray/plot/accessor.py:433: error: Overloaded function signatures 1 and 2 overlap with incompatible return types [misc]
xarray/plot/accessor.py:433: error: Overloaded function signatures 1 and 3 overlap with incompatible return types [misc]
xarray/plot/accessor.py:552: error: Overloaded function implementation cannot produce return type of signature 2 [misc]
xarray/plot/accessor.py:552: error: Overloaded function implementation cannot produce return type of signature 3 [misc]
xarray/plot/accessor.py:557: error: Overloaded function signatures 1 and 2 overlap with incompatible return types [misc]
xarray/plot/accessor.py:557: error: Overloaded function signatures 1 and 3 overlap with incompatible return types [misc]
xarray/plot/accessor.py:676: error: Overloaded function implementation cannot produce return type of signature 2 [misc]
xarray/plot/accessor.py:676: error: Overloaded function implementation cannot produce return type of signature 3 [misc]
xarray/plot/accessor.py:681: error: Overloaded function signatures 1 and 2 overlap with incompatible return types [misc]
xarray/plot/accessor.py:681: error: Overloaded function signatures 1 and 3 overlap with incompatible return types [misc]
xarray/plot/accessor.py:800: error: Overloaded function implementation cannot produce return type of signature 2 [misc]
xarray/plot/accessor.py:800: error: Overloaded function implementation cannot produce return type of signature 3 [misc]
xarray/plot/accessor.py:948: error: Overloaded function signatures 1 and 2 overlap with incompatible return types [misc]
xarray/plot/accessor.py:948: error: Overloaded function signatures 1 and 3 overlap with incompatible return types [misc]
xarray/plot/accessor.py:1075: error: Overloaded function signatures 1 and 2 overlap with incompatible return types [misc]
xarray/plot/accessor.py:1075: error: Overloaded function signatures 1 and 3 overlap with incompatible return types [misc]
xarray/plot/accessor.py:1190: error: Overloaded function signatures 1 and 2 overlap with incompatible return types [misc]
xarray/plot/accessor.py:1190: error: Overloaded function signatures 1 and 3 overlap with incompatible return types [misc]
xarray/plot/dataset_plot.py:324: error: Overloaded function signatures 1 and 2 overlap with incompatible return types [misc]
xarray/plot/dataset_plot.py:324: error: Overloaded function signatures 1 and 3 overlap with incompatible return types [misc]
xarray/plot/dataset_plot.py:478: error: Overloaded function signatures 1 and 2 overlap with incompatible return types [misc]
xarray/plot/dataset_plot.py:478: error: Overloaded function signatures 1 and 3 overlap with incompatible return types [misc]
xarray/plot/dataset_plot.py:649: error: Function gets multiple values for keyword argument "x" [misc]
xarray/plot/dataset_plot.py:649: error: Function gets multiple values for keyword argument "y" [misc]
xarray/plot/dataset_plot.py:649: error: Function gets multiple values for keyword argument "u" [misc]
xarray/plot/dataset_plot.py:649: error: Function gets multiple values for keyword argument "v" [misc]
xarray/plot/dataset_plot.py:649: error: Function gets multiple values for keyword argument "density" [misc]
xarray/plot/dataset_plot.py:649: error: Function gets multiple values for keyword argument "linewidth" [misc]
xarray/plot/dataset_plot.py:649: error: Function gets multiple values for keyword argument "color" [misc]
xarray/plot/dataset_plot.py:649: error: Function gets multiple values for keyword argument "cmap" [misc]
xarray/plot/dataset_plot.py:649: error: Function gets multiple values for keyword argument "norm" [misc]
xarray/plot/dataset_plot.py:649: error: Function gets multiple values for keyword argument "arrowsize" [misc]
xarray/plot/dataset_plot.py:649: error: Function gets multiple values for keyword argument "arrowstyle" [misc]
xarray/plot/dataset_plot.py:649: error: Function gets multiple values for keyword argument "minlength" [misc]
xarray/plot/dataset_plot.py:649: error: Function gets multiple values for keyword argument "transform" [misc]
xarray/plot/dataset_plot.py:649: error: Function gets multiple values for keyword argument "zorder" [misc]
xarray/plot/dataset_plot.py:649: error: Function gets multiple values for keyword argument "start_points" [misc]
xarray/plot/dataset_plot.py:649: error: Function gets multiple values for keyword argument "maxlength" [misc]
xarray/plot/dataset_plot.py:649: error: Function gets multiple values for keyword argument "integration_direction" [misc]
xarray/plot/dataset_plot.py:649: error: Function gets multiple values for keyword argument "broken_streamlines" [misc]
xarray/plot/dataset_plot.py:649: error: Argument 1 has incompatible type "*List[ndarray[Any, Any]]"; expected "Union[float, Tuple[float, float]]" [arg-type]
xarray/plot/dataset_plot.py:649: error: Argument 1 has incompatible type "*List[ndarray[Any, Any]]"; expected "Union[str, Colormap, None]" [arg-type]
xarray/plot/dataset_plot.py:649: error: Argument 1 has incompatible type "*List[ndarray[Any, Any]]"; expected "Union[str, Normalize, None]" [arg-type]
xarray/plot/dataset_plot.py:649: error: Argument 1 has incompatible type "*List[ndarray[Any, Any]]"; expected "float" [arg-type]
xarray/plot/dataset_plot.py:649: error: Argument 1 has incompatible type "*List[ndarray[Any, Any]]"; expected "Union[str, ArrowStyle]" [arg-type]
xarray/plot/dataset_plot.py:649: error: Argument 1 has incompatible type "*List[ndarray[Any, Any]]"; expected "Optional[Transform]" [arg-type]
xarray/plot/dataset_plot.py:649: error: Argument 1 has incompatible type "*List[ndarray[Any, Any]]"; expected "Optional[float]" [arg-type]
xarray/plot/dataset_plot.py:649: error: Argument 1 has incompatible type "*List[ndarray[Any, Any]]"; expected "Literal['forward', 'backward', 'both']" [arg-type]
xarray/plot/dataset_plot.py:649: error: Argument 1 has incompatible type "*List[ndarray[Any, Any]]"; expected "bool" [arg-type]
xarray/plot/dataset_plot.py:751: error: Overloaded function signatures 1 and 2 overlap with incompatible return types [misc]
xarray/plot/dataset_plot.py:751: error: Overloaded function signatures 1 and 3 overlap with incompatible return types [misc]
xarray/plot/dataarray_plot.py:718: error: Incompatible return value type (got "Tuple[Union[ndarray[Any, Any], List[ndarray[Any, Any]]], ndarray[Any, Any], Union[BarContainer, Polygon, List[Union[BarContainer, Polygon]]]]", expected "Tuple[ndarray[Any, Any], ndarray[Any, Any], BarContainer]") [return-value]
xarray/plot/dataarray_plot.py:996: error: "Axes" has no attribute "view_init" [attr-defined]
xarray/plot/dataarray_plot.py:1106: error: Overloaded function signatures 1 and 2 overlap with incompatible return types [misc]
xarray/plot/dataarray_plot.py:1106: error: Overloaded function signatures 1 and 3 overlap with incompatible return types [misc]
xarray/plot/dataarray_plot.py:1261: error: Argument 1 to "scatter" of "Axes" has incompatible type "*List[ndarray[Any, Any]]"; expected "Union[Sequence[Union[Union[Tuple[float, float, float], str], Union[str, Tuple[float, float, float, float], Tuple[Union[Tuple[float, float, float], str], float], Tuple[Tuple[float, float, float, float], float]]]], Union[Union[Tuple[float, float, float], str], Union[str, Tuple[float, float, float, float], Tuple[Union[Tuple[float, float, float], str], float], Tuple[Tuple[float, float, float, float], float]]], None]" [arg-type]
xarray/plot/dataarray_plot.py:1261: error: Argument 1 to "scatter" of "Axes" has incompatible type "*List[ndarray[Any, Any]]"; expected "Optional[Union[str, Path, MarkerStyle]]" [arg-type]
xarray/plot/dataarray_plot.py:1261: error: Argument 1 to "scatter" of "Axes" has incompatible type "*List[ndarray[Any, Any]]"; expected "Union[str, Colormap, None]" [arg-type]
xarray/plot/dataarray_plot.py:1261: error: Argument 1 to "scatter" of "Axes" has incompatible type "*List[ndarray[Any, Any]]"; expected "Union[str, Normalize, None]" [arg-type]
xarray/plot/dataarray_plot.py:1261: error: Argument 1 to "scatter" of "Axes" has incompatible type "*List[ndarray[Any, Any]]"; expected "Optional[float]" [arg-type]
xarray/plot/dataarray_plot.py:1261: error: Argument 1 to "scatter" of "Axes" has incompatible type "*List[ndarray[Any, Any]]"; expected "Union[float, Sequence[float], None]" [arg-type]
xarray/plot/dataarray_plot.py:1615: error: "Axes" has no attribute "set_zlabel" [attr-defined]
xarray/plot/dataarray_plot.py:1655: error: Overloaded function signatures 1 and 2 overlap with incompatible return types [misc]
xarray/plot/dataarray_plot.py:1655: error: Overloaded function signatures 1 and 3 overlap with incompatible return types [misc]
xarray/plot/dataarray_plot.py:1874: error: Overloaded function signatures 1 and 2 overlap with incompatible return types [misc]
xarray/plot/dataarray_plot.py:1874: error: Overloaded function signatures 1 and 3 overlap with incompatible return types [misc]
xarray/plot/dataarray_plot.py:2010: error: Overloaded function signatures 1 and 2 overlap with incompatible return types [misc]
xarray/plot/dataarray_plot.py:2010: error: Overloaded function signatures 1 and 3 overlap with incompatible return types [misc]
xarray/plot/dataarray_plot.py:2146: error: Overloaded function signatures 1 and 2 overlap with incompatible return types [misc]
xarray/plot/dataarray_plot.py:2146: error: Overloaded function signatures 1 and 3 overlap with incompatible return types [misc]
xarray/plot/dataarray_plot.py:2464: error: "Axes" has no attribute "plot_surface" [attr-defined]
xarray/tests/test_plot.py:427: error: Value of type "Union[_SupportsArray[dtype[Any]], _NestedSequence[_SupportsArray[dtype[Any]]], int, float, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]]" is not indexable [index]
xarray/tests/test_plot.py:443: error: Module has no attribute "viridis" [attr-defined]
xarray/tests/test_plot.py:457: error: "None" not callable [misc]
xarray/tests/test_plot.py:462: error: "None" not callable [misc]
xarray/tests/test_plot.py:465: error: "None" not callable [misc]
xarray/tests/test_plot.py:471: error: Module has no attribute "viridis" [attr-defined]
xarray/tests/test_plot.py:477: error: Module has no attribute "viridis" [attr-defined]
xarray/tests/test_plot.py:482: error: Module has no attribute "viridis" [attr-defined]
xarray/tests/test_plot.py:486: error: Module has no attribute "viridis" [attr-defined]
xarray/tests/test_plot.py:493: error: "None" not callable [misc]
xarray/tests/test_plot.py:498: error: "None" not callable [misc]
xarray/tests/test_plot.py:501: error: "None" not callable [misc]
xarray/tests/test_plot.py:931: error: Module has no attribute "magma" [attr-defined]
xarray/tests/test_plot.py:933: error: Module has no attribute "magma" [attr-defined]
xarray/tests/test_plot.py:1173: error: Module has no attribute "RdBu" [attr-defined]
xarray/tests/test_plot.py:1746: error: Item "Colormap" of "Optional[Colormap]" has no attribute "colors" [union-attr]
xarray/tests/test_plot.py:1746: error: Item "None" of "Optional[Colormap]" has no attribute "colors" [union-attr]
xarray/tests/test_plot.py:1747: error: Item "Colormap" of "Optional[Colormap]" has no attribute "colors" [union-attr]
xarray/tests/test_plot.py:1747: error: Item "None" of "Optional[Colormap]" has no attribute "colors" [union-attr]
xarray/tests/test_plot.py:1749: error: Item "Colormap" of "Optional[Colormap]" has no attribute "_rgba_over" [union-attr]
xarray/tests/test_plot.py:1749: error: Item "None" of "Optional[Colormap]" has no attribute "_rgba_over" [union-attr]
xarray/tests/test_plot.py:1801: error: Item "None" of "Optional[ndarray[Any, Any]]" has no attribute "size" [union-attr]
xarray/tests/test_plot.py:1952: error: Item "None" of "Optional[ndarray[Any, Any]]" has no attribute "min" [union-attr]
xarray/tests/test_plot.py:1952: error: Item "None" of "Optional[ndarray[Any, Any]]" has no attribute "max" [union-attr]
xarray/tests/test_plot.py:1968: error: Item "None" of "Optional[ndarray[Any, Any]]" has no attribute "dtype" [union-attr]
xarray/tests/test_plot.py:1969: error: Value of type "Optional[ndarray[Any, Any]]" is not indexable [index]
xarray/tests/test_plot.py:2125: error: "Artist" has no attribute "get_clim" [attr-defined]
xarray/tests/test_plot.py:2135: error: "Colorbar" has no attribute "vmin" [attr-defined]
xarray/tests/test_plot.py:2136: error: "Colorbar" has no attribute "vmax" [attr-defined]
xarray/tests/test_plot.py:2202: error: "Artist" has no attribute "get_clim" [attr-defined]
xarray/tests/test_plot.py:2218: error: "Artist" has no attribute "norm" [attr-defined]
xarray/tests/test_plot.py:2747: error: Item "_AxesBase" of "Optional[_AxesBase]" has no attribute "legend_" [union-attr]
xarray/tests/test_plot.py:2747: error: Item "None" of "Optional[_AxesBase]" has no attribute "legend_" [union-attr]
xarray/tests/test_plot.py:2754: error: Item "None" of "Optional[_AxesBase]" has no attribute "get_legend" [union-attr]
xarray/tests/test_plot.py:2775: error: Item "None" of "Optional[FigureBase]" has no attribute "axes" [union-attr]
xarray/tests/test_plot.py:2775: error: Argument 1 to "len" has incompatible type "Union[_AxesBase, None, Any]"; expected "Sized" [arg-type]
xarray/tests/test_plot.py:2803: error: Module has no attribute "dates" [attr-defined]
xarray/tests/test_plot.py:2812: error: Module has no attribute "dates" [attr-defined]
xarray/tests/test_plot.py:2831: error: Item "None" of "Optional[_AxesBase]" has no attribute "xaxis" [union-attr]
xarray/tests/test_plot.py:2831: error: Module has no attribute "dates" [attr-defined]
xarray/tests/test_groupby.py:715: error: Argument 1 to "groupby" of "Dataset" has incompatible type "ndarray[Any, dtype[signedinteger[Any]]]"; expected "Union[Hashable, DataArray, IndexVariable]" [arg-type]
xarray/tests/test_groupby.py:715: note: Following member(s) of "ndarray[Any, dtype[signedinteger[Any]]]" have conflicts:
xarray/tests/test_groupby.py:715: note: __hash__: expected "Callable[[], int]", got "None"
xarray/tests/test_dataset.py:6964: error: "PlainQuantity[Any]" not callable [operator]
xarray/tests/test_dataset.py:6965: error: "PlainQuantity[Any]" not callable [operator]
xarray/tests/test_dataset.py:7007: error: "PlainQuantity[Any]" not callable [operator]
xarray/tests/test_dataset.py:7008: error: "PlainQuantity[Any]" not callable [operator]
xarray/tests/test_dataarray.py:6687: error: "PlainQuantity[Any]" not callable [operator]
xarray/tests/test_dataarray.py:6689: error: "PlainQuantity[Any]" not callable [operator]
xarray/tests/test_dataarray.py:6735: error: "PlainQuantity[Any]" not callable [operator]
xarray/tests/test_dataarray.py:6737: error: "PlainQuantity[Any]" not callable [operator]
Some guidance how to solve these:
[xy]ticksin mpl is currently overly narrowly type hinted because I was following the docstring, but I agree thatArrayLikeis a better type hint for that, plan on updating (including the docstring) upstream[xy]limoriginally neglected the case of passingset_xlim((min, max))as a tuple, but that has been updated. xarray has that type hinted as array like, but mpl has it hinted as a 2-tuple (I think it is currently still of floats, but may be expanded as we more directly address units/categoricals/etc). Willing to debate here, but my starting position is that the "exactly 2 values" is valuable info here, and I thinktupleis the only way to do that.get_rendereris not actually available on all of our backends, we should maybe see if there is a more preferred way of doing what you are doing here that will work for all backends, but haven't looked into it too closely.Module has no attribute <colormap>is another instance of dynamically generated behavior which can't be statically type checked (elegantly, at least), can probably be replaced bympl.colormaps["<colormap>"]in many cases, which is statically typecheckable- Anything to do with 3D Axes is not type hinted, perhaps ignore for now (or help us get that type hinted adequately, but it is relatively low priority currently)
Module has no attribute "dates"we don't currently type hint dates/units things, but it is on my mind, not sure yet if it will be in first release or not though (may at least put a placeholder that gets rid of this error, but treats everything as "Any").
Originally posted by @ksunden in #7787 (comment)
The suggestion from mpl (specifically @tacaswell) was to use constrained layout for the purpose that xarray currently uses
get_renderer, this will ensure that thefacetgridworks with all mpl backends.
Originally posted by @ksunden in #7787 (comment)
I'm also relatively sure that if you are willing to put a floor on the version of Matplotlib you support
get_window_extentwill use it's internally cached renderer (and when we make it uniformly optional we also fixed the cache invalidation logic).
Originally posted by @tacaswell in #7787 (comment)
Reactions are currently unavailable
Activity
[-]Tackling a few of them (but not all in one go):[/-][+]Mypy errors with matplotlib 3.8[/+]ksunden commentedon May 1, 2023
[xy]ticks upstream PR submitted, linked above
TomNicholas commentedon Jul 15, 2023
@headtr1ck I just got reminded about this issue (in person at scipy) by @ksunden of matplotlib. He says ominously type hints are coming... But that he is willing to help us with type hinting our code.
headtr1ck commentedon Jul 17, 2023
Thanks for the reminder. I should have more time to work on this soon. Would be nice to align everything!
headtr1ck commentedon Jul 29, 2023
I have now an env with the newest numpy (pypi) and matplotlib (main branch).
So far I see 145 errors.
Many of them are from the tests where we get Optional attributes.
And I also get some errors of parts that should not be affected, I guess I have slightly different versions of packages as the github action or something.
Some mypy errors have to be fixed on matplotlibs side.
For example,
"Colorbar" has no attribute "vmin"or"Colormap" has no attribute "colors".@ksunden do you prefer an issue for each of them, or should I compile a single issue where I collect all my findings?
Also, what time is left approx. before 3.8 is released?
headtr1ck commentedon Jul 29, 2023
The major issue that I was encountering was that we do not distinguish between
AxesandAxes3D.The only way to fix this was to add several isinstance checks whenever we expect an Axes3D.
Maybe we could change this somehow, but I think that would be a major refactor, so not worth it.
ksunden commentedon Aug 2, 2023
I think that #8030 clears up most of the flags for 3D stuff (probably mostly by ignoring for now...) it's not super easy to do that statically (as e.g. matplotlib projections are actually a dynamically changeable thing...) we may be able to work towards doing better for axis creation methods, but that only goes so far sometimes... I think some use of
typing.cast(noop at runtime, but informs the type checker) may be useful for encoding certain known side channel information flows, but not likely to be as good as if the API was designed with a more strict type system in mind.We are looking to branch and release an RC this week (maybe as soon as tomorrow, but trying to get a handful of more PRs merged...), and how long it takes/if there are further RCs depends on what feedback we get on the RC (which includes whether further changes are needed to type hints)
wangkuiyi commentedon Sep 2, 2024
@ksunden - I got the same error with matplitlib 3.9.2
@headtr1ck - I fixed the mypy error with explicit type hint