Skip to content
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

DataFrame.sort_values overload signature is incomplete with respect to the ascending argument #63

Closed
miggec opened this issue Aug 18, 2021 · 1 comment · Fixed by #64
Assignees

Comments

@miggec
Copy link

miggec commented Aug 18, 2021

python 3.6
pandas 1.1.5
pandas-stubs 1.2.0.1

The docs state that a list of bools is accepted for the ascending argument, but the stubs raise an error in that instance.

Minimal example of some (valid) code that fails type checking:

import pandas

df = pandas.DataFrame(
    [[1, 'a'], [2, 'b'], [2, 'c']],
    columns=['num', 'char']
)
print(df)
df = df.sort_values(
    by=['num', 'char'],
    ascending=[True, False],
)
print(df)

Output:

   num char
0    1    a
1    2    b
2    2    c
   num char
0    1    a
2    2    c
1    2    b

mypy error:

error: No overload variant of "sort_values" of "DataFrame" matches argument types "List[str]", "List[bool]", "bool"  [call-overload]
note: Possible overload variant:
note:     def sort_values(self, by: Union[str, List[str]], axis: Union[Literal[0], Literal[1], Union[Literal['index'], Literal['columns']]] = ..., ascending: bool = ..., kind: Union[Literal['quicksort'], Literal['mergesort'], Literal['heapsort']] = ..., na_position: Union[Literal['first'], Literal['last']] = ..., ignore_index: bool = ..., key: Optional[Callable[[Series], Union[Series, Union[Union[ExtensionArray, Any], Index, Series]]]] = ..., *, inplace: Literal[False] = ...) -> DataFrame
note:     <1 more non-matching overload not shown>

A workaround if you came here from a search engine:

import pandas

df = pandas.DataFrame(
    [[1, 'a'], [2, 'b'], [2, 'c']],
    columns=['num', 'char']
)
print(df)
ascending: Any = [True, False]
df = df.sort_values(
    by=['num', 'char'],
    ascending=ascending,
)
print(df)
@joannasendorek
Copy link
Collaborator

Hi! Thank you for reporting an issue. Please see #64 for a fix. It should be merged soon.

@joannasendorek joannasendorek linked a pull request Aug 20, 2021 that will close this issue
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

Successfully merging a pull request may close this issue.

2 participants