Skip to content

ERR: better error message with invalid argument in sort_values #42358

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
wants to merge 2 commits into from
Closed

ERR: better error message with invalid argument in sort_values #42358

wants to merge 2 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Jul 3, 2021

  • closes #xxxx
  • tests added / passed
  • Ensure all linting tests pass, see here for how to run them
  • whatsnew entry
    added a if branch to check the ascending type, as the existing one accepts value with string as well instead of boolean.

k=df.sort_values(by=['col1'],ascending="False") does not give exception with str.
added piece of code to raise exception if the type is not boolean

@pep8speaks
Copy link

pep8speaks commented Jul 3, 2021

Hello @deej197! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

Line 3444:1: W293 blank line contains whitespace
Line 3445:9: E303 too many blank lines (2)
Line 3445:27: E225 missing whitespace around operator

Comment last updated at 2021-07-03 19:22:47 UTC

@@ -3441,8 +3441,10 @@ def sort_values(
)
ascending = ascending[0]

if not is_bool(ascending):
raise ValueError("ascending must be boolean")
#if not is_bool(ascending):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is_bool(ascending) is equivalent to isinstance(ascending, (bool, np.bool_), so this shouldn't make a difference. if im wrong and this does make a difference, this needs a test

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i see this issue open #41634. if this is not resolved, then is_bool function is not working as expected.

regarding the comment, wasnt aware of the same as this is my first contribution. will note this for future.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@deej197 Isn't this issue for DataFrame not series?

def sort_values( # type: ignore[override]

You might want to look into using validate_ascending

def validate_ascending(

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lithomas1 I can make the changes in this validate_ascending function , but i am stuck in running tests locally. I tried replacing the pandas package in C:\Users\usename\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages with the modified package, but i dont see the changes being applied.

appreciate any suggestions on executing tests internally.

#if not is_bool(ascending):
# raise ValueError("ascending must be boolean")
if type(ascending)!=bool:
raise ValueError("ascending should of type bool")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are there some words left out of this message? what's wrong with the existing one?

@jreback jreback changed the title ENH ERR: better error message with invalid argument in sort_values Jul 4, 2021
@jreback jreback added the Error Reporting Incorrect or improved errors from pandas label Jul 4, 2021
@datapythonista
Copy link
Member

Thanks for the contribution @deej197, but unfortunately you won't be able to contribute with a proper development environment. If you could run this test locally you could see that:

  • It's adding new bugs, and doesn't affect the current one
  • The problem is not the one you mention in the title, the error message is fine, the problem is that it only raises on Series, and not in DataFrame.

And it's also better to start by opening an issue, finding a reproducible example, and when there is agreement with the solution, then open the PR (which would require tests and a release note, besides the code changes). I opened an issue myself, so you can see how would be better to start: #42434. Feel free to work on the issue, but as I said, you need a working development environment. Otherwise you won't be able to test what you're doing, and you'll be submitting obviously wrong PRs like this, that don't add value, and waste reviewers time.

If you follow the contribution guide, you shouldn't have problems setting up the develoment environment, if something is not clear enough, feel free to open an issue to ask for clarification in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Error Reporting Incorrect or improved errors from pandas
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants