-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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
ERR: Improve error message and doc for invalid labels in cut/qcut #30691
Conversation
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 |
Looks like you already made most of these changes in this PR: https://github.com/pandas-dev/pandas/pull/30615/files ? |
looks like this pickup up your other changes. |
7c7d565
to
23f900f
Compare
sorry my mistake - just rebased with master now |
hmm mypy seems to be giving:
Need to wait for this to be merged: #30698 |
Looks like im getting an unrelated compiler error in one of the builds - can see its throwing errors in other PRs as well
|
Yeah the numpy dev build will fail if any warnings are raised. Hopefully someone will have a look soon.. |
pandas/core/reshape/tile.py
Outdated
"User desired bin labels must be passed in as an argument, " | ||
"not just `True`" | ||
) | ||
elif is_list_like(labels): |
There was a problem hiding this comment.
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')
pandas/core/reshape/tile.py
Outdated
@@ -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: |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
99fbf2a
to
174dc3d
Compare
thanks @ryankarlos |
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff