Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

NumPy >= 2.1.0 causes MyPy failures #20561

Closed
Assignees
stinodego
Labels
A-typingArea: type checkingP-mediumPriority: mediumacceptedReady for implementationciRelated to the continuous integration setuppythonRelated to Python Polars
@stinodego

Description

@stinodego

So far this has not shown up the CI becausenumba requiresnumpy < 2.1, but new type improvements in the NumPy library in 2.1 and later are causing failures in our repo.

Reproduction steps:

  • Activate the repo's virtual environment
  • Runuv pip install -U numpy (this should upgradenumpy from2.0.2 to a later version, e.g.2.2.1)
  • Go to thepy-polars folder
  • Runmypy

Example of CI failure:
https://github.com/pola-rs/polars/actions/runs/12619806580/job/35164768145?pr=20549

polars/_utils/various.py:104: error: Incompatible return value type (got "numpy.bool[builtins.bool]", expected "builtins.bool")  [return-value]polars/_utils/various.py:[13](https://github.com/pola-rs/polars/actions/runs/12619806580/job/35164768145?pr=20549#step:6:14)0: error: Incompatible return value type (got "numpy.bool[builtins.bool]", expected "builtins.bool")  [return-value]polars/_utils/various.py:158: error: Incompatible return value type (got "numpy.bool[builtins.bool]", expected "builtins.bool")  [return-value]polars/series/series.py:[14](https://github.com/pola-rs/polars/actions/runs/12619806580/job/35164768145?pr=20549#step:6:15)39: error: Incompatible types in assignment (expression has type "str", variable has type "Literal['?', 'b', 'B', 'h', 'H', 'i', 'I', 'l', 'L', 'q', 'Q', 'e', 'f', 'd', 'g', 'F', 'D', 'G', 'O', 'S', 'a', 'U', 'V', 'M', 'm', 'c', 'T']")  [assignment]polars/series/series.py:4759: error: Unused "type: ignore" comment  [unused-ignore]polars/dataframe/frame.py:1902: error: No overload variant of "__setitem__" of "ndarray" matches argument types "str", "ndarray[Any, Any]"  [call-overload]polars/dataframe/frame.py:1902: note: Possible overload variants:polars/dataframe/frame.py:1902: note:     def __setitem__(self, SupportsIndex | slice[Any, Any, Any] | EllipsisType | _SupportsArray[dtype[numpy.bool[builtins.bool]] | dtype[integer[Any]]] | _NestedSequence[_SupportsArray[dtype[numpy.bool[builtins.bool]] | dtype[integer[Any]]]] | builtins.bool | int | _NestedSequence[builtins.bool | int] | None | tuple[SupportsIndex | slice[Any, Any, Any] | EllipsisType | _SupportsArray[dtype[numpy.bool[builtins.bool]] | dtype[integer[Any]]] | _NestedSequence[_SupportsArray[dtype[numpy.bool[builtins.bool]] | dtype[integer[Any]]]] | builtins.bool | int | _NestedSequence[builtins.bool | int] | None, ...], object, /) -> Nonepolars/dataframe/frame.py:1902: note:     def __setitem__(self, SupportsIndex | slice[Any, Any, Any] | EllipsisType | _SupportsArray[dtype[numpy.bool[builtins.bool]] | dtype[integer[Any]]] | _NestedSequence[_SupportsArray[dtype[numpy.bool[builtins.bool]] | dtype[integer[Any]]]] | builtins.bool | int | _NestedSequence[builtins.bool | int] | None | tuple[SupportsIndex | slice[Any, Any, Any] | EllipsisType | _SupportsArray[dtype[numpy.bool[builtins.bool]] | dtype[integer[Any]]] | _NestedSequence[_SupportsArray[dtype[numpy.bool[builtins.bool]] | dtype[integer[Any]]]] | builtins.bool | int | _NestedSequence[builtins.bool | int] | None, ...], SupportsInt | SupportsIndex | str | bytes | _NestedSequence[SupportsInt | SupportsIndex | str | bytes] | _SupportsArray[dtype[numpy.bool[builtins.bool]] | dtype[integer[Any]]] | _NestedSequence[_SupportsArray[dtype[numpy.bool[builtins.bool]] | dtype[integer[Any]]]] | builtins.bool | int | _NestedSequence[builtins.bool | int], /) -> Nonepolars/dataframe/frame.py:1902: note:     def __setitem__(self, SupportsIndex | slice[Any, Any, Any] | EllipsisType | _SupportsArray[dtype[numpy.bool[builtins.bool]] | dtype[integer[Any]]] | _NestedSequence[_SupportsArray[dtype[numpy.bool[builtins.bool]] | dtype[integer[Any]]]] | builtins.bool | int | _NestedSequence[builtins.bool | int] | None | tuple[SupportsIndex | slice[Any, Any, Any] | EllipsisType | _SupportsArray[dtype[numpy.bool[builtins.bool]] | dtype[integer[Any]]] | _NestedSequence[_SupportsArray[dtype[numpy.bool[builtins.bool]] | dtype[integer[Any]]]] | builtins.bool | int | _NestedSequence[builtins.bool | int] | None, ...], SupportsFloat | SupportsIndex | str | bytes | _NestedSequence[SupportsFloat | SupportsIndex | str | bytes | None] | <6 more items> | None, /) -> Nonepolars/dataframe/frame.py:1902: note:     def __setitem__(self, SupportsIndex | slice[Any, Any, Any] | EllipsisType | _SupportsArray[dtype[numpy.bool[builtins.bool]] | dtype[integer[Any]]] | _NestedSequence[_SupportsArray[dtype[numpy.bool[builtins.bool]] | dtype[integer[Any]]]] | builtins.bool | int | _NestedSequence[builtins.bool | int] | None | tuple[SupportsIndex | slice[Any, Any, Any] | EllipsisType | _SupportsArray[dtype[numpy.bool[builtins.bool]] | dtype[integer[Any]]] | _NestedSequence[_SupportsArray[dtype[numpy.bool[builtins.bool]] | dtype[integer[Any]]]] | builtins.bool | int | _NestedSequence[builtins.bool | int] | None, ...], SupportsComplex | SupportsFloat | SupportsIndex | str | bytes | <8 more items> | None, /) -> Nonepolars/dataframe/frame.py:1902: note:     def __setitem__(self, SupportsIndex | slice[Any, Any, Any] | EllipsisType | _SupportsArray[dtype[numpy.bool[builtins.bool]] | dtype[integer[Any]]] | _NestedSequence[_SupportsArray[dtype[numpy.bool[builtins.bool]] | dtype[integer[Any]]]] | builtins.bool | int | _NestedSequence[builtins.bool | int] | None | tuple[SupportsIndex | slice[Any, Any, Any] | EllipsisType | _SupportsArray[dtype[numpy.bool[builtins.bool]] | dtype[integer[Any]]] | _NestedSequence[_SupportsArray[dtype[numpy.bool[builtins.bool]] | dtype[integer[Any]]]] | builtins.bool | int | _NestedSequence[builtins.bool | int] | None, ...], timedelta | int | str | bytes | character[str | bytes] | number[Any, int | float | complex] | timedelta64[timedelta | int | None] | numpy.bool[builtins.bool] | _NestedSequence[timedelta | int | str | bytes | character[str | bytes] | number[Any, int | float | complex] | timedelta64[timedelta | int | None] | numpy.bool[builtins.bool] | None] | None, /) -> Nonepolars/dataframe/frame.py:1902: note:     def __setitem__(self, SupportsIndex | slice[Any, Any, Any] | EllipsisType | _SupportsArray[dtype[numpy.bool[builtins.bool]] | dtype[integer[Any]]] | _NestedSequence[_SupportsArray[dtype[numpy.bool[builtins.bool]] | dtype[integer[Any]]]] | builtins.bool | int | _NestedSequence[builtins.bool | int] | None | tuple[SupportsIndex | slice[Any, Any, Any] | EllipsisType | _SupportsArray[dtype[numpy.bool[builtins.bool]] | dtype[integer[Any]]] | _NestedSequence[_SupportsArray[dtype[numpy.bool[builtins.bool]] | dtype[integer[Any]]]] | builtins.bool | int | _NestedSequence[builtins.bool | int] | None, ...], date | int | str | bytes | character[str | bytes] | number[Any, int | float | complex] | datetime64[date | int | None] | numpy.bool[builtins.bool] | _NestedSequence[date | int | str | bytes | character[str | bytes] | number[Any, int | float | complex] | datetime64[date | int | None] | numpy.bool[builtins.bool] | None] | None, /) -> Nonepolars/dataframe/frame.py:1902: note:     def __setitem__(self, SupportsIndex | slice[Any, Any, Any] | EllipsisType | _SupportsArray[dtype[numpy.bool[builtins.bool]] | dtype[integer[Any]]] | _NestedSequence[_SupportsArray[dtype[numpy.bool[builtins.bool]] | dtype[integer[Any]]]] | builtins.bool | int | _NestedSequence[builtins.bool | int] | None | tuple[SupportsIndex | slice[Any, Any, Any] | EllipsisType | _SupportsArray[dtype[numpy.bool[builtins.bool]] | dtype[integer[Any]]] | _NestedSequence[_SupportsArray[dtype[numpy.bool[builtins.bool]] | dtype[integer[Any]]]] | builtins.bool | int | _NestedSequence[builtins.bool | int] | None, ...], Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], /) -> Nonetests/unit/interop/numpy/test_to_numpy_series.py:58: error: Non-overlapping equality check (left operand type: "str", right operand type: "list[Any]")  [comparison-overlap]tests/unit/interop/numpy/test_to_numpy_series.py:83: error: Non-overlapping equality check (left operand type: "str", right operand type: "list[Any]")  [comparison-overlap]tests/unit/interop/numpy/test_to_numpy_series.py:112: error: Non-overlapping equality check (left operand type: "str", right operand type: "list[int]")  [comparison-overlap]tests/unit/interop/numpy/test_to_numpy_series.py:114: error: Non-overlapping equality check (left operand type: "str", right operand type: "list[Any]")  [comparison-overlap]tests/unit/interop/numpy/test_to_numpy_series.py:124: error: Non-overlapping equality check (left operand type: "str", right operand type: "list[datetime]")  [comparison-overlap]tests/unit/interop/numpy/test_to_numpy_series.py:134: error: Non-overlapping equality check (left operand type: "list[Any]", right operand type: "str")  [comparison-overlap]tests/unit/interop/numpy/test_to_numpy_series.py:175: error: Non-overlapping equality check (left operand type: "str", right operand type: "list[int | None]")  [comparison-overlap]tests/unit/interop/numpy/test_to_numpy_series.py:177: error: Non-overlapping equality check (left operand type: "str", right operand type: "list[Any]")  [comparison-overlap]tests/unit/interop/numpy/test_to_numpy_series.py:187: error: Non-overlapping equality check (left operand type: "str", right operand type: "list[datetime | None]")  [comparison-overlap]tests/unit/interop/numpy/test_to_numpy_series.py:214: error: Non-overlapping equality check (left operand type: "str", right operand type: "list[Any]")  [comparison-overlap]tests/unit/interop/numpy/test_to_numpy_series.py:223: error: Non-overlapping equality check (left operand type: "list[Any]", right operand type: "str")  [comparison-overlap]tests/unit/interop/numpy/test_to_numpy_series.py:233: error: Non-overlapping equality check (left operand type: "list[Any]", right operand type: "str")  [comparison-overlap]tests/unit/interop/numpy/test_to_numpy_series.py:253: error: Non-overlapping equality check (left operand type: "str", right operand type: "list[list[str]]")  [comparison-overlap]tests/unit/interop/numpy/test_to_numpy_series.py:348: error: Non-overlapping equality check (left operand type: "str", right operand type: "list[Any]")  [comparison-overlap]tests/unit/interop/numpy/test_to_numpy_series.py:355: error: Non-overlapping equality check (left operand type: "str", right operand type: "list[int]")  [comparison-overlap]tests/unit/interop/numpy/test_to_numpy_series.py:367: error: Non-overlapping equality check (left operand type: "str", right operand type: "list[Any]")  [comparison-overlap]tests/unit/interop/numpy/test_to_numpy_series.py:379: error: Non-overlapping equality check (left operand type: "str", right operand type: "list[int]")  [comparison-overlap]tests/unit/interop/numpy/test_to_numpy_df.py:[16](https://github.com/pola-rs/polars/actions/runs/12619806580/job/35164768145?pr=20549#step:6:17)6: error: Non-overlapping equality check (left operand type: "str", right operand type: "list[list[Any]]")  [comparison-overlap]tests/unit/series/test_series.py:5[17](https://github.com/pola-rs/polars/actions/runs/12619806580/job/35164768145?pr=20549#step:6:18): error: Incompatible types in assignment (expression has type "list[Any] | str", variable has type "list[Any | None]")  [assignment]tests/unit/datatypes/test_temporal.py:290: error: No overload variant of "datetime64" matches argument types "datetime", "str"  [call-overload]tests/unit/datatypes/test_temporal.py:290: note: Possible overload variants:tests/unit/datatypes/test_temporal.py:290: note:     def [_DT64ItemT_co: date | int | None] __init__(self, datetime64[_DT64ItemT_co], /) -> datetime64[_DT64ItemT_co]tests/unit/datatypes/test_temporal.py:290: note:     def [_DT64ItemT_co: date | int | None, _AnyDT64Arg: (datetime, date, None)] __init__(self, _AnyDT64Arg, /) -> datetime64[_AnyDT64Arg]tests/unit/datatypes/test_temporal.py:290: note:     def [_DT64ItemT_co: date | int | None] __init__(self, Literal['NAT', 'NaT', 'nat', b'NAT', b'NaT', b'nat'] | None = ..., Literal['Y', 'M', b'Y', b'M', 'W', 'D', b'W', b'D', 'h', 'm', 's', 'ms', 'us', 'μs', b'h', b'm', b's', b'ms', b'us', 'ns', 'ps', 'fs', 'as', b'ns', b'ps', b'fs', b'as'] | tuple[Literal['Y', 'M', b'Y', b'M', 'W', 'D', b'W', b'D', 'h', 'm', 's', 'ms', 'us', 'μs', b'h', b'm', b's', b'ms', b'us', 'ns', 'ps', 'fs', 'as', b'ns', b'ps', b'fs', b'as'], SupportsIndex] = ..., /) -> datetime64[None]tests/unit/datatypes/test_temporal.py:290: note:     def [_DT64ItemT_co: date | int | None] __init__(self, Literal['NOW', 'now', b'NOW', b'now'], Literal['h', 'm', 's', 'ms', 'us', 'μs', b'h', b'm', b's', b'ms', b'us'] | tuple[Literal['h', 'm', 's', 'ms', 'us', 'μs', b'h', b'm', b's', b'ms', b'us'], SupportsIndex] = ..., /) -> datetime64[datetime]tests/unit/datatypes/test_temporal.py:290: note:     def [_DT64ItemT_co: date | int | None] __init__(self, Literal['TODAY', 'today', b'TODAY', b'today'] | _HasDateAttributes, Literal['Y', 'M', b'Y', b'M', 'W', 'D', b'W', b'D'] | tuple[Literal['Y', 'M', b'Y', b'M', 'W', 'D', b'W', b'D'], SupportsIndex] = ..., /) -> datetime64[date]tests/unit/datatypes/test_temporal.py:290: note:     def [_DT64ItemT_co: date | int | None] __init__(self, int | bytes | str | date, Literal['ns', 'ps', 'fs', 'as', b'ns', b'ps', b'fs', b'as'] | tuple[Literal['ns', 'ps', 'fs', 'as', b'ns', b'ps', b'fs', b'as'], SupportsIndex], /) -> datetime64[int]tests/unit/datatypes/test_temporal.py:290: note:     def [_DT64ItemT_co: date | int | None] __init__(self, int | bytes | str, Literal['h', 'm', 's', 'ms', 'us', 'μs', b'h', b'm', b's', b'ms', b'us'] | tuple[Literal['h', 'm', 's', 'ms', 'us', 'μs', b'h', b'm', b's', b'ms', b'us'], SupportsIndex], /) -> datetime64[datetime]tests/unit/datatypes/test_temporal.py:290: note:     def [_DT64ItemT_co: date | int | None] __init__(self, int | bytes | str, Literal['Y', 'M', b'Y', b'M', 'W', 'D', b'W', b'D'] | tuple[Literal['Y', 'M', b'Y', b'M', 'W', 'D', b'W', b'D'], SupportsIndex], /) -> datetime64[date]tests/unit/datatypes/test_temporal.py:290: note:     def [_DT64ItemT_co: date | int | None] __init__(self, bytes | str | None, Literal['Y', 'M', b'Y', b'M', 'W', 'D', b'W', b'D', 'h', 'm', 's', 'ms', 'us', 'μs', b'h', b'm', b's', b'ms', b'us', 'ns', 'ps', 'fs', 'as', b'ns', b'ps', b'fs', b'as'] | tuple[Literal['Y', 'M', b'Y', b'M', 'W', 'D', b'W', b'D', 'h', 'm', 's', 'ms', 'us', 'μs', b'h', b'm', b's', b'ms', b'us', 'ns', 'ps', 'fs', 'as', b'ns', b'ps', b'fs', b'as'], SupportsIndex] = ..., /) -> datetime64[_DT64ItemT_co]Found 26 errors in 7 files (checked 554 source files)

Some of the problems seem to be on NumPy's side. They have an issue related to typing regressions:
numpy/numpy#28076

We should look into fixing this on our side as much as possible, so that we can run MyPy with the latest NumPy version.

Metadata

Metadata

Assignees

Labels

A-typingArea: type checkingP-mediumPriority: mediumacceptedReady for implementationciRelated to the continuous integration setuppythonRelated to Python Polars

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp