Skip to content

BUG: Invalid index type "Tuple[slice, int]" for "_LocIndexerFrame"; #133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bashtage opened this issue Jul 12, 2022 · 2 comments
Closed

Comments

@bashtage
Copy link
Contributor

Describe the bug
Standard loc operations fails

To Reproduce

import pandas as pd

df = pd.DataFrane({1000: [1,2,3], 2000:[3,4,5]})
df.loc[:, 2000]

Produces

 error: Invalid index type "Tuple[slice, int]" for "_LocIndexerFrame"; expected type "Union[Union[slice, ndarray[Any, dtype[signedinteger[_64Bit]]], Index, List[int], Series[int]], Union[Series[bool], ndarray[Any, dtype[bool_]], List[bool]],
 List[Union[str, str_]], Tuple[Union[Union[slice, ndarray[Any, dtype[signedinteger[_64Bit]]], Index, List[int], Series[int]], Union[Series[bool], ndarray[Any, dtype[bool_]], List[bool]], slice, List[Union[str, str_]], Tuple[Union[str, int, slice], ...]], Union[List[Union[str, str_]], slice, Series[bool], Callable[..., Any]]]]"

Please complete the following information:

  • Windows
  • 11
  • 3.10
  • mypy 0.961
  • pandas-stubs 1.4.3.220710
@bashtage
Copy link
Contributor Author

bashtage commented Jul 12, 2022

Loosely speaking I think loc should take some combinations like

_sliceT = Union[slice, pd.IndexSlice]
Label = Hashable | None

Sequence[Label]
_sliceT
Label
tuple[Sequence[Label], Sequence[Label]]
tuple[Sequence[Label], _sliceT]
tuple[Sequence[Label], Label]
tuple[_sliceT , _sliceT]
tuple[_sliceT , Sequence[Label]]
tuple[_sliceT , Label]

bashtage pushed a commit to bashtage/pandas-stubs that referenced this issue Jul 13, 2022
Allow any scalar types in .loc to return a Series

xref pandas-dev#133
bashtage pushed a commit to bashtage/pandas-stubs that referenced this issue Jul 13, 2022
Allow any scalar types in .loc to return a Series

xref pandas-dev#133
bashtage pushed a commit to bashtage/pandas-stubs that referenced this issue Jul 15, 2022
Allow any scalar types in .loc to return a Series

xref pandas-dev#133
Dr-Irv pushed a commit that referenced this issue Jul 15, 2022
* ENH: Improve DataFrame loc indexing

Allow any scalar types in .loc to return a Series

xref #133

* TST: Add check

Co-authored-by: Kevin Sheppard <[email protected]>
@bashtage
Copy link
Contributor Author

closed in #138

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant