-
-
Notifications
You must be signed in to change notification settings - Fork 19.4k
BUG: Coercing bool types to int in qcut #28802
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
BUG: Coercing bool types to int in qcut #28802
Conversation
pandas/core/reshape/tile.py
Outdated
|
|
||
| if dtype is not None: | ||
| # GH 19768: force NaT to NaN during integer conversion | ||
| if is_bool_dtype(x): |
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.
@jreback Not entirely sure where this should go - Adding x.astype(int) under elif is_bool_dtype(x) higher up throws an error in tests with the existing np.where(x.notna(), x.view(np.int64), np.nan) statement if x is ndarray - it passes if x is Series though.
AttributeError: 'numpy.ndarray' object has no attribute 'isnan'
It passes if adding is_bool_dtype(x) with new np.where condition using ~np.isnan(x) like i've done here to account for x being an ndarray
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.
so don't use np.isnan, change this to
x = np.where(notna(x), x.astype(np.int64, copy=False), np.nan)
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.
I've gone with doing the integer conversion in the elif block higher up and leaving dtype as None as @jschendel suggested, rather than making any changes here.
pandas/core/reshape/tile.py
Outdated
|
|
||
| if dtype is not None: | ||
| # GH 19768: force NaT to NaN during integer conversion | ||
| if is_bool_dtype(x): |
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.
so don't use np.isnan, change this to
x = np.where(notna(x), x.astype(np.int64, copy=False), np.nan)
doc/source/whatsnew/v0.25.1.rst
Outdated
|
|
||
| - Bug in :meth:`Series.replace` and :meth:`DataFrame.replace` when replacing timezone-aware timestamps using a dict-like replacer (:issue:`27720`) | ||
| - Bug in :meth:`Series.rename` when using a custom type indexer. Now any value that isn't callable or dict-like is treated as a scalar. (:issue:`27814`) | ||
| - :func:`qcut` and `cut` now handle boolean input (:issue:`20303`) |
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.
can you put :func:`cut` as well
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.
this needs to go in 1.0.0
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.
Done
…ercing-bool-types-to-int-in-qcut
|
thanks @ryankarlos |
pytest pandas/tests/reshape/test_qcut.py pandas/tests/reshape/test_cut.py -vblack pandasgit diff upstream/master --name-only -- "*.py" | xargs flake8