Skip to content

BUG: series assignment with a boolean indexer #2686

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 3 commits into from

Conversation

jreback
Copy link
Contributor

@jreback jreback commented Jan 11, 2013

  • fixed assignment with a boolean indexer and a non-scalar as the value (see below)
  • 2nd commit fixed the alignment issue; that is if the value is not a full series, align first (using where machinery)
  • add neg and inv methods
  • _check_bool_indexer now coerces to bool if needed (otherwise weird effects when doing neg/inv on boolean series)
In [1]: import numpy as np

In [2]: import pandas as pd

In [3]: x = pd.Series(index=np.arange(10))

In [4]: y = pd.Series(np.random.rand(10),index=np.arange(10))

In [5]: y
Out[5]: 
0    0.197830
1    0.134425
2    0.766618
3    0.057765
4    0.790927
5    0.153636
6    0.585305
7    0.906787
8    0.647155
9    0.494154

In [6]: x[y>0.5] = y

In [7]: x
Out[7]: 
0         NaN
1         NaN
2    0.197830
3         NaN
4    0.134425
5         NaN
6    0.766618
7    0.057765
8    0.790927
9         NaN

     fixed setitem with boolean indexer to accept an object needing alignment (e.g. a partial series)
@wesm
Copy link
Member

wesm commented Jan 20, 2013

thanks jeff

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants