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

Panel slice assigning does not reindex correctly? #1630

Closed
CRP opened this issue Jul 16, 2012 · 2 comments
Closed

Panel slice assigning does not reindex correctly? #1630

CRP opened this issue Jul 16, 2012 · 2 comments
Labels
Milestone

Comments

@CRP
Copy link
Contributor

CRP commented Jul 16, 2012

Suppose I have

a=Panel(randn(3,10,2))
b=Series(randn(10))
b.sort()

now the index of b has a different order, yet same values as the major_index of a

if I do

a.ix[0,:,0]=b

the slice of a gets assigned the values of b without reindexing first, but somehow the index is till kept track of:

b
Out[220]: 
4   -2.465417
8   -2.202345
3   -1.173703
5   -0.802436
7   -0.307515
0   -0.045943
1    0.155771
6    0.367755
9    0.458332
2    1.629641

a.ix[0,:,0]=b

a.ix[0,:,0]
Out[223]: 
0   -2.465417
1   -2.202345
2   -1.173703
3   -0.802436
4   -0.307515
5   -0.045943
6    0.155771
7    0.367755
8    0.458332
9    1.629641

a.ix[0,:,0]==b
Out[224]: 
0    True
1    True
2    True
3    True
4    True
5    True
6    True
7    True
8    True
9    True
@ghost ghost assigned changhiskhan Sep 18, 2012
@changhiskhan
Copy link
Contributor

Actually this is a problem for DataFrame as well:

In [43]: df = DataFrame(np.random.randn(len(b), 4), columns=['A', 'B', 'C', 'D'])

In [44]: df
Out[44]: 
          A         B         C         D
0 -1.784259 -0.523289  0.066058  0.416523
1 -1.592496  1.191418  0.504262  0.508421
2 -0.566371  0.228974  0.516623  0.209813
3  1.447583  0.808516 -0.764518  0.231316
4  1.058431 -0.061739 -0.936624  1.220623
5  1.794763  0.311278 -0.101091 -2.709552
6 -0.602857  0.157062 -2.161062  0.783041
7  0.683989  0.421005 -0.900611  0.862070
8  0.287105  0.220197 -1.467609  1.256840
9  1.050565  0.240500 -0.232877  0.230123

In [45]: df.ix[:, 0] = b

In [46]: df
Out[46]: 
          A         B         C         D
0 -0.434466 -0.523289  0.066058  0.416523
1  0.426553  1.191418  0.504262  0.508421
2  0.486326  0.228974  0.516623  0.209813
3  0.599647  0.808516 -0.764518  0.231316
4  0.664624 -0.061739 -0.936624  1.220623
5  0.719194  0.311278 -0.101091 -2.709552
6  0.857904  0.157062 -2.161062  0.783041
7  1.360497  0.421005 -0.900611  0.862070
8  2.037406  0.220197 -1.467609  1.256840
9  2.350040  0.240500 -0.232877  0.230123

In [47]: b
Out[47]: 
9   -0.434466
5    0.426553
1    0.486326
8    0.599647
4    0.664624
7    0.719194
0    0.857904
3    1.360497
2    2.037406
6    2.350040

@wesm
Copy link
Member

wesm commented Sep 20, 2012

This is great. Thanks, Chang

@wesm wesm closed this as completed Sep 20, 2012
yarikoptic added a commit to neurodebian/pandas that referenced this issue Sep 27, 2012
Version 0.9.0 Release Candidate 1

* tag 'v0.9.0rc1': (58 commits)
  RLS: Version 0.9.0 Release Candidate 1
  BLD: add lib depends pandas-dev#1945
  BUG: missing case for assigning DataFrame via ix
  BUG: python 3.1 timedelta compat issue
  BUG: python 3 tzoffset is not hashable
  TST: adds dateutil to travis-ci install commands
  BUG: let selecting multiple columns in DataFrame.__getitem__ work when there are duplicates. close pandas-dev#1943
  BUG: DatetimeConverter does not handle datetime64 arrays properly
  BUG: reindex with axis=1 when setting Series to scalar location, close pandas-dev#1942
  BUG: fix formatting of Timestamps in to_html/IPython notebook. refactor to_html code. close pandas-dev#1940
  ENH: allow single str input to na_values pandas-dev#1944
  TST: when xlrd is not installed skip tests needing it, close pandas-dev#1941
  BUG: DatetimeIndex localizes twice if input is localized DatetimeIndex pandas-dev#1838
  BUG: align input on setting via ix pandas-dev#1630
  cython methods for group bins pandas-dev#1809
  BUG: allow non-numeric columns in groupby first/last pandas-dev#1809
  TST: skip unicode filename test if system requires encoding to ascii
  BUG: more fixedoffset occurrences pandas-dev#1928
  BUG: no zone in tzinfo pandas-dev#1838
  BUG: handle lists too in DataFrame.xs when partially selecting data from DataFrame. close pandas-dev#1796
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants