Skip to content
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: alignment bug when setting a subset of rows and attempting to switch columns #8258

Closed
johne13 opened this issue Sep 12, 2014 · 0 comments · Fixed by #8457
Closed

BUG: alignment bug when setting a subset of rows and attempting to switch columns #8258

johne13 opened this issue Sep 12, 2014 · 0 comments · Fixed by #8457
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves
Milestone

Comments

@johne13
Copy link

johne13 commented Sep 12, 2014

Originally posted at stackexchange:
http://stackoverflow.com/questions/25811529/setting-values-on-a-subset-of-rows-indexing-boolean-setting/25812825#25812825
Jeff suggested posting here also.

df = DataFrame({'L':   ['left', 'right', 'left', 'right'],
                'R':   ['right', 'left', 'right', 'left'],
                'idx': [False, True, False, True],
                'num': np.arange(4) })

df1 = df.copy()
df2 = df.copy()
df3 = df.copy()
df4 = df.copy()

#1 nothing happens (expected result)
df1.loc[df1.idx,['L','R']] = df1.loc[df1.idx,['R','L']]

#2 something weird happens
df2.loc[df2.idx,['L','R']] = df2[['R','L']]

Results below:

In [572]: df
Out[572]: 
       L      R    idx  num
0   left  right  False    0
1  right   left   True    1
2   left  right  False    2
3  right   left   True    3

In [573]: df1
Out[573]: 
       L      R    idx  num
0   left  right  False    0
1  right   left   True    1
2   left  right  False    2
3  right   left   True    3

In [574]: df2
Out[574]: 
       L      R    idx  num
0   left  right  False    0
1   left  right   True    1
2   left  right  False    2
3  right   left   True    3
INSTALLED VERSIONS
------------------
commit: None
python: 2.7.7.final.0
python-bits: 64
OS: Windows
OS-release: 7
machine: AMD64
processor: Intel64 Family 6 Model 26 Stepping 5, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None

pandas: 0.14.1.dev
nose: 1.3.3
Cython: 0.20.1
numpy: 1.8.1
scipy: 0.14.0
statsmodels: 0.5.0
IPython: 2.1.0
sphinx: 1.2.2
patsy: 0.2.1
scikits.timeseries: None
dateutil: 1.5
pytz: 2014.3
bottleneck: None
tables: 3.1.1
numexpr: 2.3.1
matplotlib: 1.3.1
openpyxl: 1.8.5
xlrd: 0.9.3
xlwt: 0.7.5
xlsxwriter: 0.5.5
lxml: 3.3.5
bs4: 4.3.1
html5lib: None
httplib2: None
apiclient: None
rpy2: None
sqlalchemy: 0.9.4
pymysql: None
psycopg2: None
@jreback jreback added Bug Indexing Related to indexing on series/frames, not to indexes themselves labels Sep 13, 2014
@jreback jreback added this to the 0.15.1 milestone Sep 13, 2014
@jreback jreback modified the milestones: 0.15.0, 0.15.1 Oct 4, 2014
@jreback jreback changed the title Possible alignment bug when setting a subset of rows and attempting to switch columns BUG: Possible alignment bug when setting a subset of rows and attempting to switch columns Oct 4, 2014
@jreback jreback changed the title BUG: Possible alignment bug when setting a subset of rows and attempting to switch columns BUG: alignment bug when setting a subset of rows and attempting to switch columns Oct 4, 2014
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 a pull request may close this issue.

2 participants