Skip to content

BUG: where gives incorrect results when upcasting (GH 9731) #9743

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
merged 2 commits into from
Apr 2, 2015

Conversation

evanpw
Copy link
Contributor

@evanpw evanpw commented Mar 28, 2015

closes #9731

The main issue is when the destination and source arrays have different lengths, np.putmask doesn't behave like arr[mask] = values:

"Sets a.flat[n] = values[n] for each n where mask.flat[n]==True"

We have to use np.place instead. A secondary issue is that np.place doesn't automatically convert an integer to a datetime64 like np.putmask does (I created a numpy issue for this), so we need an additional check for that case. The rest of the commit is just cleaning up _maybe_upcast_putmask, which had some parameters that were never used, and a confusing docstring.

@jreback jreback added the Bug label Mar 28, 2015
if `value` is an integer or integer array, convert to `dtype`
"""
if dtype in _DATELIKE_DTYPES:
if np.isscalar(value):
Copy link
Contributor

Choose a reason for hiding this comment

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

use lib.isscalar

@jreback jreback added the Indexing Related to indexing on series/frames, not to indexes themselves label Apr 2, 2015
@jreback jreback added this to the 0.16.1 milestone Apr 2, 2015
jreback added a commit that referenced this pull request Apr 2, 2015
BUG: where gives incorrect results when upcasting (GH 9731)
@jreback jreback merged commit 7dfb279 into pandas-dev:master Apr 2, 2015
@jreback
Copy link
Contributor

jreback commented Apr 2, 2015

@evanpw thanks!

this was subtle!

@jreback
Copy link
Contributor

jreback commented Apr 2, 2015

I assume you changed to use np.place because some OTHER tests were initially failing on your change. Or do we need some tests for the same operation but with dtype = M8[ns] or m8[ns]?

if so, can you do a pr with those?

@evanpw
Copy link
Contributor Author

evanpw commented Apr 3, 2015

The tests that were failing after I changed np.putmask to np.place were the ones testing idxmax and idxmin, but the new tests in GH #9804 are more direct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[] (__getitem__) boolean indexing assignment bug with nans
2 participants