Giter VIP home page Giter VIP logo

Comments (3)

Dr-Irv avatar Dr-Irv commented on July 21, 2024 1

Instead of list[_IndexSliceTuple] that I suggested here: #899 (comment)

use Sequence[_IndexSliceTuple] . I tried it on the example above and it worked.

from pandas-stubs.

Dr-Irv avatar Dr-Irv commented on July 21, 2024

Thanks for the report.

I think that if we add list[_IndexSliceTuple] to:

idx: (
MaskType
| Index
| Sequence[float]
| list[str]
| slice
| _IndexSliceTuple
| Callable

that will fix this. PR with tests welcome.

from pandas-stubs.

lionel42 avatar lionel42 commented on July 21, 2024

I updated a test case for the issue in the PR.

I tested the above suggested solution which fails with mypy .

It gives

tests\test_series.py:186: error: Invalid index type "list[tuple[str, str]]" for "_LocIndexerSeries[int]"; expected type "Series[bool] | ndarray[Any, dtype[bool_]] | list[bool] | Index[Any] | Sequence[float] | list[str] | slice | tuple[Index[Any] | Series[bool] | ndarray[Any, dtype[bool_]] | list[bool] | str | bytes | date | datetime | timedelta | datetime64 | timedelta64 | bool | int | float | Timestamp | Timedelta | complex | list[Any] | slice | tuple[str | bytes | date | datetime | timedelta | datetime64 | timedelta64 | bool | int | float | Timestamp | Timedelta | complex, ...], ...] | list[tuple[Index[Any] | Series[bool] | ndarray[Any, dtype[bool_]] | list[bool] | str | bytes | date | datetime | timedelta | datetime64 | timedelta64 | bool | int | float | Timestamp | Timedelta | complex | list[Any] | slice | tuple[str | bytes | date | datetime | timedelta | datetime64 | timedelta64 | bool | int | float | Timestamp | Timedelta | complex, ...], ...]] | Callable[..., Any]"  [index]

instead of

tests\test_series.py:186: error: Invalid index type "list[tuple[str, str]]" for "_LocIndexerSeries[int]"; expected type "Series[bool] | ndarray[Any, dtype[bool_]] | list[bool] | Index[Any] | Sequence[float] | list[str] | slice | tuple[Index[Any] | Series[bool] | ndarray[Any, dtype[bool_]] | list[bool] | str | bytes | date | datetime | timedelta | datetime64 | timedelta64 | bool | int | float | Timestamp | Timedelta | complex | list[Any] | slice | tuple[str | bytes | date | datetime | timedelta | datetime64 | timedelta64 | bool | int | float | Timestamp | Timedelta | complex, ...], ...] | Callable[..., Any]"  [index]

I also tried adding an additional overload option:

    # Multiindex case
    @overload
    def __getitem__(
        self,
        idx: list[_IndexSliceTuple],
    ) -> Series[S1]: ...

This one worked with mypy (no error raised) but it failed for pyright

Poe => test

===========================================
Beginning: 'Run mypy on 'tests' (using the local stubs) and on the local stubs'
===========================================

Success: no issues found in 226 source files

===========================================
End: 'Run mypy on 'tests' (using the local stubs) and on the local stubs', runtime: 39.946 seconds.
===========================================


===========================================
Beginning: 'Run pyright on 'tests' (using the local stubs) and on the local stubs'
===========================================


test_series.py:186:23 - error: No overloads for "__getitem__" match the provided arguments (reportCallIssue)
test_series.py:186:23 - error: Argument of type "list[tuple[Literal['A'], Literal['c']] | tuple[Literal['B'], Literal['d']]]" cannot be assigned to parameter "idx" of type "list[_IndexSliceTuple[Unknown]]" in function "__getitem__"
    "list[tuple[Literal['A'], Literal['c']] | tuple[Literal['B'], Literal['d']]]" is incompatible with "list[_IndexSliceTuple[Unknown]]"
      Type parameter "_T@list" is invariant, but "tuple[Literal['A'], Literal['c']] | tuple[Literal['B'], Literal['d']]" is not the same as "_IndexSliceTuple[Unknown]"
      Consider switching from "list" to "Sequence" which is covariant (reportArgumentType)
test_series.py:186:23 - error: "assert_type" mismatch: expected "Series[int]" but received "Unknown" (reportAssertTypeFailure)
3 errors, 0 warnings, 0 informations

===========================================
Step: 'Run pyright on 'tests' (using the local stubs) and on the local stubs' failed!
===========================================

from pandas-stubs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.