Skip to content

ERR: Improve error message and doc for invalid labels in cut/qcut #30691

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

Merged

Conversation

ryankarlos
Copy link
Contributor

@ryankarlos ryankarlos commented Jan 4, 2020

@pep8speaks
Copy link

pep8speaks commented Jan 4, 2020

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

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2020-01-07 17:48:37 UTC

@ryankarlos ryankarlos changed the title ERR: Improve error message and doc for labels is True in cut/qcut ERR: Improve error message and doc for invalid labels in cut/qcut Jan 4, 2020
@alimcmaster1 alimcmaster1 added the Deprecate Functionality to remove in pandas label Jan 4, 2020
@alimcmaster1
Copy link
Member

Looks like you already made most of these changes in this PR: https://github.com/pandas-dev/pandas/pull/30615/files ?

@alimcmaster1 alimcmaster1 removed the Deprecate Functionality to remove in pandas label Jan 4, 2020
@jreback
Copy link
Contributor

jreback commented Jan 4, 2020

looks like this pickup up your other changes.

@ryankarlos ryankarlos force-pushed the ERR/imporve_error_message_cut/qcut branch from 7c7d565 to 23f900f Compare January 4, 2020 19:08
@alimcmaster1 alimcmaster1 added Docs Error Reporting Incorrect or improved errors from pandas labels Jan 4, 2020
@ryankarlos
Copy link
Contributor Author

sorry my mistake - just rebased with master now

@alimcmaster1
Copy link
Member

alimcmaster1 commented Jan 4, 2020

hmm mypy seems to be giving:

Performing static analysis using mypy
pandas/core/generic.py:464: error: Non-overlapping identity check (left operand type: "str", right operand type: "Type[int]")
Found 1 error in 1 file (checked 842 source files)
Performing static analysis using mypy DONE
##[error]Process completed with exit code 1.

Need to wait for this to be merged: #30698

@ryankarlos
Copy link
Contributor Author

ryankarlos commented Jan 5, 2020

Looks like im getting an unrelated compiler error in one of the builds - can see its throwing errors in other PRs as well

gcc -pthread -shared -B /home/vsts/miniconda3/envs/pandas-dev/compiler_compat -L/home/vsts/miniconda3/envs/pandas-dev/lib -Wl,-rpath=/home/vsts/miniconda3/envs/pandas-dev/lib -Wl,--no-as-needed -Wl,--sysroot=/ build/temp.linux-x86_64-3.7/pandas/io/sas/sas.o -o /home/vsts/work/1/s/pandas/io/sas/_sas.cpython-37m-x86_64-linux-gnu.so
error: command 'gcc' failed with exit status 1
##[error]Bash exited with code '1'.
Finishing: Setup environment and build pandas

@alimcmaster1
Copy link
Member

alimcmaster1 commented Jan 5, 2020

Yeah the numpy dev build will fail if any warnings are raised.
Due to this flag https://github.com/pandas-dev/pandas/blob/master/ci/azure/posix.yml#L59

Hopefully someone will have a look soon..

"User desired bin labels must be passed in as an argument, "
"not just `True`"
)
elif is_list_like(labels):
Copy link
Contributor

Choose a reason for hiding this comment

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

ok, can you add an else that handles the non-list-like case (e.g. 'foo')

@@ -396,7 +398,12 @@ def _bins_to_cuts(
labels = _format_labels(
bins, precision, right=right, include_lowest=include_lowest, dtype=dtype
)
else:
elif labels is True:
Copy link
Member

Choose a reason for hiding this comment

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

Maybe a little bit cleaner to validate labels immediately instead of embedding the logic here. Right after the duplicates validation at the beginning of _bins_to_cuts you could add something like:

if labels is not None and labels is not False and not is_list_like(labels):
    raise ValueError(...)

Or alternatively could factor out the not:

if not (labels is None or labels is False or is_list_like(labels)):
    raise ValueError(...)

This would allow the rest of the logic in the _bins_to_cut to proceed under the assumption that labels is valid. The advantage being then that this block of code can remain unchanged as the else block here must be list-like labels since the other two options have already been eliminated by the preceding if statements.

Copy link
Contributor Author

@ryankarlos ryankarlos Jan 7, 2020

Choose a reason for hiding this comment

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

Thanks for the feedback. Ive now added a block for eliminating not None and not is_list_like (which allows me to get rid of the is True check and embed that in the previous check) but after doing a check for is not False as there is also an outer else block for cases where labels is False, so was a bit tricky doing them all in one go but hopefully it looks a lot cleaner now.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks. For checking all three in one go I meant moving the check further up in _bins_to_cuts to around line 369.

@jschendel jschendel added the Reshaping Concat, Merge/Join, Stack/Unstack, Explode label Jan 7, 2020
@ryankarlos ryankarlos force-pushed the ERR/imporve_error_message_cut/qcut branch from 99fbf2a to 174dc3d Compare January 7, 2020 17:33
@ryankarlos ryankarlos requested a review from jschendel January 7, 2020 18:38
@jreback jreback added this to the 1.0 milestone Jan 7, 2020
@jreback jreback merged commit c8a6d8c into pandas-dev:master Jan 7, 2020
@jreback
Copy link
Contributor

jreback commented Jan 7, 2020

thanks @ryankarlos

@ryankarlos ryankarlos deleted the ERR/imporve_error_message_cut/qcut branch January 8, 2020 03:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Docs Error Reporting Incorrect or improved errors from pandas Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ERR: cut/qcut need better error message when passing invalid input
6 participants