Skip to content

Commit 3a12fdd

Browse files
committed
add panel
1 parent 5605b2b commit 3a12fdd

File tree

2 files changed

+209
-203
lines changed

2 files changed

+209
-203
lines changed

pandas/tests/indexing/test_indexing.py

-203
Original file line numberDiff line numberDiff line change
@@ -1434,91 +1434,6 @@ def test_iloc_getitem_labelled_frame(self):
14341434
# trying to use a label
14351435
self.assertRaises(ValueError, df.iloc.__getitem__, tuple(['j', 'D']))
14361436

1437-
def test_iloc_getitem_panel(self):
1438-
1439-
# GH 7189
1440-
p = Panel(np.arange(4 * 3 * 2).reshape(4, 3, 2),
1441-
items=['A', 'B', 'C', 'D'],
1442-
major_axis=['a', 'b', 'c'],
1443-
minor_axis=['one', 'two'])
1444-
1445-
result = p.iloc[1]
1446-
expected = p.loc['B']
1447-
tm.assert_frame_equal(result, expected)
1448-
1449-
result = p.iloc[1, 1]
1450-
expected = p.loc['B', 'b']
1451-
tm.assert_series_equal(result, expected)
1452-
1453-
result = p.iloc[1, 1, 1]
1454-
expected = p.loc['B', 'b', 'two']
1455-
self.assertEqual(result, expected)
1456-
1457-
# slice
1458-
result = p.iloc[1:3]
1459-
expected = p.loc[['B', 'C']]
1460-
tm.assert_panel_equal(result, expected)
1461-
1462-
result = p.iloc[:, 0:2]
1463-
expected = p.loc[:, ['a', 'b']]
1464-
tm.assert_panel_equal(result, expected)
1465-
1466-
# list of integers
1467-
result = p.iloc[[0, 2]]
1468-
expected = p.loc[['A', 'C']]
1469-
tm.assert_panel_equal(result, expected)
1470-
1471-
# neg indicies
1472-
result = p.iloc[[-1, 1], [-1, 1]]
1473-
expected = p.loc[['D', 'B'], ['c', 'b']]
1474-
tm.assert_panel_equal(result, expected)
1475-
1476-
# dups indicies
1477-
result = p.iloc[[-1, -1, 1], [-1, 1]]
1478-
expected = p.loc[['D', 'D', 'B'], ['c', 'b']]
1479-
tm.assert_panel_equal(result, expected)
1480-
1481-
# combined
1482-
result = p.iloc[0, [True, True], [0, 1]]
1483-
expected = p.loc['A', ['a', 'b'], ['one', 'two']]
1484-
tm.assert_frame_equal(result, expected)
1485-
1486-
# out-of-bounds exception
1487-
self.assertRaises(IndexError, p.iloc.__getitem__, tuple([10, 5]))
1488-
1489-
def f():
1490-
p.iloc[0, [True, True], [0, 1, 2]]
1491-
1492-
self.assertRaises(IndexError, f)
1493-
1494-
# trying to use a label
1495-
self.assertRaises(ValueError, p.iloc.__getitem__, tuple(['j', 'D']))
1496-
1497-
# GH
1498-
p = Panel(
1499-
np.random.rand(4, 3, 2), items=['A', 'B', 'C', 'D'],
1500-
major_axis=['U', 'V', 'W'], minor_axis=['X', 'Y'])
1501-
expected = p['A']
1502-
1503-
result = p.iloc[0, :, :]
1504-
tm.assert_frame_equal(result, expected)
1505-
1506-
result = p.iloc[0, [True, True, True], :]
1507-
tm.assert_frame_equal(result, expected)
1508-
1509-
result = p.iloc[0, [True, True, True], [0, 1]]
1510-
tm.assert_frame_equal(result, expected)
1511-
1512-
def f():
1513-
p.iloc[0, [True, True, True], [0, 1, 2]]
1514-
1515-
self.assertRaises(IndexError, f)
1516-
1517-
def f():
1518-
p.iloc[0, [True, True, True], [2]]
1519-
1520-
self.assertRaises(IndexError, f)
1521-
15221437
def test_iloc_getitem_doc_issue(self):
15231438

15241439
# multi axis slicing issue with single block
@@ -2004,124 +1919,6 @@ def test_multi_nan_indexing(self):
20041919
Index(['C1', 'C2', 'C3', 'C4'], name='b')])
20051920
tm.assert_frame_equal(result, expected)
20061921

2007-
def test_iloc_panel_issue(self):
2008-
2009-
# GH 3617
2010-
p = Panel(randn(4, 4, 4))
2011-
2012-
self.assertEqual(p.iloc[:3, :3, :3].shape, (3, 3, 3))
2013-
self.assertEqual(p.iloc[1, :3, :3].shape, (3, 3))
2014-
self.assertEqual(p.iloc[:3, 1, :3].shape, (3, 3))
2015-
self.assertEqual(p.iloc[:3, :3, 1].shape, (3, 3))
2016-
self.assertEqual(p.iloc[1, 1, :3].shape, (3, ))
2017-
self.assertEqual(p.iloc[1, :3, 1].shape, (3, ))
2018-
self.assertEqual(p.iloc[:3, 1, 1].shape, (3, ))
2019-
2020-
def test_panel_getitem(self):
2021-
# GH4016, date selection returns a frame when a partial string
2022-
# selection
2023-
ind = date_range(start="2000", freq="D", periods=1000)
2024-
df = DataFrame(
2025-
np.random.randn(
2026-
len(ind), 5), index=ind, columns=list('ABCDE'))
2027-
panel = Panel(dict([('frame_' + c, df) for c in list('ABC')]))
2028-
2029-
test2 = panel.ix[:, "2002":"2002-12-31"]
2030-
test1 = panel.ix[:, "2002"]
2031-
tm.assert_panel_equal(test1, test2)
2032-
2033-
# GH8710
2034-
# multi-element getting with a list
2035-
panel = tm.makePanel()
2036-
2037-
expected = panel.iloc[[0, 1]]
2038-
2039-
result = panel.loc[['ItemA', 'ItemB']]
2040-
tm.assert_panel_equal(result, expected)
2041-
2042-
result = panel.loc[['ItemA', 'ItemB'], :, :]
2043-
tm.assert_panel_equal(result, expected)
2044-
2045-
result = panel[['ItemA', 'ItemB']]
2046-
tm.assert_panel_equal(result, expected)
2047-
2048-
result = panel.loc['ItemA':'ItemB']
2049-
tm.assert_panel_equal(result, expected)
2050-
2051-
result = panel.ix['ItemA':'ItemB']
2052-
tm.assert_panel_equal(result, expected)
2053-
2054-
result = panel.ix[['ItemA', 'ItemB']]
2055-
tm.assert_panel_equal(result, expected)
2056-
2057-
# with an object-like
2058-
# GH 9140
2059-
class TestObject:
2060-
2061-
def __str__(self):
2062-
return "TestObject"
2063-
2064-
obj = TestObject()
2065-
2066-
p = Panel(np.random.randn(1, 5, 4), items=[obj],
2067-
major_axis=date_range('1/1/2000', periods=5),
2068-
minor_axis=['A', 'B', 'C', 'D'])
2069-
2070-
expected = p.iloc[0]
2071-
result = p[obj]
2072-
tm.assert_frame_equal(result, expected)
2073-
2074-
def test_panel_setitem(self):
2075-
2076-
# GH 7763
2077-
# loc and setitem have setting differences
2078-
np.random.seed(0)
2079-
index = range(3)
2080-
columns = list('abc')
2081-
2082-
panel = Panel({'A': DataFrame(np.random.randn(3, 3),
2083-
index=index, columns=columns),
2084-
'B': DataFrame(np.random.randn(3, 3),
2085-
index=index, columns=columns),
2086-
'C': DataFrame(np.random.randn(3, 3),
2087-
index=index, columns=columns)})
2088-
2089-
replace = DataFrame(np.eye(3, 3), index=range(3), columns=columns)
2090-
expected = Panel({'A': replace, 'B': replace, 'C': replace})
2091-
2092-
p = panel.copy()
2093-
for idx in list('ABC'):
2094-
p[idx] = replace
2095-
tm.assert_panel_equal(p, expected)
2096-
2097-
p = panel.copy()
2098-
for idx in list('ABC'):
2099-
p.loc[idx, :, :] = replace
2100-
tm.assert_panel_equal(p, expected)
2101-
2102-
def test_panel_assignment(self):
2103-
# GH3777
2104-
wp = Panel(randn(2, 5, 4), items=['Item1', 'Item2'],
2105-
major_axis=date_range('1/1/2000', periods=5),
2106-
minor_axis=['A', 'B', 'C', 'D'])
2107-
wp2 = Panel(randn(2, 5, 4), items=['Item1', 'Item2'],
2108-
major_axis=date_range('1/1/2000', periods=5),
2109-
minor_axis=['A', 'B', 'C', 'D'])
2110-
2111-
# TODO: unused?
2112-
# expected = wp.loc[['Item1', 'Item2'], :, ['A', 'B']]
2113-
2114-
def f():
2115-
wp.loc[['Item1', 'Item2'], :, ['A', 'B']] = wp2.loc[
2116-
['Item1', 'Item2'], :, ['A', 'B']]
2117-
2118-
self.assertRaises(NotImplementedError, f)
2119-
2120-
# to_assign = wp2.loc[['Item1', 'Item2'], :, ['A', 'B']]
2121-
# wp.loc[['Item1', 'Item2'], :, ['A', 'B']] = to_assign
2122-
# result = wp.loc[['Item1', 'Item2'], :, ['A', 'B']]
2123-
# tm.assert_panel_equal(result,expected)
2124-
21251922
def test_multi_assign(self):
21261923

21271924
# GH 3626, an assignement of a sub-df to a df

0 commit comments

Comments
 (0)