Skip to content

Bug in Panel Indexing #3830

Closed
Closed
@dhirschfeld

Description

@dhirschfeld

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.]])

Metadata

Metadata

Assignees

No one assigned

    Labels

    IndexingRelated to indexing on series/frames, not to indexes themselves

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions