Skip to content

Bug in Panel Indexing #3830

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
dhirschfeld opened this issue Jun 10, 2013 · 4 comments · Fixed by #4507
Closed

Bug in Panel Indexing #3830

dhirschfeld opened this issue Jun 10, 2013 · 4 comments · Fixed by #4507
Labels
Indexing Related to indexing on series/frames, not to indexes themselves
Milestone

Comments

@dhirschfeld
Copy link
Contributor

related to #3777

It seems that assigning a DataFrame to a Panel slice doesn't work correctly.
Unless I'm mistaken the below test code should work:

a = np.zeros((2,4,5))
panel = pd.Panel(a, items=['a1','a2'])
df = pd.DataFrame(a[0,:,:])

np.testing.assert_equal(panel.loc['a1'].values, df.values)
np.testing.assert_equal(panel.loc['a2'].values, df.values)

# Assignment by Value Passes for 'a2'
panel.loc['a2'] = df.values
np.testing.assert_equal(panel.loc['a1'].values, df.values)
np.testing.assert_equal(panel.loc['a2'].values, df.values)

# Assignment by DataFrame Fails for 'a2'
panel.loc['a2'] = df
np.testing.assert_equal(panel.loc['a1'].values, df.values)
np.testing.assert_equal(panel.loc['a2'].values, df.values)



Traceback (most recent call last):

  File "C:\Users\dhirschfeld\.spyder2\temp.py", line 41, in <module>
    np.testing.assert_equal(panel.loc['a2'].values, df.values)

  File "C:\dev\bin\Python27\lib\site-packages\numpy\testing\utils.py", line 257, in assert_equal
    return assert_array_equal(actual, desired, err_msg, verbose)

  File "C:\dev\bin\Python27\lib\site-packages\numpy\testing\utils.py", line 588, in chk_same_position
    raise AssertionError(msg)

AssertionError: 
Arrays are not equal

x and y nan location mismatch:
 x: array([[  0.,   0.,   0.,   0.,  nan],
       [  0.,   0.,   0.,   0.,  nan],
       [  0.,   0.,   0.,   0.,  nan],
       [  0.,   0.,   0.,   0.,  nan]])
 y: array([[ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.]])
@jreback
Copy link
Contributor

jreback commented Jun 10, 2013

try

panel['a2'] = df

this is somewhat related to #3777; and it essentially not implemented (not sure why it doesn't give an error though)

@dhirschfeld
Copy link
Contributor Author

Thanks, I can confirm that your solution works. It would be nice if it worked for .loc as well or at least threw an error so incorrect values won't silently pass through.

@jreback
Copy link
Contributor

jreback commented Jun 10, 2013

yep, marking as a bug for 0.12

@jreback
Copy link
Contributor

jreback commented Aug 7, 2013

@dhirschfeld This will now raise a NotImplementedError; In theory this should work, just have to implement if I have time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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