Comments (3)
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.
Thanks for the report.
I think that if we add list[_IndexSliceTuple]
to:
pandas-stubs/pandas-stubs/core/series.pyi
Lines 194 to 201 in 0342d90
that will fix this. PR with tests welcome.
from pandas-stubs.
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)
- Issue with `concat` and passing a `Union` due to presence of checking for `Iterable[None]` HOT 2
- result of itertuples gives an error when passed to NamedTuple - incompatible type "_PandasNamedTuple"; expected "NamedTuple" HOT 1
- DatetimeIndex constructor should accept set HOT 3
- pd.concat with names=None HOT 5
- Series.fillna(None) HOT 3
- Wrong typing for the `values` argument of the `pandas.DataFrame.pivot_table` method HOT 5
- Error: "Object of type `Series[Unknown]` is not callable" on groupby().size().to_frame() HOT 1
- In `DataFrame.select_dtypes` type values like `np.number` or `np.datetime64` should be allowed HOT 2
- `concat` of types `Iterable[Any]` cause Pyright to think subsequent code is unreachable because of recent stubs change HOT 39
- Argument of type `str` cannot be assigned to parameter `index_col` in function `read_excel` HOT 1
- pd.to_datetime(list[datetime.date]) is wrong input type (mypy), but pandas returns output. HOT 2
- Pandas concat incorrectly marks subsequent code as unreachable HOT 1
- pandas.DataFrame.from_dict : issue with dtype and columns arguments types HOT 2
- concat still reports unreachable for Iterable[None|Any] corner case HOT 11
- register_dataframe_accessor causes "Untyped class decorator obscures type of class; ignoring decorator" HOT 2
- Return type of pipe not consistent with types at run time HOT 7
- README.md still suggests to join a gitter room HOT 1
- VSCode questions HOT 6
- Use the new TypeIs feature to update the notna/notnull/isna/isnull type guards
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pandas-stubs.